<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Derek Comartin - CodeOpinion</title>
    <description>The latest articles on DEV Community by Derek Comartin - CodeOpinion (@codeopinion).</description>
    <link>https://dev.to/codeopinion</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F176529%2F7b6390b2-39c3-48d7-93b3-6ad3d3feb531.jpg</url>
      <title>DEV Community: Derek Comartin - CodeOpinion</title>
      <link>https://dev.to/codeopinion</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codeopinion"/>
    <language>en</language>
    <item>
      <title>Event Choreography for Loosely Coupled Business Processes</title>
      <dc:creator>Derek Comartin - CodeOpinion</dc:creator>
      <pubDate>Wed, 13 Jul 2022 23:27:00 +0000</pubDate>
      <link>https://dev.to/codeopinion/event-choreography-for-loosely-coupled-business-processes-1jnl</link>
      <guid>https://dev.to/codeopinion/event-choreography-for-loosely-coupled-business-processes-1jnl</guid>
      <description>&lt;p&gt;What's Event Choreography? Let's back up a bit to answer that. Event Driven Architecture is a way to make your system more extensible and loosely coupled. Using events as a way to communicate between service boundaries. But how do you handle long-running business processes and workflows that involve multiple services? Using RPC is going back to tight coupling, which we're trying to avoid with Event Driven Architecture. So what's a solution? Event Choreography&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/TA12e2ZJcGg"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Join!
&lt;/h2&gt;

&lt;p&gt;Developer-level members of my &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/join"&gt;YouTube channel&lt;/a&gt; or &lt;a href="https://www.patreon.com/codeopinion"&gt;Patreon&lt;/a&gt; get access to a private Discord server to chat with other developers about Software Architecture and Design as well as access to source code for any working demo application that I post on my blog or YouTube. Check out the &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/join"&gt;YouTube Membership&lt;/a&gt; or &lt;a href="https://www.patreon.com/codeopinion"&gt;Patreon&lt;/a&gt; for more info.&lt;/p&gt;

&lt;h2&gt;
  
  
  Follow CodeOpinion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codeopinion"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/"&gt;YouTube&lt;/a&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>microservices</category>
      <category>api</category>
      <category>eventdriven</category>
    </item>
    <item>
      <title>SOLID? Nope, just Coupling and Cohesion</title>
      <dc:creator>Derek Comartin - CodeOpinion</dc:creator>
      <pubDate>Wed, 13 Jul 2022 20:12:01 +0000</pubDate>
      <link>https://dev.to/codeopinion/solid-nope-just-coupling-and-cohesion-3e8m</link>
      <guid>https://dev.to/codeopinion/solid-nope-just-coupling-and-cohesion-3e8m</guid>
      <description>&lt;p&gt;How do we avoid writing spaghetti code so our systems don’t turn into a hot mess? For me Coupling and Cohesion. Some people focus on things like SOLID principles and Clean Architecture. While I don’t necessarily have a problem with that if you’re pragmatic, I don’t ever really think about either of those explicitly.&lt;/p&gt;

&lt;h2&gt;
  
  
  YouTube
&lt;/h2&gt;

&lt;p&gt;Check out my &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw"&gt;YouTube channel&lt;/a&gt; where I post all kinds of content that accompanies my posts including this video showing everything in this post.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;a href="https://www.youtube.com/watch?v=YDNR%5C_gfBk0Q" rel="noopener noreferrer"&gt;
      youtube.com
    &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Coupling and Cohesion
&lt;/h2&gt;

&lt;p&gt;With over 20 years of professional software development experience, I’m mostly thinking about coupling and cohesion as a guide to software design. I’m not explicitly thinking about SOLID principles or clean architecture.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/07/image.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mCtRr6Rs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/07/image-150x150.png" alt="yin yang" width="150" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Coupling and cohesion are like the yin-yang of software design. They push and pull against each other. You’re striving for high cohesion and low coupling, however, you’re trying to find a balance. We’re always fighting against coupling.&lt;/p&gt;

&lt;p&gt;There are many different forms of coupling but to narrow it down for simplicity’s sake:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“degree of interdependence between software modules”&lt;/p&gt;

&lt;p&gt;&lt;cite&gt;ISO/IEC/IEEE 24765:2010 Systems and software engineering — Vocabulary&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;At a micro level, this could be the interdependence between classes or functions, and at the macro level, this could be the interdependence between services.&lt;/p&gt;

&lt;p&gt;When you’re thinking about spaghetti code you’re likely actually referring to a system that has a high degree of coupling at the macro and micro levels. This makes changes difficult to make or they break other parts of the system because there’s a high degree of coupling. Check out my post on &lt;a href="https://codeopinion.com/write-stable-code-using-coupling-metrics/"&gt;Write Stable Code using Coupling Metrics&lt;/a&gt; for more on coupling.&lt;/p&gt;

&lt;p&gt;Cohesion refers to:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“degree to which the elements inside a module belong together”&lt;/p&gt;

&lt;p&gt;&lt;cite&gt;Structured Design: Fundamentals of a Discipline of Computer Program and Systems Design&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can look at cohesion both from a micro and macro level. From a micro level, this can be viewed as how do all the methods relate in a class? Or how do all the functions of a module relate? From a macro level, how do all the features relate to a service? Check out my post on &lt;a href="https://codeopinion.com/highly-cohesive-software-design-to-tame-complexity/"&gt;Highly COHESIVE Software Design to tame Complexity&lt;/a&gt; for more on cohesion.&lt;/p&gt;

&lt;p&gt;But what does “belong together” mean? For me, this is about functional cohesion. Grouping-related options of a task. Not grouping based on data (which is informational cohesion). Yes, data is important, however, data is required by the functionality that is exposed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Business Capabilities
&lt;/h2&gt;

&lt;p&gt;Speaking of functionality, let’s jump to the Single Responsibility Principle for a second as this might clarify why functional cohesion is important.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When you write a software module, you want to make sure that when changes are requested, those changes can only originate from a &lt;strong&gt;single person&lt;/strong&gt; , or rather, a single &lt;strong&gt;tightly coupled group of people&lt;/strong&gt; representing a single narrowly defined business function. You want to isolate your modules from the complexities of the organization as a whole, and design your systems such that each module is responsible (responds to) the needs of just that &lt;strong&gt;one business function&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;cite&gt;&lt;a href="https://blog.cleancoder.com/uncle-bob/2014/05/08/SingleReponsibilityPrinciple.html" rel="noreferrer noopener"&gt;&lt;/a&gt;&lt;a href="https://blog.cleancoder.com/uncle-bob/2014/05/08/SingleReponsibilityPrinciple.html"&gt;https://blog.cleancoder.com/uncle-bob/2014/05/08/SingleReponsibilityPrinciple.html&lt;/a&gt;&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This might seem a bit more clear how the single responsibility principle at its root addresses coupling and cohesion.&lt;/p&gt;

&lt;p&gt;If we focus on business capabilities and group them together, we’ll end up with a service. That’s why I always define a service as:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A Service is the authority of a set of business capabilities.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;At a macro level, we’re trying to have a high degree of cohesion by grouping by business capabilities. Behind those capabilities is data ownership.&lt;/p&gt;

&lt;p&gt;Unfortunately, many are still focused purely on data and what I call “entity services”. This was a screenshot from a post on Reddit. The question was if this data model diagram should be implemented as a service per “entity”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/07/image-1.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8892NIoM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/07/image-1.png" alt="entity services" width="716" height="824"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This type of thinking is based on informational cohesion, not functional cohesion. The focus solely on data and not thinking at all about functionality and behavior leads to design generally around CRUD.&lt;/p&gt;

&lt;p&gt;As an example, you’ll often have “Manager”, and “Repository” classes that look similar to this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/07/image-2.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QPKs9wSM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/07/image-2-1024x470.png" alt="IProductRepository" width="880" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Product “entity” is really just a data model with a bunch of properties. There is no behavior exposed, they are just data buckets.&lt;/p&gt;

&lt;p&gt;So where is the actual functionality of a product? In a large system, for example in a distribution domain, a product isn’t just a product.&lt;/p&gt;

&lt;p&gt;A product means different things to different people within that domain.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/07/1-2.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gopnAJPr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/07/1-2-1024x318.png" alt="Service Boundaries by Functional Cohesion" width="880" height="273"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sales are thinking about the Sale Price of a product and are customer-centric. Purchasing/Procurement is thinking about the cost and is vendor centeric. The warehouse is concerned about shipping and receiving. They all have different business capabilities, and because those capabilities are different, they care about different data behind those capabilities.&lt;/p&gt;

&lt;p&gt;A product isn’t just a product that has to live within a single boundary. It’s a concept that can live within multiple different service boundaries.&lt;/p&gt;

&lt;p&gt;Organizing related business capacities (features) into services allows us to decide how we want to handle technical concerns within each service or to a specific feature. Dependencies shared concerns such as data access, validation, etc. All of these decisions can be localized and made per service.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/07/4.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Gy4JQNDL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/07/4-1024x346.png" alt="Services with features with high functional cohesion" width="880" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Loose Coupling
&lt;/h2&gt;

&lt;p&gt;So you’ve defined boundaries based on functional cohesion, but they must have some interdependence between each other?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/07/2-1.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HoCKqJYl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/07/2-1-300x181.png" alt="Tight Coupling between Services" width="300" height="181"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Having a free for all where any service can be coupled to any other service is still a hot mess of spaghetti. In other words, tight coupling. The system will still be hard to change and fragile to change.&lt;/p&gt;

&lt;p&gt;You want to remove the tight coupling by having service boundaries be independent and not directly coupled to other services. One way of achieving this is through loose coupling provided by messaging.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/07/3-1.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qmqrsCjO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/07/3-1-300x194.png" alt="Loose Coupling between Services" width="300" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because you’re grouping by business capabilities, and the data behind those capabilities, each service should have all the data it needs. This means that you aren’t coupling services because you need to fetch data from them to perform an action.&lt;/p&gt;

&lt;p&gt;Services together need to create workflow and exchange information. As an example from the diagram above, if the Warehouse has a “Quantity on Hand”, you might think that Sales would need that so it knows if it can sell a given product. However, Sales actually has its own concept called ATP (Available to Promise) which is a business function that is the projected amount of inventory it can sell. This consists of what’s in stock in the Warehouse, not allocated existing orders (Invoicing), as well as purchase orders and expected receipts (Purchasing).&lt;/p&gt;

&lt;p&gt;Sales can maintain their ATP by consuming events from other services. It does not need to make directly coupled to an API to make calls at runtime to calculate ATP for a given product. It maintains and owns the ATP for all products based on events it’s consuming that are published from other services. When Invoicing publishes an OrderInvoiced event, it can subtract an amount from ATP. If the warehouse does a stock count and publishes an InventoryAdjusted event, Sales will update the ATP accordingly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Responsibility
&lt;/h2&gt;

&lt;p&gt;From a lower-level code perspective, the coupling can be challenging when we have to deal with many different technical concerns. Web, Authorization, Validation, Data Access, and Business Logic. But as mentioned earlier, each feature/capability can define how each of these concerns is handled.&lt;/p&gt;

&lt;p&gt;While you can share between features, such as a domain model, this naturally starts limiting the coupling between a set of features.&lt;/p&gt;

&lt;p&gt;One approach to handle the common concerns is by using the pipes &amp;amp; filters pattern. Specifically, the Russian doll model which the request passes through a filter that can call (or not) the next filter. This allows you to separate various concerns and create a pipeline for a request.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/07/5-1.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OJ3N6Wuq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/07/5-1-1024x146.png" alt="Pipes &amp;amp; Filters" width="880" height="125"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For more check out my post on &lt;a href="https://codeopinion.com/separating-concerns-with-pipes-filters/"&gt;Separating Concerns with Pipes &amp;amp; Filters&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Coupling and Cohesion
&lt;/h2&gt;

&lt;p&gt;Building a large system without any boundaries (low cohesion) and a high degree of coupling is ultimately building a big turd pile of a system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/07/6-1.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--noczK36l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/07/6-1-300x286.png" alt="Big Turd Pile" width="300" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will be hard to add new functionality, and hard to change existing functionality without breaking and causing regressions.&lt;/p&gt;

&lt;p&gt;Focusing on having highly cohesive services that provide specific business capabilities and loosely coupling between those services to provide workflow and business processes will allow you to build a system that is more resilient to change.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/07/7.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0b53tKgX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/07/7-300x156.png" alt="Smaller Turd Piles" width="300" height="156"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Decomposing a large system into smaller independent logical service boundaries allows you to make different decisions that are localized to an individual service. No system will be perfect, especially over time and it will need to evolve. Focus on coupling and cohesion as a guide.&lt;/p&gt;

&lt;h2&gt;
  
  
  Join!
&lt;/h2&gt;

&lt;p&gt;Developer-level members of my &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/join"&gt;YouTube channel&lt;/a&gt; or &lt;a href="https://www.patreon.com/codeopinion"&gt;Patreon&lt;/a&gt; get access to a private Discord server to chat with other developers about Software Architecture and Design as well as access to source code for any working demo application that I post on my blog or YouTube. Check out the &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/join"&gt;YouTube Membership&lt;/a&gt; or &lt;a href="https://www.patreon.com/codeopinion"&gt;Patreon&lt;/a&gt; for more info.&lt;/p&gt;

&lt;h2&gt;
  
  
  You also might like
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://codeopinion.com/highly-cohesive-software-design-to-tame-complexity/"&gt;Highly COHESIVE Software Design to tame Complexity&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codeopinion.com/write-stable-code-using-coupling-metrics/"&gt;Write Stable Code using Coupling Metrics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codeopinion.com/separating-concerns-with-pipes-filters/"&gt;Separating Concerns with Pipes &amp;amp; Filters&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://particular.net/webinars/finding-your-service-boundaries-a-practical-guide?utm_source=codeopinion&amp;amp;utm_medium=paid&amp;amp;utm_term=solid_principles&amp;amp;utm_content=additional_resources&amp;amp;utm_campaign=blog_sponsor"&gt;Finding your service boundaries: a practical guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://particular.net/videos/finding-service-boundaries-illustrated-in-healthcare?utm_source=codeopinion&amp;amp;utm_medium=paid&amp;amp;utm_term=solid_principles_cont&amp;amp;utm_content=additional_resources&amp;amp;utm_campaign=blog_sponsor"&gt;Finding service boundaries, illustrated in healthcare&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Follow CodeOpinion
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://twitter.com/codeopinion"&gt;Twitter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;[YouTube]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The post &lt;a href="https://codeopinion.com/solid-nope-just-coupling-and-cohesion/"&gt;SOLID? Nope, just Coupling and Cohesion&lt;/a&gt; appeared first on &lt;a href="https://codeopinion.com"&gt;CodeOpinion&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>microservices</category>
      <category>eventdriven</category>
      <category>api</category>
    </item>
    <item>
      <title>What is Software Architecture?</title>
      <dc:creator>Derek Comartin - CodeOpinion</dc:creator>
      <pubDate>Wed, 06 Jul 2022 21:40:30 +0000</pubDate>
      <link>https://dev.to/codeopinion/what-is-software-architecture-2pjk</link>
      <guid>https://dev.to/codeopinion/what-is-software-architecture-2pjk</guid>
      <description>&lt;p&gt;Software architecture is about making key decisions that will impact how you can make decisions in the future.  It's about giving yourself options at a relatively low cost early on so that your system can evolve over time without a high cost.  Software architecture is about options.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/dvnZfSK4dBI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Join!
&lt;/h2&gt;

&lt;p&gt;Developer-level members of my &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/join"&gt;YouTube channel&lt;/a&gt; or &lt;a href="https://www.patreon.com/codeopinion"&gt;Patreon&lt;/a&gt; get access to a private Discord server to chat with other developers about Software Architecture and Design as well as access to source code for any working demo application that I post on my blog or YouTube. Check out the &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/join"&gt;YouTube Membership&lt;/a&gt; or &lt;a href="https://www.patreon.com/codeopinion"&gt;Patreon&lt;/a&gt; for more info.&lt;/p&gt;

&lt;h2&gt;
  
  
  Follow CodeOpinion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codeopinion"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/"&gt;YouTube&lt;/a&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>microservices</category>
      <category>api</category>
      <category>programming</category>
    </item>
    <item>
      <title>Avoiding Batch Jobs by a message in the FUTURE</title>
      <dc:creator>Derek Comartin - CodeOpinion</dc:creator>
      <pubDate>Wed, 29 Jun 2022 21:59:46 +0000</pubDate>
      <link>https://dev.to/codeopinion/avoiding-batch-jobs-by-a-message-in-the-future-56dc</link>
      <guid>https://dev.to/codeopinion/avoiding-batch-jobs-by-a-message-in-the-future-56dc</guid>
      <description>&lt;p&gt;Some people will call it cron jobs, scheduled tasks, or batch jobs. Whatever you call it, it’s a process that runs periodically looking at the state of a database to determine some specific action to occur for the various records it finds. If you’ve dealt with this, you probably know it can be a nightmare, especially with failures. And of course, these usually run in the middle of the night, so get ready for a page!&lt;/p&gt;

&lt;h2&gt;
  
  
  YouTube
&lt;/h2&gt;

&lt;p&gt;Check out my &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw"&gt;YouTube channel&lt;/a&gt; where I post all kinds of content that accompanies my posts including this video showing everything in this post.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/zWgqj2OEKX8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Reservation
&lt;/h2&gt;

&lt;p&gt;A while back I placed an online order at a big box store that was set for pick-up at the store, rather than delivery. Here’s the confirmation order:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://codeopinion.com/wp-content/uploads/2022/03/1-4.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RMODKDFb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://codeopinion.com/wp-content/uploads/2022/03/1-4.png" alt="Order Confirmation Email" width="833" height="739"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that the email says, once my order is ready for pick-up I’ll get an email. This is because an employee at the store has to physically go to get the item off the shelf somewhere in the store, and then bring it to a holding area for pick-up orders.&lt;/p&gt;

&lt;p&gt;Once the item is taken from the shelf by the employee at the store, they set the order as being available for pick-up, which triggers this email I received:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://codeopinion.com/wp-content/uploads/2022/03/2-4.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---MIzyWBn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://codeopinion.com/wp-content/uploads/2022/03/2-4.png" alt="Order Ready Email" width="834" height="680"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The interesting part of this email is that it says I have 7 days to pick up my order, otherwise I’ll be refunded and the item will be put back onto the shelf.&lt;/p&gt;

&lt;p&gt;Basically, this is a reservation. For more on the Reservation Pattern, check out my post on A&lt;a href="https://codeopinion.com/avoiding-distributed-transactions-with-the-reservation-pattern/"&gt;voiding Distributed Transactions with the Reservation Pattern&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Timeline
&lt;/h2&gt;

&lt;p&gt;There are a couple of different scenarios. The first is that I actually drive to the store and pick up the item that I ordered.&lt;/p&gt;

&lt;p&gt;The timeline would be that I placed my order, sometime later the order was reserved (taken from the shelf by an employee), and then later I arrived at the store to complete my reservation/order.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/3-4.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AL0rPYEu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/3-4-1024x153.png" alt="Reservation Completed Timeline" width="880" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second scenario is that I place my online order, it’s reserved for me, but I just never show up to pick the item up at the store.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/4-3.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZjtlD6Cu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/4-3-1024x157.png" alt="Reservation Expired Timeline" width="880" height="135"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After 7 days from the order being reserved, the reservation will expire, which means an employee will take the item and put it back on the shelf so someone else can purchase it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Batch Jobs
&lt;/h2&gt;

&lt;p&gt;If you’re using batch jobs, how would that work? Typically you’ll have a process that runs every day that will look at the state of the database and then determine what to do. In this example, this might be selecting all the orders that are reserved but have not yet been completed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/5-4.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CKXkafv5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/5-4.png" alt="Batch jobs looking at the state of the database" width="880" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, the batch job has to do all of the refunds to credit cards and update the database to set the orders as canceled.&lt;/p&gt;

&lt;p&gt;The issue with batch jobs is that they are done in a batch. If there are 100 orders that have expired, the batch job iterates one by one performing these actions. What happens if at order 42 of 100 the process fails, because of a bug or failing to connect to the payment gateway, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/6-4.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tR1-w6J2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/6-4.png" alt="Batch jobs failing" width="880" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Batch jobs, purely based on the name or not done in isolation. This means the entire batch fails. Typically batch jobs are run during off-peak hours, which is usually in the middle of the night. If it fails in the middle of the night, you’re likely to get a page/alert of the failure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Isolation
&lt;/h2&gt;

&lt;p&gt;Rather what we would want is to handle each individual expired order/reservation in isolation. What we want to do is tell the system in the future, as a reminder, to cancel the reservation/order in 7 days when it’s reserved.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/7-4.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B6K1l509--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/7-4-1024x264.png" alt="Expire Reservation Future Message" width="880" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the customer doesn’t come and pick up the item at the store, then the “expire reservation” reminder will kick in and execute at the appropriate time, which is 7 days from when the order was reserved.&lt;/p&gt;

&lt;p&gt;However, if the customer does come and pick up the item at the store which completes the order, the “expire reservation” will still be triggered, however, it won’t need to do anything since the order is complete. It can exit early and not perform any action.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/8-2.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7-tL_sSN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/8-2-1024x266.png" alt="Reservation Completed Timeline" width="880" height="229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each Order will have its own “expire reservation”. Each is executed exactly 7 days from when the order was reserved and each will be executed in isolation. If one fails, it doesn’t affect the others.&lt;/p&gt;

&lt;h2&gt;
  
  
  Delayed Delivery
&lt;/h2&gt;

&lt;p&gt;So how can we technically implement this type of future reminder? You can use a queue that supports delayed delivery.&lt;/p&gt;

&lt;p&gt;When sending a message to a queue, you’re also going to provide the queue with a period of time to delay the delivery to a consumer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/9-2.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pmyq0JP5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/9-2-1024x203.png" alt="Send message to a Queue with Delayed Delivery" width="880" height="174"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This means that the queue will not make the message visible to consumers. Consumers will not be able to pull this message from the queue until the delay period of time has elapsed. The consumers won’t even see the message in the queue.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/10.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kwEESygn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/10-1024x199.png" alt="Message not visible during period of time" width="880" height="171"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the delayed delivery period has elapsed, the message will be visible again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/11.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zfrURwoz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/11-1024x204.png" alt="Message visible again" width="880" height="175"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The consumer will then pull the message and process it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/12.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N7BLrxqf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/12-1024x210.png" alt="Consumer processes message" width="880" height="180"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What this allows us to do is send a message to be processed in the future.&lt;/p&gt;

&lt;p&gt;In the example of our online order, this means that once an Order is reserved and the item is taken from the shelf, we enqueue a “expire reservation” message with delayed delivery of 7 days. After the 7 days, we will process that “expire reservation” message. If the order is already completed, the process just exits early. If it hasn’t been completed, it then does the credit card refund and updates the database to set the Order as canceled.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Avoiding Batch Jobs
&lt;/h2&gt;

&lt;p&gt;You can avoid batch jobs and have smaller units of work in isolation by telling your system to do something in the future. Leveraging a queue that supports delayed delivery is one example of how you can accomplish this.&lt;/p&gt;

&lt;p&gt;The workload will be smoothed out across time and provide isolation so you can handle failure at an individual level of work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Join!
&lt;/h2&gt;

&lt;p&gt;Developer-level members of my &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/join"&gt;YouTube channel&lt;/a&gt; or &lt;a href="https://www.patreon.com/codeopinion"&gt;Patreon&lt;/a&gt; get access to a private Discord server to chat with other developers about Software Architecture and Design as well as access to source code for any working demo application that I post on my blog or YouTube. Check out the &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/join"&gt;YouTube Membership&lt;/a&gt; or &lt;a href="https://www.patreon.com/codeopinion"&gt;Patreon&lt;/a&gt; for more info.&lt;/p&gt;

&lt;h2&gt;
  
  
  You also might like
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://codeopinion.com/avoiding-distributed-transactions-with-the-reservation-pattern/"&gt;Avoiding Distributed Transactions with the Reservation Pattern&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codeopinion.com/outbox-pattern-reliably-save-state-publish-events/"&gt;Outbox Pattern: Reliably Save State &amp;amp; Publish Events&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://particular.net/blog/death-to-the-batch-job?utm_source=codeopinion&amp;amp;utm_medium=paid&amp;amp;utm_term=batch_jobs&amp;amp;utm_content=additional_resources&amp;amp;utm_campaign=blog_sponsor"&gt;Death to the batch job&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Follow CodeOpinion
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://twitter.com/codeopinion"&gt;Twitter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw"&gt;YouTube&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mailchi.mp/63c7a0b3ff38/codeopinion"&gt;Newsletter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The post &lt;a href="https://codeopinion.com/avoiding-batch-jobs-by-a-message-in-the-future/"&gt;Avoiding Batch Jobs by a message in the FUTURE&lt;/a&gt; appeared first on &lt;a href="https://codeopinion.com"&gt;CodeOpinion&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>microservices</category>
      <category>eventdriven</category>
      <category>api</category>
    </item>
    <item>
      <title>Should you Delete or Soft Delete?</title>
      <dc:creator>Derek Comartin - CodeOpinion</dc:creator>
      <pubDate>Wed, 29 Jun 2022 14:34:18 +0000</pubDate>
      <link>https://dev.to/codeopinion/should-you-delete-or-soft-delete-24f2</link>
      <guid>https://dev.to/codeopinion/should-you-delete-or-soft-delete-24f2</guid>
      <description>&lt;p&gt;Should you delete records from your database or instead use a soft delete? I was recently asked my view on this question from a follower on Twitter. So what's my answer? Well I'm not usually thinking about "deleting" anything. Rather I'm thinking about adding.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/lDYXtj95Jy8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Join!
&lt;/h2&gt;

&lt;p&gt;Developer-level members of my &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/join"&gt;YouTube channel&lt;/a&gt; or &lt;a href="https://www.patreon.com/codeopinion"&gt;Patreon&lt;/a&gt; get access to a private Discord server to chat with other developers about Software Architecture and Design as well as access to source code for any working demo application that I post on my blog or YouTube. Check out the &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/join"&gt;YouTube Membership&lt;/a&gt; or &lt;a href="https://www.patreon.com/codeopinion"&gt;Patreon&lt;/a&gt; for more info.&lt;/p&gt;

&lt;h2&gt;
  
  
  Follow CodeOpinion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codeopinion"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/"&gt;YouTube&lt;/a&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>api</category>
      <category>microservices</category>
      <category>database</category>
    </item>
    <item>
      <title>Where should you use gRPC? And where NOT to use it!</title>
      <dc:creator>Derek Comartin - CodeOpinion</dc:creator>
      <pubDate>Thu, 23 Jun 2022 16:21:04 +0000</pubDate>
      <link>https://dev.to/codeopinion/where-should-you-use-grpc-and-where-not-to-use-it-126n</link>
      <guid>https://dev.to/codeopinion/where-should-you-use-grpc-and-where-not-to-use-it-126n</guid>
      <description>&lt;p&gt;I've recently read a few blogs and watched some videos that compare gRPC with REST as well as GraphQL. It seemed like the majority make the claim that gRPC is the standard for communication between services without giving any real reason why. What I think would be better served is explaining where and the situations where gRPC could be useful and where I'd avoid using it.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/4SuFtQV8RCk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Join!
&lt;/h2&gt;

&lt;p&gt;Developer-level members of my &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/join"&gt;YouTube channel&lt;/a&gt; or &lt;a href="https://www.patreon.com/codeopinion"&gt;Patreon&lt;/a&gt; get access to a private Discord server to chat with other developers about Software Architecture and Design as well as access to source code for any working demo application that I post on my blog or YouTube. Check out the &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/join"&gt;YouTube Membership&lt;/a&gt; or &lt;a href="https://www.patreon.com/codeopinion"&gt;Patreon&lt;/a&gt; for more info.&lt;/p&gt;

&lt;h2&gt;
  
  
  Follow CodeOpinion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codeopinion"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw"&gt;YouTube&lt;/a&gt;&lt;br&gt;
&lt;a href="https://mailchi.mp/63c7a0b3ff38/codeopinion"&gt;Newsletter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>api</category>
      <category>distributedsystems</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Sidecar Pattern for Abstracting Common Concerns</title>
      <dc:creator>Derek Comartin - CodeOpinion</dc:creator>
      <pubDate>Wed, 22 Jun 2022 21:50:41 +0000</pubDate>
      <link>https://dev.to/codeopinion/sidecar-pattern-for-abstracting-common-concerns-ib8</link>
      <guid>https://dev.to/codeopinion/sidecar-pattern-for-abstracting-common-concerns-ib8</guid>
      <description>&lt;p&gt;What is the sidecar pattern? Applications and services often have generic concerns such as health checks, configuration, metrics, as well as how they communicate with each other either directly or through messaging. Services usually implement these using libraries or SDKs to handle these concerns. How can you share these concerns across all these services so you’re not implementing them in every service? The sidecar pattern and ambassador pattern might be a good fit to solve this problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  YouTube
&lt;/h2&gt;

&lt;p&gt;Check out my &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw"&gt;YouTube channel&lt;/a&gt; where I post all kinds of content that accompanies my posts including this video showing everything in this post.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/9zAjtcf9Wyo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Shared Concerns
&lt;/h2&gt;

&lt;p&gt;Regardless of the platform, you’re going to leverage libraries/packages/SDKs to handle common concerns like health checks, configuration, metrics, and more. Each service will have these common concerns and need to use the libraries for their respective platform.&lt;/p&gt;

&lt;p&gt;For example, if you had two services, one written in .NET and the other written in Go. Each service would leverage libraries in its ecosystem to provide this common functionality.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/2-4.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--REgQfC8U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/2-4-1024x551.png" alt="Shared concerns for different services" width="880" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even with libraries, you still need to define how you’re handling and dealing with these common concerns. You may be using the same underlying infrastructure for both of them. As an example, each service might be publishing metrics to Cloudwatch.&lt;/p&gt;

&lt;p&gt;Wouldn’t be nice if there was a standardized way that each service would handle these shared concerns?&lt;/p&gt;

&lt;h2&gt;
  
  
  Sidecar pattern
&lt;/h2&gt;

&lt;p&gt;The sidecar pattern allows you to extract the common concerns from your service and host them separately in a separate process, known as a sidecar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/3-3.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6qq2kUfZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/3-3.png" alt="sidecar process runs locally to service" width="815" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the containerized world, this is often thought of as a separate container from your service, however, it really is just a separate process that runs locally alongside your service.&lt;/p&gt;

&lt;p&gt;With a sidecar, your service can now interact with a separate process that will handle the common concerns. The sidecar can perform health checks on your service, your service can send metrics to the sidecar, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ambassador Pattern
&lt;/h2&gt;

&lt;p&gt;Back to the example of sending metrics to Cloudwatch. With the sidecar, we can also apply the Ambassador Pattern. This all makes the sidecar a proxy to send data to Cloudwatch. This means our service is interacting with the sidecar, using a common API, and it’s in charge of sending the data to Cloudwatch. It’s not just metrics and Cloudwatch, this applies to any external service.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/5-3.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s-kpyhdd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/5-3-1024x325.png" alt="sidecar as a proxy to external services" width="880" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The benefit is that the sidecar is handling any failures, retries, backoffs, etc. We don’t have to implement all kinds of retry logic in our service, rather that’s a common concern handled by the sidecar when communicating with external services.&lt;/p&gt;

&lt;p&gt;If we want to make an HTTP request to an external service, we proxy it through the sidecar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/6-3.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2t2LMx0U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/6-3-1024x318.png" alt="sidecar handling retry logic" width="880" height="273"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If there is a transient failure, the sidecar is responsible for doing the retry while still maintaining the connection to our service while it does so.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/7-3.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fhVYlism--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/7-3-1024x320.png" alt="Handling transient failures and retries" width="880" height="275"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Abstraction
&lt;/h2&gt;

&lt;p&gt;While each service has its own instance of a sidecar, you can be using the same sidecar for many different services. This allows each service to have the exact same interface to all of the shared concerns the sidecar provides.&lt;/p&gt;

&lt;p&gt;This means that you can also be using it for things like a message broker.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/8-1.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ThlNgt2P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/8-1-1024x185.png" alt="sidecar as abstraction to message broker" width="880" height="159"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you read any of my other blog posts or watch my videos on YouTube, you know I’m an advocate for loosely coupling between services using messages, and not using blocking synchronous request-response.&lt;/p&gt;

&lt;p&gt;A sidecar can provide a common abstraction over a message broker. This means that each service doesn’t have to interact with the broker directly, nor does it need to use the specific libraries or SDKs for that broker. The sidecar is providing a common API for sending and consuming messages and is abstracting the underlying message broker.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeopinion.com/wp-content/uploads/2022/06/9-1.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k_aIvula--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2022/06/9-1-1024x185.png" alt="different services to AMQP supported message broker" width="880" height="159"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This means you could have one service using .NET and another using Python, both exchanging messages to a broker supporting AMQP. Each service would be completely unaware of what that underlying transport and message broker is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trade-offs
&lt;/h2&gt;

&lt;p&gt;So why would you want to use a sidecar and ambassador patterns? If you have services that are using different languages/platforms, and you want to standardize common concerns. Instead of each service implementing using their native packages/libraries/SDKs to their respective platform, the sidecar pattern allows you to define a common API that each service uses. This allows you to focus more on what your service actually provides rather than common infrastructure or concerns.&lt;/p&gt;

&lt;p&gt;One trade-off to mention is latency. If you’re using a sidecar with the ambassador pattern to proxy requests to external services, a message broker, etc, you’re going to be adding latency. While this latency might not that much, it’s something to note.&lt;/p&gt;

&lt;p&gt;If you don’t have a system that’s comprised of many services, or they are all using the same language/platform, then a sidecar could just be unneeded complexity. You could leverage an internal shared package/library that each service would use for defining a common API for shared concerns, it doesn’t need to be a sidecar. Again, your context matters. Use the patterns when you have the problems these patterns solve.&lt;/p&gt;

&lt;h2&gt;
  
  
  Join!
&lt;/h2&gt;

&lt;p&gt;Developer-level members of my &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/join"&gt;YouTube channel&lt;/a&gt; or &lt;a href="https://www.patreon.com/codeopinion"&gt;Patreon&lt;/a&gt; get access to a private Discord server to chat with other developers about Software Architecture and Design as well as access to source code for any working demo application that I post on my blog or YouTube. Check out the &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw/join"&gt;YouTube Membership&lt;/a&gt; or &lt;a href="https://www.patreon.com/codeopinion"&gt;Patreon&lt;/a&gt; for more info.&lt;/p&gt;

&lt;h2&gt;
  
  
  You also might like
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://codeopinion.com/handling-failures-in-message-driven-architecture/"&gt;Handling Failures in Message Driven Architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codeopinion.com/rest-apis-for-microservices-beware/"&gt;REST APIs for Microservices? Beware!&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.particular.net/courses/distributed-systems-design-fundamentals-online"&gt;Distributed Systems Design Fundamentals&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Follow CodeOpinion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codeopinion"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw"&gt;YouTube&lt;/a&gt;&lt;br&gt;
&lt;a href="https://mailchi.mp/63c7a0b3ff38/codeopinion"&gt;Newsletter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://codeopinion.com/sidecar-pattern-for-abstracting-common-concerns/"&gt;Sidecar Pattern for Abstracting Common Concerns&lt;/a&gt; appeared first on &lt;a href="https://codeopinion.com"&gt;CodeOpinion&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>microservices</category>
      <category>eventdriven</category>
      <category>api</category>
    </item>
    <item>
      <title>Build Asynchronous Systems! The world is full of Asynchronous Workflows</title>
      <dc:creator>Derek Comartin - CodeOpinion</dc:creator>
      <pubDate>Tue, 21 Jun 2022 14:42:33 +0000</pubDate>
      <link>https://dev.to/codeopinion/build-asynchronous-systems-the-world-is-full-of-asynchronous-workflows-29ab</link>
      <guid>https://dev.to/codeopinion/build-asynchronous-systems-the-world-is-full-of-asynchronous-workflows-29ab</guid>
      <description>&lt;p&gt;The world is asynchronous. A lot of the workflows and business processes you encounter out in the world are long-running and driven by asynchronous systems. &lt;/p&gt;

&lt;p&gt;Yet as developers, we're still often writing procedural and synchronous code to model these business processes. I'm going to give one of my favorite examples of a going out to eat at a restaurant to illustrate this and how this can be applied in software.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/87fOMcRPDts"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>eventdriven</category>
      <category>api</category>
      <category>distributedsystems</category>
    </item>
    <item>
      <title>Does a Data Access Layer make it easier to change your Database?</title>
      <dc:creator>Derek Comartin - CodeOpinion</dc:creator>
      <pubDate>Wed, 15 Jun 2022 17:09:09 +0000</pubDate>
      <link>https://dev.to/codeopinion/does-a-data-access-layer-make-it-easier-to-change-your-database-4l76</link>
      <guid>https://dev.to/codeopinion/does-a-data-access-layer-make-it-easier-to-change-your-database-4l76</guid>
      <description>&lt;p&gt;One primary reason for a data access layer or abstraction is your ability to move underlying databases easier. Have you ever replaced the underlying database of a large system or service? For example, moved from one relational database like PostgreSQL to MySQL. Or perhaps went from a relational database to a document or event store?&lt;/p&gt;

&lt;p&gt;There seem to be two groups of people. Those that have will say that abstracting the underlying database is crucial.  While the other group never has moved database and question abstracting or creating a data access layer because you likely won't replace the database.&lt;/p&gt;

&lt;p&gt;For me, like many things in software architecture, it's about coupling. If you limit coupling this isn't much of a hot topic.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/_IXEfi1B-lA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>database</category>
      <category>distributedsystems</category>
      <category>backend</category>
    </item>
    <item>
      <title>Why use DTOs (Data Transfer Objects)?</title>
      <dc:creator>Derek Comartin - CodeOpinion</dc:creator>
      <pubDate>Wed, 13 May 2020 23:13:03 +0000</pubDate>
      <link>https://dev.to/codeopinion/why-use-dtos-data-transfer-objects-fl6</link>
      <guid>https://dev.to/codeopinion/why-use-dtos-data-transfer-objects-fl6</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodeopinion.com%2Fwp-content%2Fuploads%2F2020%2F05%2FDataTransferObjects-1024x536.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodeopinion.com%2Fwp-content%2Fuploads%2F2020%2F05%2FDataTransferObjects-1024x536.png" alt="Data Transfer Objects"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Should you really use DTOs (Data Transfer Objects)? Seem like a lot of work mapping your database entities to another object? Why Bother? The simple answer is coupling.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Transfer Objects
&lt;/h2&gt;

&lt;p&gt;First, what are DTOs? When people refer to Data Transfer Objects, what they mean are objects that represent data structures that generally do not contain any business logic or behavior. If they do contain behavior, it’s generally trivial.&lt;/p&gt;

&lt;p&gt;Data Transfer Objects are often used to be serialized by the producer and then deserialized by the consumer. Often times these consumers may live in another process being used by an entirely different language and/or platform.&lt;/p&gt;

&lt;h2&gt;
  
  
  YouTube
&lt;/h2&gt;

&lt;p&gt;I’ve recorded a short video explaining this with some sample code. Check out the video and make sure to &lt;a href="https://www.youtube.com/channel/UC3RKA4vunFAfrfxiJhPEplw?sub_confirmation=1" rel="noopener noreferrer"&gt;subscribe to my YouTube Channel&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Crossing Boundaries
&lt;/h2&gt;

&lt;p&gt;The most common example of this is creating an HTTP API using ASP.NET Core that returns an object from its Controller actions that are ultimately serialized to JSON. The consumer is oftentimes JavaScript that uses those JSON responses in displaying the browser using a Component or SPA Framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  Internals
&lt;/h2&gt;

&lt;p&gt;If you’re not using DTOs, then you’re likely exposing internal data structures.&lt;/p&gt;

&lt;p&gt;The biggest culprit of this is simple TODO demo applications that expose the database entities directly. Meaning they output a serialized list of TODOs to the javascript frontend. And when you want to create a new record, they often times take the TODO object to insert directly into the database. This is leaking internals.&lt;/p&gt;

&lt;p&gt;This is my biggest complaint with simple demo applications are they often don’t implement or follow some practices, because rightly so, they aren’t applicable to a simple TODO application. However, people take the example of a simple TODO and use the same patterns into a much large application.&lt;/p&gt;

&lt;p&gt;The problem is when internal data objects are serialized and consumed by a client you either down own or cannot change easily. Or, which happens more often, the application itself gets very large.&lt;/p&gt;

&lt;h2&gt;
  
  
  Contracts
&lt;/h2&gt;

&lt;p&gt;The moment you want change internal data objects, you now have to update the clients.&lt;/p&gt;

&lt;p&gt;Take this simple example of a Customer that is an internal data structure we use through the system and likely use to persist using an ORM.&lt;/p&gt;

&lt;p&gt;View the code on &lt;a href="https://gist.github.com/dcomartin/a40b8144b0e21e16ef409a17e0cf20da" rel="noopener noreferrer"&gt;Gist&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If we are serializing this structure and clients are consuming this, if we change this structure, we’re likely going to break out clients.&lt;/p&gt;

&lt;p&gt;View the code on &lt;a href="https://gist.github.com/dcomartin/2a9ffeefd9e7af5dd034ed1f51e448eb" rel="noopener noreferrer"&gt;Gist&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This change would require a change to all of our clients. We could easily make this change in our own codebase and have all our own usages be correct, but we would be breaking all of our decoupled clients that get a serialized representation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Representation
&lt;/h2&gt;

&lt;p&gt;When creating an HTTP API, it’s all about representations. Most often times clients need a rich representation of a resource, not a just serialized version of a database entity. They often times need related data.&lt;/p&gt;

&lt;p&gt;Having your API return rich representations means you must do some level of composition to create an object, not just a database entity, that will get serialized. This is where a DTO comes into play.&lt;/p&gt;

&lt;p&gt;I actually don’t often use the term DTO, but rather use the word Representation or ViewModel. The purpose is still the same, it’s a data structure that is a contract between the producer and the consumer. That contract should remain stable (through backwards compatibility) or have a versioning strategy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coupling
&lt;/h2&gt;

&lt;p&gt;The reason you want to use DTOs is that you want clients to couple to that contract, not to your internal data structures. This allows you to modify and evolve your internals freely without breaking clients.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://codeopinion.com/building-self-descriptive-http-api-asp-net-core/" rel="noopener noreferrer"&gt;Building a Self Descriptive HTTP API in ASP.NET Core&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codeopinion.com/self-descriptive-http-api-in-asp-net-core-object-as-resource/" rel="noopener noreferrer"&gt;Object as Resource&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codeopinion?ref_src=twsrc%5Etfw" rel="noopener noreferrer"&gt;Follow @codeopinion&lt;/a&gt;(function() {&amp;lt;br&amp;gt;
    window.mc4wp = window.mc4wp || {&amp;lt;br&amp;gt;
        listeners: [],&amp;lt;br&amp;gt;
        forms: {&amp;lt;br&amp;gt;
            on: function(evt, cb) {&amp;lt;br&amp;gt;
                window.mc4wp.listeners.push(&amp;lt;br&amp;gt;
                    {&amp;lt;br&amp;gt;
                        event : evt,&amp;lt;br&amp;gt;
                        callback: cb&amp;lt;br&amp;gt;
                    }&amp;lt;br&amp;gt;
                );&amp;lt;br&amp;gt;
            }&amp;lt;br&amp;gt;
        }&amp;lt;br&amp;gt;
    }&amp;lt;br&amp;gt;
})();&amp;lt;br&amp;gt;
&amp;lt;!-- Mailchimp for WordPress v4.7.7 - &lt;a href="https://wordpress.org/plugins/mailchimp-for-wp/" rel="noopener noreferrer"&gt;https://wordpress.org/plugins/mailchimp-for-wp/&lt;/a&gt; --&amp;gt;&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;div&amp;gt;
    &amp;lt;div&amp;gt;
      &amp;lt;h2&amp;gt;Enjoy this post? Subscribe!&amp;lt;/h2&amp;gt;

      &amp;lt;p&amp;gt;Subscribe to our weekly Newsletter and stay tuned.&amp;lt;/p&amp;gt;

      &amp;lt;div&amp;gt;
        &amp;lt;span&amp;gt;
          &amp;lt;i&amp;gt;&amp;lt;/i&amp;gt;
        &amp;lt;/span&amp;gt;
        &amp;lt;input type="text" name="EMAIL" placeholder="your@email.com"&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;input type="submit" value="Subscribe"&amp;gt;

    &amp;lt;/div&amp;gt;    
  &amp;lt;/div&amp;gt;
  &amp;lt;div&amp;gt;      
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;br&gt;
Leave this field empty if you're human: &lt;br&gt;
&amp;lt;!-- / Mailchimp for WordPress Plugin --&amp;gt;

&lt;p&gt;The post &lt;a href="https://codeopinion.com/why-use-dtos-data-transfer-objects/" rel="noopener noreferrer"&gt;Why use DTOs (Data Transfer Objects)?&lt;/a&gt; appeared first on &lt;a href="https://codeopinion.com" rel="noopener noreferrer"&gt;CodeOpinion&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Message Properties</title>
      <dc:creator>Derek Comartin - CodeOpinion</dc:creator>
      <pubDate>Thu, 05 Dec 2019 02:45:46 +0000</pubDate>
      <link>https://dev.to/codeopinion/message-properties-39do</link>
      <guid>https://dev.to/codeopinion/message-properties-39do</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M8RSj8w---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2016/03/envelope-300x225.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M8RSj8w---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codeopinion.com/wp-content/uploads/2016/03/envelope-300x225.png" alt="Message Properties"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Over the years I’ve learned various aspects of messaging either through using various products, reading other blogs, or unfortunately in a lot of cases, discovering them myself. One of those aspects is message properties.&lt;/p&gt;

&lt;p&gt;Specifically, (meta) data that you might want to include in your messages to solve some common problems.&lt;/p&gt;

&lt;p&gt;My plan is to dive deeper with implementation examples for each topic listed in this post. Hopefully, this post can serve as a reference point to your adventures in messaging or possibly gain some insight that provides a solution for a pain point you may (already) be experiencing.&lt;/p&gt;

&lt;p&gt;I was inspired to write this post after seeing this tweet:&lt;/p&gt;


&lt;blockquote class="ltag__twitter-tweet"&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--liu-kISY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/660135190648504320/E384PlvP_normal.jpg" alt="Savvas Kλeanthous 🇬🇧🇪🇺🇨🇾 profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Savvas Kλeanthous 🇬🇧🇪🇺🇨🇾
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        &lt;a class="comment-mentioned-user" href="https://dev.to/skleanthous"&gt;@skleanthous&lt;/a&gt;

      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B8bbACBj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-99c56e7c338b4d5c17d78f658882ddf18b0bbde5b3f42f84e7964689e7e8fb15.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      When messages are transmitted they should include at minimum:&lt;br&gt;1. Message name&lt;br&gt;2. Name of service which owns the contract of the message&lt;br&gt;3. Message version&lt;br&gt;4. Message unique id&lt;br&gt;5. Correlation id&lt;br&gt;6. Causation id&lt;br&gt;7. UTC Timestamp&lt;br&gt;&lt;br&gt;[1 of 5
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      21:55 PM - 20 Nov 2019
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1197272391304523776" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-reply-action.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1197272391304523776" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-retweet-action.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      102
      &lt;a href="https://twitter.com/intent/like?tweet_id=1197272391304523776" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-like-action.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
      287
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  Type/Name
&lt;/h2&gt;

&lt;p&gt;The naming of messages is incredibly important for a variety of reasons. When talking about events, it’s important to name them in the past tense because it conveys that they are statements of fact.&lt;/p&gt;

&lt;p&gt;Most often the name of an event is used to determine how to deserialize into a specific type. Where I’ve personally run into problems, in .NET specifically, is using the CLR type name as the event name to determine how to deserialize. The issue with this is you’re very likely to change the name of your CLR type.&lt;/p&gt;

&lt;p&gt;Prefer to having a static name for an event and not using the CLR type name at runtime to create the event name.&lt;/p&gt;

&lt;h2&gt;
  
  
  Message Version
&lt;/h2&gt;

&lt;p&gt;Most often when needing to version a message is to simply create a new type/name. With events, I think this approach works fairly well when you discover a better way to describe the event and along with it the data to expose.&lt;/p&gt;

&lt;p&gt;When a new event isn’t required, but rather a slight change in data is to specify the version in the message. Consuming clients can use the message name along with the version to determine how to process the body of the message.&lt;/p&gt;

&lt;h2&gt;
  
  
  Message ID
&lt;/h2&gt;

&lt;p&gt;A unique identifier of a message. This can be used for idempotency and concurrency. Message Handlerscan keep track of which messages IDs they have processed and determine if they should act upon receiving a message.&lt;/p&gt;

&lt;p&gt;This is important because message handlers should be reentrant and messages can be delivered more than once.&lt;/p&gt;

&lt;h2&gt;
  
  
  Correlation ID
&lt;/h2&gt;

&lt;p&gt;A unique identifier that allows you to reference the flow of events (event chain) or a transaction. Also, often called a Trace ID. Assigning a correlation ID as soon as possible and any message handler that receives a message with a correlation ID then uses that same ID for any messages it outputs.&lt;/p&gt;

&lt;p&gt;This is very useful for logging and error handling in asynchronous and distributed environments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Contract Owner
&lt;/h2&gt;

&lt;p&gt;Who owns the message contract can be important. Depending on how messages are distributed, there may be many messages from various owners. Knowing who owns a message contract is helpful for troubleshooting as well as how to handle that message.&lt;/p&gt;

&lt;p&gt;An &lt;strong&gt;OrderPlaced&lt;/strong&gt; event seems like it could be unique across all services, however, in a distribution domain, is that a Sales OrderPlaced from the Sales service or a Purch OrderPlaced from the purchasing service?&lt;/p&gt;

&lt;p&gt;Having the owner of the message provides the ability to distinguish how to handle the message when the name alone doesn’t provide enough distinction.&lt;/p&gt;

&lt;h2&gt;
  
  
  UTC Timestamp
&lt;/h2&gt;

&lt;p&gt;This seems obvious but it gives more context to when the message was created. A useful is keeping track of latency between a message being created to how long it’s taking a given service to process it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sender
&lt;/h2&gt;

&lt;p&gt;Who originated the message. Not the service, but rather the user. This could be an access token that is then used to determine if the sender has the correct permissions or is authorized to perform the given request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resource/Entity Version
&lt;/h2&gt;

&lt;p&gt;The version of the resource/entity that you are performing an action on. Similar to the message ID this can be used for concurrency. A wonderful example of this is Azure Cosmos DB which uses an ETag as the resource version which is then used with an If-None-Match header for optimistic concurrency. If you’re using Cosmos DB check out my post on &lt;a href="https://codeopinion.com/documentdb-optimistic-concurrency/"&gt;Optimistic Concurrency in Azure Cosmos DB&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Message Properties
&lt;/h2&gt;

&lt;p&gt;I’ll be going in-depth in each of the above topics with code examples for the actual implementation of how you would use these message properties. Stay tuned.&lt;/p&gt;

&lt;p&gt;If you’d like to add to the list, let me know in the comments or on Twitter.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://codeopinion.com/idempotent-commands/"&gt;Idempotent Commands&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codeopinion.com/idempotent-aggregates/"&gt;Idempotent Aggregates&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codeopinion?ref_src=twsrc%5Etfw"&gt;Follow @codeopinion&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://codeopinion.com/message-properties/"&gt;Message Properties&lt;/a&gt; appeared first on &lt;a href="https://codeopinion.com"&gt;CodeOpinion&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>ddd</category>
      <category>microservices</category>
      <category>distributedsystems</category>
    </item>
    <item>
      <title>Roundup #58: Orleans 3.0, Snitch, What’s Your Problem? Next 5 years of ASP.NET Core</title>
      <dc:creator>Derek Comartin - CodeOpinion</dc:creator>
      <pubDate>Fri, 08 Nov 2019 00:49:17 +0000</pubDate>
      <link>https://dev.to/codeopinion/roundup-58-orleans-3-0-snitch-what-s-your-problem-next-5-years-of-asp-net-core-2maj</link>
      <guid>https://dev.to/codeopinion/roundup-58-orleans-3-0-snitch-what-s-your-problem-next-5-years-of-asp-net-core-2maj</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OXjmROKP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://codeopinion.com/wp-content/uploads/2019/01/Roundup.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OXjmROKP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://codeopinion.com/wp-content/uploads/2019/01/Roundup.png" alt="" width="880" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here are the things that caught my eye recently in .NET.  I’d love to hear what you found most interesting this week.  Let me know in the comments or on Twitter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codeopinion?ref_src=twsrc%5Etfw"&gt;Follow @codeopinion&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://devblogs.microsoft.com/dotnet/orleans-3-0/"&gt;Introducing Orleans 3.0&lt;/a&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;We are excited to announce the Orleans 3.0 release. A great number of improvements and fixes went in, as well as several new features, since Orleans 2.0. These changes were driven by the experience of many people running Orleans-based applications in production in a wide range of scenarios and environments, and by the ingenuity and passion of the global Orleans community that always strives to make the codebase better, faster, and more flexible. A BIG Thank You to all who contributed to this release in various ways!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I was happy to see the generic host for co-hosting with something like ASP.NET Core. I’ve blogged &lt;a href="https://codeopinion.com/co-hosting-orleans-and-asp-net-core/"&gt;Co-Hosting Orleans and ASP.NET Core&lt;/a&gt; which this about this feature.&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://devblogs.microsoft.com/dotnet/orleans-3-0/"&gt;https://devblogs.microsoft.com/dotnet/orleans-3-0/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://github.com/spectresystems/snitch"&gt;Snitch&lt;/a&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;A tool that helps you find transitive package references that can be removed.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;gt; snitch Foo.csproj --tfm net462&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Building Foo (net462)...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Building Bar (netstandard2.0)...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Building Baz (netstandard2.0)...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;The following packages can be removed:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Autofac (ref by Baz)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Newtonsoft.Json (ref by Bar)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;The following packages might be removed:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Castle.Core (ref by Baz) 4.4.0 &amp;lt;- 4.3.1 (Baz)&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Link: &lt;a href="https://github.com/spectresystems/snitch"&gt;https://github.com/spectresystems/snitch&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.youtube.com/watch?v=ZWIUn5BHDBc"&gt;What’s Your Problem?&lt;/a&gt;&lt;a href="https://www.youtube.com/watch?v=ZWIUn5BHDBc"&gt;– Asbjørn Ulsberg&lt;/a&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;A talk given by Asbjørn Ulsberg from PayEx at the 2019 Platform Summit in Stockholm.&lt;/p&gt;

&lt;p&gt;An API isn’t stronger than its weakest link and what’s often ignored in the ongoing maintenance and development of an API is the constant effort required to provide great self-servicable error messages. What this means is that without great, user-friendly error messages, your API is not going to be great.&lt;/p&gt;

&lt;p&gt;Just think about your first interaction with an API. How many failing requests have you sent before you have dug yourself through swathes of error messages and documentation to get to that one penultimate successful request making your heart sing and fists shaking in the air?&lt;/p&gt;

&lt;p&gt;Great error messages make them not feel like errors, but like friendly guidance towards a working request. They should be detailed enough to let the developer fix whatever problem there is themselves, like a dialogue between a customer and a support technician.&lt;/p&gt;

&lt;p&gt;This talk will give you ideas of how to handle errors and exceptions that occur in your application, be it with the incoming request, database failures or errors received from a 3rd party and how to serialize them into user friendly and actionable problem messages.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ZWIUn5BHDBc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://www.youtube.com/watch?v=ZWIUn5BHDBc"&gt;https://www.youtube.com/watch?v=ZWIUn5BHDBc&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.youtube.com/watch?v=7dJBmV_psW0"&gt;The next 5 years of ASP.NET Core – Ryan Nowak&lt;/a&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Join Ryan Nowak on a tour of ASP.NET Core’s evolution from “Project K” to present day and look forward to a few possible futures. We’ll discuss technical design details of how the ASP.NET Core stack is changing from bottom (hosting and startup), through the server, middleware pipeline, and up to high-level frameworks like MVC and Blazor.&lt;/p&gt;

&lt;p&gt;This is a technical deep-dive talk, and will explore possible design directions of .NET 5 and future releases.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/7dJBmV_psW0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://www.youtube.com/watch?v=7dJBmV_psW0"&gt;https://www.youtube.com/watch?v=7dJBmV_psW0&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codeopinion?ref_src=twsrc%5Etfw"&gt;Follow @codeopinion&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://codeopinion.com/roundup-58/"&gt;Roundup #58: Orleans 3.0, Snitch, What’s Your Problem? Next 5 years of ASP.NET Core&lt;/a&gt; appeared first on &lt;a href="https://codeopinion.com"&gt;CodeOpinion&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>dotnetcore</category>
      <category>aspnetcore</category>
    </item>
  </channel>
</rss>
