<?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>Forem: Allan B/H</title>
    <description>The latest articles on Forem by Allan B/H (@abarran03).</description>
    <link>https://forem.com/abarran03</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%2F524629%2F2b6db6d9-c192-4657-891f-3023637c79a0.jpg</url>
      <title>Forem: Allan B/H</title>
      <link>https://forem.com/abarran03</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/abarran03"/>
    <language>en</language>
    <item>
      <title>Microservices: The Static Contract Pitfall and how to avoid it</title>
      <dc:creator>Allan B/H</dc:creator>
      <pubDate>Tue, 30 Nov 2021 16:16:16 +0000</pubDate>
      <link>https://forem.com/abarran03/microservices-architecture-the-static-contract-pitfall-2hnn</link>
      <guid>https://forem.com/abarran03/microservices-architecture-the-static-contract-pitfall-2hnn</guid>
      <description>&lt;p&gt;Hi everyone! I would like to show you how &lt;em&gt;&lt;em&gt;The Static Contract pitfall&lt;/em&gt;&lt;/em&gt; could drive APIs to unexpected issues, and how versioning helps to avoid them. For that purpose I will be using &lt;em&gt;&lt;em&gt;O'Reilly's Microservices Antipatterns and Pitfalls&lt;/em&gt;&lt;/em&gt; and Microsoft site related to &lt;em&gt;&lt;em&gt;RESTful web API design&lt;/em&gt;&lt;/em&gt;. References were added at bottom.&lt;/p&gt;

&lt;h2&gt;
  
  
  But what is a pitfall?
&lt;/h2&gt;

&lt;p&gt;According to Richards (2016) a pitfall is &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;something that was never a good idea, even from the start.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And that is the case for &lt;em&gt;&lt;em&gt;The Static Contract pitfall&lt;/em&gt;&lt;/em&gt;. This assumption leads APIs to be not flexible enough for contract changes in front of client applications. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Static Contract Pitfall
&lt;/h2&gt;

&lt;p&gt;Imagine having a REST API endpoint consumed by three different client applications, but one of them needs an extension of a service published. So, the API provider in order to deploy the new changes, requires to check compatibility with the others consumers. Ups! Something goes wrong, the changes imply modifying a JSON contract, then consumers will be impacted and none of them would adapt to those modifications at the same time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f0MtDXG1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gltyq1c4uqlkg5ren0io.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f0MtDXG1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gltyq1c4uqlkg5ren0io.PNG" alt="Many clients consume an API endpoint, and changing this service could be complicated" width="444" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It happens all the time, contracts between providers and consumers are not static. They change very often by adding new features to microservices. However, there are some strategies to keep those issues away and implement backward compatibility without breaking all clients.&lt;/p&gt;

&lt;h2&gt;
  
  
  Versioning strategies
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Header versioning
&lt;/h3&gt;

&lt;p&gt;This type of versioning allows to manage the API version by adding the version number in a custom HTTP Header. It requires that client applications use this header to specify which service version will be consumed.&lt;br&gt;
Besides, it is important to consider server-side cache in case every request was stored, here using a proxy could help to reduce duplicated cache data.&lt;br&gt;
In the next example is showed the creation of a new order using an &lt;em&gt;&lt;em&gt;api-version&lt;/em&gt;&lt;/em&gt; specified in the &lt;em&gt;&lt;em&gt;Custom-Header&lt;/em&gt;&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POST https://enterprise.domain.com/orders/123  
Custom-Header: api-version=1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  URI versioning
&lt;/h3&gt;

&lt;p&gt;This technique consist in defining the version of an API in the uniform resource identifier (URI). It makes very clear to know which version will be consumed for client applications. &lt;br&gt;
For instance, choosing a version of a service used to retrieve an order could be done by &lt;em&gt;&lt;em&gt;v1&lt;/em&gt;&lt;/em&gt; or any custom standard. &lt;br&gt;
It is relevant to mention that this implementation makes harder to follow &lt;a href="https://en.wikipedia.org/wiki/HATEOAS"&gt;HATEOS&lt;/a&gt; constraint because all links associated to resources should have defined their correct version number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET https://enterprise.domain.com/v1/orders/123  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Query string versioning
&lt;/h3&gt;

&lt;p&gt;Regarding to this versioning strategy, the version goes in the query string parameter. In that case, it is recommended to establish a default version number when a client misses sending this parameter. The following example uses &lt;em&gt;&lt;em&gt;?version=3&lt;/em&gt;&lt;/em&gt; as query string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET https://enterprise.domain.com/orders/123?version=3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As URI strategy, the previous approach has the same issue related to implementation of HATEOS. &lt;/p&gt;

&lt;h3&gt;
  
  
  MediaType versioning
&lt;/h3&gt;

&lt;p&gt;Finally, very closed to header versioning practice, MediaType needs to be sent in the &lt;em&gt;&lt;em&gt;Accept Content Type Header&lt;/em&gt;&lt;/em&gt;. Provider is responsible for handling all possible format responses with their defined versions. For example, deleting an order could be performed if version were specified in &lt;em&gt;&lt;em&gt;Accept header&lt;/em&gt;&lt;/em&gt; along format response required.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DELETE https://enterprise.domain.com/orders/123 
Accept: application/vnd.enterprise.domain.com.v2+json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  tl;dr
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Versioning strategy&lt;/th&gt;
&lt;th&gt;Location&lt;/th&gt;
&lt;th&gt;Some Considerations&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Header&lt;/td&gt;
&lt;td&gt;Custom HTTP header&lt;/td&gt;
&lt;td&gt;Server-side cache issues&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;URI&lt;/td&gt;
&lt;td&gt;Properly as part of URI&lt;/td&gt;
&lt;td&gt;Very simple and clear which version is used&lt;br&gt;Makes harder to implement HATEOAS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Query String&lt;/td&gt;
&lt;td&gt;Query string param of URI&lt;/td&gt;
&lt;td&gt;Should be defined a default version value &lt;br&gt; Makes harder to implement HATEOAS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mediatype&lt;/td&gt;
&lt;td&gt;Accept Http header&lt;/td&gt;
&lt;td&gt;Handle all possible format responses with their defined versions &lt;br&gt; Server-side cache issues&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Microservices have became an extended practice in software architecture, from those implementations have emerged many lesson to learn and for this reason there are several antipatterns and pitfalls to take in consideration. Learning from the experience of the others and having in mind those best practices is crucial to build a strong architecture. Here is important to evaluate the options and choose the best one according to context.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;Richards, M. (2016). Microservices Antipatterns and Pitfalls. CA: O’Reilly Media.&lt;/p&gt;

&lt;p&gt;Microsoft (2021). RESTful web API design. Retrieve from &lt;a href="https://docs.microsoft.com/en-us/azure/architecture/best-practices/api-design"&gt;https://docs.microsoft.com/en-us/azure/architecture/best-practices/api-design&lt;/a&gt; &lt;/p&gt;

</description>
      <category>microservices</category>
      <category>beginners</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Microservices Patterns: Orchestration and Choreography</title>
      <dc:creator>Allan B/H</dc:creator>
      <pubDate>Sat, 20 Feb 2021 21:41:27 +0000</pubDate>
      <link>https://forem.com/abarran03/microservices-patterns-orchestration-and-choreography-j06</link>
      <guid>https://forem.com/abarran03/microservices-patterns-orchestration-and-choreography-j06</guid>
      <description>&lt;p&gt;Hi everyone! This is my first post and I'd like to share some thoughts about the differences between &lt;em&gt;&lt;em&gt;Orchestration&lt;/em&gt;&lt;/em&gt; and &lt;em&gt;&lt;em&gt;Choreography&lt;/em&gt;&lt;/em&gt; as architecture approaches in a solution based on microservices. &lt;/p&gt;

&lt;p&gt;There are many ways to define the interaction between software components, in a microservices architecture, to have a robust result, is crucial to follow some &lt;a href="https://dzone.com/articles/microservices-design-principles" rel="noopener noreferrer"&gt;principles of design&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That is why could be a very important tool to know about &lt;em&gt;&lt;em&gt;Orchestration&lt;/em&gt;&lt;/em&gt; and &lt;em&gt;&lt;em&gt;Choreography&lt;/em&gt;&lt;/em&gt; terms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Orchestration
&lt;/h2&gt;

&lt;p&gt;This pattern behaves like a real orchestra, where there is a central guider that coordinates all of rest of musicians in order to play a symphony. In &lt;em&gt;&lt;em&gt;Orchestration&lt;/em&gt;&lt;/em&gt;, a piece of software does that work and by certain number of calls, it makes possible the entire process.&lt;/p&gt;

&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff487zb7pxi0g7z83ve7b.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff487zb7pxi0g7z83ve7b.PNG" alt="Alt Orchestration"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;According to the last image, &lt;em&gt;service 1&lt;/em&gt; is responsible for making the requests to other components. Those calls could be either synchronous or asynchronous. So, &lt;em&gt;service 1&lt;/em&gt; manages the interactions between &lt;em&gt;service 2&lt;/em&gt; and &lt;em&gt;service 3&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;In that sense, an orchestrator becomes an easy way to manage complex processes by a centralized control between each steps. So, it has all required functionalities to make a response to the client.&lt;/p&gt;

&lt;p&gt;Most likely, &lt;em&gt;&lt;em&gt;Orchestration&lt;/em&gt;&lt;/em&gt; can increase the dependencies between services. Due to the existence of a single coordinator of a entire process. Usually it is delegated to this component more responsibility than others and sometimes it results in a &lt;a href="https://www.martinfowler.com/bliki/AnemicDomainModel.html" rel="noopener noreferrer"&gt;lack of purpose and anemic model&lt;/a&gt; .&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A single component conducts all the process (orchestrator).&lt;/li&gt;
&lt;li&gt;Commonly, orchestrator has more responsibility that other components.&lt;/li&gt;
&lt;li&gt;Easy way to coordinate a complex process with several steps.&lt;/li&gt;
&lt;li&gt;If orchestrator gets so much responsibility, tends to anemic models.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Choreography
&lt;/h2&gt;

&lt;p&gt;On another side, &lt;em&gt;&lt;em&gt;Choreography&lt;/em&gt;&lt;/em&gt; is a pattern which components communicate by themselves to complete a request. So, there is no a single conductor but each service is responsible for doing its part of the job.  &lt;/p&gt;

&lt;p&gt;The governance of services under this model could be more complex, since there are several points of failure. And evidently, it is necessary to complement the solution with a good tracing pattern.   &lt;/p&gt;

&lt;p&gt;However, &lt;em&gt;&lt;em&gt;Choreography&lt;/em&gt;&lt;/em&gt; provides low coupling when is implemented under a event-driven architecture (although this approach is not exclusive of that pattern). Because of this, the components designed come to be more autonomous and it allows a better reusability thus the reduce of dependencies.     &lt;/p&gt;

&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgtg3ndvkxhmije5orwae.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgtg3ndvkxhmije5orwae.PNG" alt="Alt Choreography"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Therefore, in a choreography &lt;em&gt;service 1&lt;/em&gt; doesn't know about the calls of &lt;em&gt;service 2&lt;/em&gt; and &lt;em&gt;service 3&lt;/em&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Each service acts together to get a result with the same level of responsibility.&lt;/li&gt;
&lt;li&gt;The interactions flow uses to be more complex. &lt;/li&gt;
&lt;li&gt;Components are more autonomous. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  tl;dr
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Orchestration&lt;/th&gt;
&lt;th&gt;Choreography&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A single component conducts &lt;br&gt;all the process.&lt;/td&gt;
&lt;td&gt;Components have to act together in a coordinated way.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;br&gt;Orchestrator has more responsibility &lt;br&gt;than other components.&lt;/td&gt;
&lt;td&gt;Use to be a harder way to coordinate a &lt;br&gt;complex process with several steps.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Orchestrator with so much responsibility&lt;br&gt;tends to anemic models.&lt;/td&gt;
&lt;td&gt;Services show a tendency to be more&lt;br&gt;autonomous.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;&lt;em&gt;Orchestration&lt;/em&gt;&lt;/em&gt; and &lt;em&gt;&lt;em&gt;Choreography&lt;/em&gt;&lt;/em&gt; models have certain advantages and disadvantages and they are not good or bad by themselves. All depends on the requirements and technical capabilities. For that reason, it would be helpful to evaluate the pros and cons of both patterns to implement a solution that fits properly.&lt;br&gt;
Finally, it is necessary to emphasize that is not kind of dichotomy between &lt;em&gt;&lt;em&gt;Orchestration&lt;/em&gt;&lt;/em&gt; and &lt;em&gt;&lt;em&gt;Choreography&lt;/em&gt;&lt;/em&gt; and they could be used in a sort of combination inside an software architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;&lt;em&gt;References&lt;/em&gt;&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;Bruce, M., &amp;amp; Pereira, P. A. (2019). Microservices in action. Shelter Island, NY: Manning Publications Co.&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>beginners</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
