<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>event-driven architecture Archives - Blog IT</title>
	<atom:link href="https://blogit.create.pt/tag/event-driven-architecture/feed/" rel="self" type="application/rss+xml" />
	<link>https://blogit.create.pt/tag/event-driven-architecture/</link>
	<description>Create IT blogger community</description>
	<lastBuildDate>Thu, 16 Sep 2021 18:10:26 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>Getting Started with CloudEvents and AsyncAPI</title>
		<link>https://blogit.create.pt/davidpereira/2021/09/16/getting-started-with-cloudevents-and-asyncapi/</link>
					<comments>https://blogit.create.pt/davidpereira/2021/09/16/getting-started-with-cloudevents-and-asyncapi/#respond</comments>
		
		<dc:creator><![CDATA[David Pereira]]></dc:creator>
		<pubDate>Thu, 16 Sep 2021 12:26:26 +0000</pubDate>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[AsyncAPI]]></category>
		<category><![CDATA[CloudEvents]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[event-driven architecture]]></category>
		<guid isPermaLink="false">https://blogit.create.pt/?p=12557</guid>

					<description><![CDATA[<p>In the previous blog post we went over a case study for Azure Service Bus. In this article we&#8217;ll look at two specs, CloudEvents and AsyncAPI, that you can use to solve some problems of your event-driven architectures. Introduction At the moment, there are quite a few tools and products that have adopted CloudEvents or [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/davidpereira/2021/09/16/getting-started-with-cloudevents-and-asyncapi/">Getting Started with CloudEvents and AsyncAPI</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In the previous blog post we went over a <a href="https://blogit.create.pt/davidpereira/2021/06/02/case-study-azure-service-bus-and-event-driven-architectures/" target="_blank" rel="noreferrer noopener">case study for Azure Service Bus</a>. In this article we&#8217;ll look at two specs, CloudEvents and AsyncAPI, that you can use to solve some problems of your event-driven architectures.</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>At the moment, there are quite a few tools and products that have adopted CloudEvents or AsyncAPI. <a href="https://knative.dev/docs/eventing/accessing-traces/#" target="_blank" rel="noreferrer noopener">Knative Eventing</a> is a tool that helps developers in a serverless context, Azure Event Grid <a href="https://docs.microsoft.com/en-us/azure/event-grid/cloud-event-schema" target="_blank" rel="noreferrer noopener">natively supports CloudEvents</a>. More recently, Jenkins added <a href="https://cd.foundation/blog/2021/09/02/jenkins-interoperability-with-cloudevents" target="_blank" rel="noreferrer noopener">integration with CloudEvents</a> with a new plugin. It allows users to configure Jenkins as a source and a sink for CloudEvents. There is also interesting integrations between Kubernetes and Azure Event Grid that are compliant with the CloudEvents v1.0 spec. Checkout the <a href="https://github.com/tomkerkhove/k8s-event-grid-bridge" target="_blank" rel="noreferrer noopener">GitHub repository</a> or this <a href="https://blog.tomkerkhove.be/2021/01/19/introducing-kubernetes-event-grid-bridge/" target="_blank" rel="noreferrer noopener">blog post</a> and learn more about it.</p>



<p>Postman has <a href="https://blog.postman.com/asyncapi-joins-forces-with-postman-future-of-apis/" target="_blank" rel="noreferrer noopener">joined forces with AsyncAPI</a> along with organizations such as Salesforce, Slack and Solace. Postman in particular is publishing <a href="https://www.postman.com/postman/workspace/postman-open-technologies-asyncapi/example/12959542-7624bf1e-2e63-4e1f-a573-45598722af74" target="_blank" rel="noreferrer noopener">public collections</a> related to AsyncAPI. For example a list of companies adopting AsyncAPI, with links to those resources (GitHub repositories, websites, etc).</p>



<p style="margin-bottom:40px">I hope these projects have got you excited to learn more about these specs. Let&#8217;s dive into some of their details!</p>



<h2 class="wp-block-heading">CloudEvents</h2>



<p>The CloudEvents specification is under the <a href="https://github.com/cncf/wg-serverless" target="_blank" rel="noreferrer noopener">CNCF Serverless working group</a> since 2018. The spec&#8217;s purpose is describing event data in a common way. This is useful in many scenarios, for example, routing events to the appropriate subscribers depending on the&nbsp;<em>type</em>&nbsp;of the event. Since applications can use a lot of different transports to send and receive events, the CloudEvents spec is protocol-agnostic so it defines&nbsp;<strong>protocol bindings</strong>&nbsp;in order for the metadata to be correctly mapped for HTTP, AMQP, Kafka, etc.</p>



<p>There are many use cases in using the CloudEvents spec, but perhaps the main one would be&nbsp;<strong>interoperability</strong>. Imagine applications across clouds, being able to communicate in an event-driven architecture. Where there are producers of all sources, and consumers using all kinds of protocols (e.g. HTTP, AMQP, WebSockets). We can have middleware that connects these applications, adds E2E tracing and more with the use of CloudEvents. Of course we could connect the same applications without a common format, but it requires mapping between event formats (cloud providers use different schemas). Middleware would also need to parse the event data to get specific information.</p>



<p style="margin-bottom:30px">Another use case is SaaS (Software-as-a-service) that publishes events that clients are interested in to integrate with their own systems. For example, hooking into the checkout flow in a Shopify storefront to add extra checks. By leveraging CloudEvents these events can be&nbsp;<strong>consistent</strong>, opening the door for numerous integrations between 3rd party software.</p>



<h3 class="wp-block-heading">Extensions</h3>



<p style="margin-bottom:30px">There are a few extensions worth mentioning, one of them is for&nbsp;<a href="https://github.com/cloudevents/spec/blob/v1.0/extensions/distributed-tracing.md" target="_blank" rel="noreferrer noopener">distributed tracing</a>. However, it seems there is some discussion around removing this extension from the spec (check this&nbsp;<a href="https://github.com/cloudevents/spec/pull/751" target="_blank" rel="noreferrer noopener">PR on GitHub</a>). There are open issues on some SDKs to support it, and others have already made changes to remove it. The future isn&#8217;t clear, but I&#8217;d argue it&#8217;s interesting to follow this closely for any updates, since tracing events is very important in an event-driven architecture.</p>



<p style="margin-bottom:30px">The <a href="https://github.com/cloudevents/spec/blob/v1.0.1/extensions/partitioning.md" target="_blank" rel="noreferrer noopener">Partioning extension</a> is another interesting extension,&nbsp;it defines a field to be handled by message brokers that can separate load via a partition key. This is used for example in the Kafka protocol binding that requires implementations to map the  <code>partitionKey</code> attribute to the&nbsp;<code>key</code>&nbsp;of the Kafka message. In Kafka the concept of a partition is well known, so this maps out really well.</p>



<h3 class="wp-block-heading">Relation with Serverless computing</h3>



<p style="margin-bottom:40px">Serverless computing has increased in popularity and use in the industry, especially for it&#8217;s cost model. But many FaaS (Functions-as-a-service) providers have their own function interface. Which means developers can&#8217;t write a function in JavaScript, and deploy them in two cloud providers without making changes. This specification improves <strong>portability </strong>between FaaS platforms, so that developers receive an event in the same format and can reuse libraries for handling the event.</p>



<h2 class="wp-block-heading">AsyncAPI</h2>



<p>I’ll start with a description of what AsyncAPI is: <strong>a specification that describes and documents event-driven APIs in a machine-readable format</strong>. It&#8217;s protocol-agnostic like CloudEvents, so it can be used for APIs that work over many protocols, including MQTT, WebSockets, and Kafka.</p>



<p>The following is AsyncAPI&#8217;s vision stated on their&nbsp;<a href="https://www.asyncapi.com/roadmap" target="_blank" rel="noreferrer noopener">website</a>:</p>



<div class="wp-block-image"><figure class="aligncenter size-full is-resized"><img fetchpriority="high" decoding="async" src="https://blogit.create.pt/wp-content/uploads/2021/09/133161353-a0a65fde-d3fc-4984-9ba7-6eb855bd9590.png" alt="asyncapi description - AsyncAPI becomes the #1 API specification for defining and developing APIs. Any kind of APIs." class="wp-image-12559" width="969" height="674" srcset="https://blogit.create.pt/wp-content/uploads/2021/09/133161353-a0a65fde-d3fc-4984-9ba7-6eb855bd9590.png 886w, https://blogit.create.pt/wp-content/uploads/2021/09/133161353-a0a65fde-d3fc-4984-9ba7-6eb855bd9590-300x209.png 300w, https://blogit.create.pt/wp-content/uploads/2021/09/133161353-a0a65fde-d3fc-4984-9ba7-6eb855bd9590-768x534.png 768w, https://blogit.create.pt/wp-content/uploads/2021/09/133161353-a0a65fde-d3fc-4984-9ba7-6eb855bd9590-696x484.png 696w, https://blogit.create.pt/wp-content/uploads/2021/09/133161353-a0a65fde-d3fc-4984-9ba7-6eb855bd9590-604x420.png 604w, https://blogit.create.pt/wp-content/uploads/2021/09/133161353-a0a65fde-d3fc-4984-9ba7-6eb855bd9590-100x70.png 100w" sizes="(max-width: 969px) 100vw, 969px" /><figcaption>Photo taken from AsyncAPI website&#8217;s roadmap</figcaption></figure></div>



<p>I find this vision to be very interesting, mainly because of the part:&nbsp;<strong>Any kind of APIs</strong>. At first, you might wonder if this means the AsyncAPI spec will define rules and more concepts for other types of APIs like GraphQL or OpenAPI. But this is not at all the case, the goal is to&nbsp;<strong>integrate with existing tools and specs</strong>! This is valuable for developers because usually enterprise architectures consist of a mix of technologies, each for it&#8217;s appropriate use case. Developers nowadays don&#8217;t just interact with RESTful APIs in a request/response model. There are different demands and considerations for the ever increasing devices users can use, the software we build needs to match these demands and still maintain manageable. Where we can evolve and create new applications that leverage the numerous APIs that exist internally or from a 3rd party.</p>



<h3 class="wp-block-heading">Concepts</h3>



<p>The spec version 2.1.0 defines a few concepts apart from the common Producer, Consumer and Message. A&nbsp;<strong>Channel</strong>&nbsp;can be seen as a topic/exchange or queue, an application can send messages to a channel and consumers can subscribe to it to receive them. The&nbsp;<strong>Operation</strong>&nbsp;object indicates if it&#8217;s a publish or a subscribe operation and how an application can send or receive messages. A&nbsp;<strong>Binding</strong>&nbsp;(or &#8220;protocol binding&#8221;) is a mechanism to define protocol-specific information or query parameters for the channel bindings. For example, for the AMQP protocol we can specify the channel is an exclusive queue like this:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
&quot;bindings&quot;: {
    &quot;amqp&quot;: {
      &quot;is&quot;: &quot;queue&quot;,
      &quot;queue&quot;: {
        &quot;exclusive&quot;: true
      }
    }
}
</pre></div>


<p style="margin-bottom:30px">Each protocol has it&#8217;s own JSON schema and we can have bindings for Messages, Servers, Channels, Operations and others.</p>



<h3 class="wp-block-heading">Components</h3>



<p>You can define&nbsp;<strong>components</strong>&nbsp;to re-use in multiple AsyncAPI documents and we can&nbsp;<strong>reference</strong>&nbsp;other AsncAPI documents. Let&#8217;s say you have two publishers who publish the same message, but with different values in one of the message properties. We&#8217;d have two AsyncAPI documents specifying the publishers, referencing a 3rd document specifying the common message with it&#8217;s properties. The&nbsp;<code>$ref</code>&nbsp;field is a string that can be the path to the other file, or a URL for an external file where the schema we want is defined. This reference object uses the same rules and format of JSON Reference, which opens the door for many possibilites (<a href="https://www.asyncapi.com/docs/specifications/v2.1.0#referenceObject" target="_blank" rel="noreferrer noopener">check the docs</a>&nbsp;to know more).</p>



<p style="margin-bottom:30px">When we start to have a lot of apps that depend on each other&#8217;s schemas, we can take a look at some solutions to scale out AsyncAPI documents. Perhaps we use&nbsp;<a href="https://docs.confluent.io/platform/current/schema-registry/index.html">Confluent&#8217;s Sche</a><a href="https://docs.confluent.io/platform/current/schema-registry/index.html" target="_blank" rel="noreferrer noopener">ma Registry</a>&nbsp;for our JSON schemas and setup a&nbsp;<strong>catalog of events</strong>&nbsp;in our organization. This empowers new developers seeking for ways to integrate with existing systems and event producers. We can also just store these components in a GitHub repository, and reference them in our AsyncAPI documents.</p>



<h3 class="wp-block-heading">Tooling</h3>



<p style="margin-bottom:30px">There is already quite a few tools and the&nbsp;<a href="https://www.asyncapi.com/docs/community/tooling" target="_blank" rel="noreferrer noopener">tooling ecosystem</a>&nbsp;is increasing! I&#8217;ve recently seen a&nbsp;<a href="https://github.com/fmvilas/asyncapi-to-postman" target="_blank" rel="noreferrer noopener">repository</a>&nbsp;that enables the creation of Postman collections from an AsyncAPI spec. I&#8217;ve also seen&nbsp;<a href="https://github.com/asyncapi/cupid" target="_blank" rel="noreferrer noopener">architecture documents being generated</a>&nbsp;from multiple AsyncAPI specs too, having a tool that can understand relations between applications and then output a diagram is pretty cool.</p>



<h3 class="wp-block-heading">Generators for AsyncAPI</h3>



<p>One piece of tooling that is often used are generators that produce documentation and code. For example gRPC tools have this capability using the protocol buffer compiler. AsyncAPI generators can take an AsyncAPI document and generate client/server code or documentation in HTML and markdown. Currently, it depends on the template we use to generate server-side code, for example the&nbsp;<a href="https://github.com/asyncapi/nodejs-ws-template" target="_blank" rel="noreferrer noopener">Node.js WebSocket template</a>&nbsp;generates both server and client code. This can be improved and extended overtime, especially because of the way the&nbsp;<a href="https://github.com/asyncapi/generator" target="_blank" rel="noreferrer noopener">generator</a>&nbsp;is designed, enabling&nbsp;<strong>extensibility</strong>&nbsp;so we can have templates for many other languages that support more protocols, etc. For example, there is only a&nbsp;<a href="https://github.com/asyncapi/dotnet-nats-template" target="_blank" rel="noreferrer noopener">NATS generator for .NET Core</a>&#8230; but perhaps in the future there could be more protocols supported for .NET Core and examples built for Azure&nbsp;😃.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>There is a lot of exciting stuff happening in the event-driven architectures world&nbsp;😄. We have only touched the surface in this post. In the CloudEvents space there are new specs being designed and worked on: Discovery; Subscription and Schema Registry APIs. Since AsyncAPI defines a document that you can use to describe your API, it&#8217;d be interesting to see how these correlate to each other, and using them together. </p>



<p>I encourage you to join these communities and contribute to their open source projects, CloudEvents&nbsp;and&nbsp;AsyncAPI, both specs are very community-driven. Collaboration between everyone is the way forward, with  <a href="https://hacktoberfest.digitalocean.com/" target="_blank" rel="noreferrer noopener">Hacktoberfest</a> and <a href="https://www.asyncapi.com/blog/events2021" target="_blank" rel="noreferrer noopener">AsyncAPI&#8217;s Hackathon</a>&nbsp;coming up, searching good first issues is a great way to start and to contribute&nbsp;👍!</p>



<p>Let us know in the comments if you&#8217;re using these specs and what are your thoughts on them. The next blog post will be about a practical example for .NET Core, Azure and AMQP messaging using CloudEvents and AsyncAPI, so stay tuned!</p>



<p></p>



<h2 class="wp-block-heading">Additional Links</h2>



<p>Here are some links to talks, docs and blog posts that you may find useful if you&#8217;re interested to know more about CloudEvents and AsyncAPI:</p>



<ul class="wp-block-list" style="max-width:1015px"><li><a href="https://www.youtube.com/watch?v=TZPPjAv12KU" target="_blank" rel="noreferrer noopener">The Serverless and Event-Driven Future &#8211; Austen Collins, Serverless (Intermediate Skill Level)</a></li><li><a href="https://docs.openfaas.com/reference/triggers/#cloudevents" target="_blank" rel="noreferrer noopener">OpenFaaS supports CloudEvents</a></li><li><a href="https://www.postman.com/postman-galaxy/the-future-of-api-specifications/" target="_blank" rel="noreferrer noopener">The Future of API Specifications talk by Fran Méndez</a></li><li><a href="https://tech.ebayinc.com/engineering/asyncapi-2-0-enabling-the-event-driven-world/" target="_blank" rel="noreferrer noopener">AsyncAPI 2.0: Enabling the Event-Driven World</a></li></ul>
<p>The post <a href="https://blogit.create.pt/davidpereira/2021/09/16/getting-started-with-cloudevents-and-asyncapi/">Getting Started with CloudEvents and AsyncAPI</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/davidpereira/2021/09/16/getting-started-with-cloudevents-and-asyncapi/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Case Study: Azure Service Bus and Event-Driven Architectures</title>
		<link>https://blogit.create.pt/davidpereira/2021/06/02/case-study-azure-service-bus-and-event-driven-architectures/</link>
					<comments>https://blogit.create.pt/davidpereira/2021/06/02/case-study-azure-service-bus-and-event-driven-architectures/#respond</comments>
		
		<dc:creator><![CDATA[David Pereira&nbsp;and&nbsp;Francisco Grilo]]></dc:creator>
		<pubDate>Wed, 02 Jun 2021 11:02:12 +0000</pubDate>
				<category><![CDATA[Azure Service Bus]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[event-driven architecture]]></category>
		<guid isPermaLink="false">https://blogit.create.pt/?p=12291</guid>

					<description><![CDATA[<p>Introduction In&#160;this&#160;article&#160;we&#160;will&#160;talk&#160;about&#160;Event-Driven&#160;Architectures.&#160;We&#160;choose&#160;to&#160;use&#160;the&#160;Azure&#160;Cloud&#160;Infrastructure.Service&#160;Bus&#160;provides&#160;reliable,&#160;secure&#160;asynchronous&#160;messaging&#160;at&#160;scale.&#160;This&#160;article&#160;is&#160;written&#160;by&#160;the&#160;engineering&#160;team&#160;at&#160;CreateIT and&#160;it&#160;is&#160;intended&#160;to&#160;show&#160;you&#160;a&#160;case&#160;study in one of our projects for a client. We&#8217;ll&#160;take&#160;a&#160;deeper&#160;dive&#160;into&#160;the&#160;Service&#160;Bus&#160;technology,&#160;architecture,&#160;and&#160;design&#160;choices.&#160;The&#160;post&#160;will&#160;cover&#160;both&#160;conceptual&#160;material&#160;as&#160;well&#160;as&#160;implementation&#160;details.&#160;Most&#160;importantly,&#160;we&#160;will&#160;discuss&#160;design&#160;and&#160;implementation&#160;of&#160;some&#160;of&#160;the&#160;features&#160;that&#160;provide&#160;secure&#160;and&#160;reliable&#160;messaging&#160;at&#160;scale,&#160;while&#160;minimizing&#160;operational&#160;cost. Service&#160;Bus&#160;Entities When we are working with Azure Service Bus, we can choose two Entities: Topics or Queues. You can have multiple Topics or Queues per Service Bus Namespace, but firstly you need to differ one from another. If you want a FIFO queue and only have one Consumer, then Queues are the way to go. If you need multiple Consumers, then the Topic is the better option. In this specific case we will create a Subscription per Consumer (Topics are only available from the Standard Pricing Tier). Event-driven architectures Benefits&#160;with&#160;event-driven&#160;architectures What&#160;are&#160;the&#160;benefits&#160;of&#160;using&#160;a&#160;queue&#160;in&#160;the&#160;middle&#160;of&#160;these&#160;systems? We can decide to load balance the input from Customer Services. Let&#8217;s say there are a lot of updates being made to a customer, meaning a [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/davidpereira/2021/06/02/case-study-azure-service-bus-and-event-driven-architectures/">Case Study: Azure Service Bus and Event-Driven Architectures</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading" id="Introduction">Introduction</h2>



<p>In&nbsp;this&nbsp;article&nbsp;we&nbsp;will&nbsp;talk&nbsp;about&nbsp;Event-Driven&nbsp;Architectures.&nbsp;We&nbsp;choose&nbsp;to&nbsp;use&nbsp;the&nbsp;Azure&nbsp;Cloud&nbsp;Infrastructure.<br>Service&nbsp;Bus&nbsp;provides&nbsp;reliable,&nbsp;secure&nbsp;asynchronous&nbsp;messaging&nbsp;at&nbsp;scale.&nbsp;This&nbsp;article&nbsp;is&nbsp;written&nbsp;by&nbsp;the&nbsp;engineering&nbsp;team&nbsp;at&nbsp;CreateIT and&nbsp;it&nbsp;is&nbsp;intended&nbsp;to&nbsp;show&nbsp;you&nbsp;a&nbsp;case&nbsp;study in one of our projects for a client. </p>



<p>We&#8217;ll&nbsp;take&nbsp;a&nbsp;deeper&nbsp;dive&nbsp;into&nbsp;the&nbsp;Service&nbsp;Bus&nbsp;technology,&nbsp;architecture,&nbsp;and&nbsp;design&nbsp;choices.&nbsp;The&nbsp;post&nbsp;will&nbsp;cover&nbsp;both&nbsp;conceptual&nbsp;material&nbsp;as&nbsp;well&nbsp;as&nbsp;implementation&nbsp;details.&nbsp;Most&nbsp;importantly,&nbsp;we&nbsp;will&nbsp;discuss&nbsp;design&nbsp;and&nbsp;implementation&nbsp;of&nbsp;some&nbsp;of&nbsp;the&nbsp;features&nbsp;that&nbsp;provide&nbsp;secure&nbsp;and&nbsp;reliable&nbsp;messaging&nbsp;at&nbsp;scale,&nbsp;while&nbsp;minimizing&nbsp;operational&nbsp;cost.</p>



<h4 class="wp-block-heading" id="Service-Bus-Entities">Service&nbsp;Bus&nbsp;Entities</h4>



<p>When we are working with Azure Service Bus, we can choose two Entities: <strong>Topics</strong> or <strong>Queues</strong>. You can have multiple Topics or Queues per Service Bus Namespace, but firstly you need to differ one from another. If you want a FIFO queue and only have one Consumer, then Queues are the way to go. If you need multiple Consumers, then the Topic is the better option. In this specific case we will create a Subscription per Consumer (Topics are only available from the Standard Pricing Tier).</p>



<h2 class="wp-block-heading" id="Event-Driven-Architectures">Event-driven architectures</h2>



<h3 class="wp-block-heading" id="Benefits-with-event-driven-architectures">Benefits&nbsp;with&nbsp;event-driven&nbsp;architectures</h3>



<p>What&nbsp;are&nbsp;the&nbsp;benefits&nbsp;of&nbsp;using&nbsp;a&nbsp;queue&nbsp;in&nbsp;the&nbsp;middle&nbsp;of&nbsp;these&nbsp;systems?</p>



<ul class="wp-block-list" style="max-width:991px;margin-top:0px;margin-bottom:0px"><li>We can decide to <strong>load balance the input</strong> from Customer Services. Let&#8217;s say there are a lot of updates being made to a customer, meaning a lot of events being published. We scale the number of consumers and user the <strong>competing pattern</strong></li><li>We can <strong>throttle the input</strong>. If on black Friday there are a ton of events and in case our Audit Log system is down. We simply store these events on the queue and consume them when the service is back online again. Of course we&#8217;d need to implement some logic for this behavior, but adding this &#8220;middleware&#8221; buys us options.</li></ul>



<p>In our use case, we wanted to move to an implementation where the Web API doesn&#8217;t get affected by any changes on these external systems. But in order to change the implementation, we must first figure out what are the challenges associated with this change.</p>



<h3 class="wp-block-heading" id="Challenges-with-event-driven-architectures"><strong>Challenges&nbsp;with&nbsp;event-driven&nbsp;architectures</strong></h3>



<h4 class="wp-block-heading" id="Message/Event-order"><strong>Message/Event&nbsp;order</strong></h4>



<p>Azure Service Bus has a feature called <strong>sessions</strong>. A session provides a context to send and retrieve messages that will preserve ordered delivery. However, in our use case we chose not to use it.</p>



<h4 class="wp-block-heading" id="Message-Lock-Duration"><strong>Message&nbsp;Lock&nbsp;Duration</strong></h4>



<p>When we are using Queues, every message has a lock Duration. During this time the consumer needs to process it. But if this consumer needs to contact multiple external systems this time may rise and our messages could stop in the Dead-Letter. So the best practice is to change it accordingly to your needs. We recommend you to set this time extremely high in the beginning, and then do some tests to calculate the average.</p>



<p>After that add 30% more of its value, in case of some lengthy  requests (in this case if we have outliers, they might stop in the Queue). If you are using a Topic, you will have a Lock Duration per Subscription. So make sure to adjust this time accordingly to its functions.</p>



<h2 class="wp-block-heading" id="Implementation"><strong>Implementation</strong></h2>



<p>In the Figure 1 you can see the initial architecture for the Customer Management system. It was responsible to make the requests to the other systems.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="612" src="https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-10-1024x612.png" alt="" class="wp-image-12299" srcset="https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-10-1024x612.png 1024w, https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-10-300x179.png 300w, https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-10-768x459.png 768w, https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-10-696x416.png 696w, https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-10-703x420.png 703w, https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-10.png 1063w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Figure 1 &#8211; Initial architecture diagram </figcaption></figure>



<p>With the new implementation, a message broker was introduced and we&nbsp;used&nbsp;the <a href="https://martinfowler.com/articles/201701-event-driven.html#Event-carriedStateTransfer" target="_blank" rel="noreferrer noopener">event-carried state transfer pattern</a>, meaning our events&nbsp;had&nbsp;all&nbsp;the&nbsp;information&nbsp;the&nbsp;consumer&nbsp;needed&nbsp;in&nbsp;order&nbsp;to&nbsp;do&nbsp;their&nbsp;job.&nbsp;We&nbsp;took&nbsp;in&nbsp;consideration&nbsp;the&nbsp;<strong>event&nbsp;notifications&nbsp;pattern</strong>,&nbsp;where&nbsp;the&nbsp;consumer&nbsp;would&nbsp;have&nbsp;to&nbsp;make&nbsp;a&nbsp;request&nbsp;to&nbsp;the&nbsp;API&nbsp;that&nbsp;originated&nbsp;the&nbsp;event,&nbsp;in&nbsp;order&nbsp;to&nbsp;get&nbsp;more&nbsp;information.&nbsp;But&nbsp;this&nbsp;brings&nbsp;new&nbsp;problems&nbsp;to&nbsp;the&nbsp;table.&nbsp;What&nbsp;if&nbsp;when&nbsp;the&nbsp;consumer&nbsp;code&nbsp;runs,&nbsp;the&nbsp;information&nbsp;for&nbsp;that&nbsp;customer&nbsp;ID&nbsp;changed?&nbsp;What&nbsp;if&nbsp;the&nbsp;event&nbsp;was&nbsp;<code>CUSTOMER_CREATED</code>&nbsp;but&nbsp;in&nbsp;the&nbsp;meanwhile&nbsp;the&nbsp;customer&nbsp;was&nbsp;deleted?</p>



<h3 class="wp-block-heading" id="Retries-with-Polly"><strong>Retries&nbsp;with&nbsp;Polly</strong></h3>



<p>In a distributed system, many things can go wrong. The network can fail or have additional latency, systems may be temporarily down, etc. We use the <code>Azure.ServiceBus.Messaging</code> NuGet package so we are able to check if the exception is a transient fault or not (more information on <a href="https://github.com/Azure/azure-sdk-for-net/blob/Azure.Messaging.ServiceBus_7.1.1/sdk/servicebus/Azure.Messaging.ServiceBus/README.md#exception-handling)" target="_blank" rel="noreferrer noopener">these docs</a>), then use <a href="https://github.com/App-vNext/Polly" target="_blank" rel="noreferrer noopener">Polly</a> to setup retry logic and fallbacks. There are other options to implement retry policies, for example we took in consideration the <a href="https://docs.microsoft.com/en-us/azure/architecture/best-practices/retry-service-specific#service-bus" target="_blank" rel="noreferrer noopener">Retry guidance for Azure Services</a> documentation from Microsoft. Since we use the latest Azure SDK,  the appropriate class would be <a href="https://docs.microsoft.com/en-us/dotnet/api/azure.messaging.servicebus.servicebusretrypolicy?view=azure-dotnet" target="_blank" rel="noreferrer noopener">ServiceBusRetryPolicy</a>.<br>We configured Polly to retry to publish a message three times (this configuration is on <code>appsettings.json</code>), with exponential times between each attempt.<br>If after the third retry we can&#8217;t publish the message we need to save it, because it has crucial information. So to solve this issue we created a Fallback Gateway, to write these messages to a Container inside an Azure Storage Account.</p>



<h3 class="wp-block-heading" id="Filters-for-message-routing"><strong>Filters&nbsp;for&nbsp;message&nbsp;routing</strong></h3>



<p>This section only applies for Topics Entities on the Azure Service Bus.<br>We can add <a href="https://docs.microsoft.com/en-us/azure/service-bus-messaging/topic-filters" target="_blank" rel="noreferrer noopener">Filters</a> on our Subscriptions to help us with routing each message to its specific Consumer. We considered two filter types:</p>



<ul class="wp-block-list" style="max-width:1003px;margin-top:-19px;margin-bottom:49px"><li>SQL Filter</li><li>Correlation Filter</li></ul>



<p style="margin-bottom:12px">Using the Correlation Filter you can configure Custom Properties and create Filters for your needs. You just need to make sure the producer of the messages, includes the header, that you are currently using to filter, on the message.</p>



<p>With SQL Filters you can create conditional expression to evaluate the current message. Just make sure that all the system properties are prefixed with <em>sys</em>. in the expression. Either way, both filters work just choose one that suits you the most!</p>



<h3 class="wp-block-heading" id="Dead-Letter-Queue"><strong>Dead-Letter&nbsp;Queue</strong></h3>



<p class="has-text-align-left">In case the consumer application can&#8217;t process the message after the <strong>Max Delivery Count</strong> attempts, instead of returning it to the queue it will be sent automatically to the Dead-Letter queue. If you are using the Topic, each subscriber has its own Dead-Letter queue. You can also, configure different Max Delivery Counts Values for each Subscriber. </p>



<p>All messages that are published to the Service Bus have a TTL (Time-To-Live). After this time ends the message will be transferred automatically to the Dead-Letter. So make sure you adjust this time accordingly to your needs.</p>



<p class="has-text-align-left">With&nbsp;this&nbsp;we&nbsp;are&nbsp;able&nbsp;to&nbsp;save&nbsp;messages&nbsp;that&nbsp;weren&#8217;t&nbsp;processed&nbsp;by&nbsp;the&nbsp;consumer&nbsp;application,&nbsp;but&nbsp;we&nbsp;should&nbsp;always&nbsp;strive&nbsp;to&nbsp;have&nbsp;an empty&nbsp;dead-letter&nbsp;queue.</p>



<h2 class="wp-block-heading" id="Conclusion">Conclusion</h2>



<p>Our&nbsp;first&nbsp;steps&nbsp;into&nbsp;an&nbsp;Event-Driven&nbsp;Architecture&nbsp;was&nbsp;a&nbsp;truly&nbsp;success!<br>We&nbsp;were&nbsp;able&nbsp;to&nbsp;expand&nbsp;our&nbsp;previous&nbsp;solution&nbsp;to&nbsp;be&nbsp;compatible&nbsp;with&nbsp;multiple&nbsp;external&nbsp;systems&nbsp;and&nbsp;instead&nbsp;of&nbsp;having&nbsp;the&nbsp;API&nbsp;sending&nbsp;a&nbsp;HTTPS&nbsp;request&nbsp;for&nbsp;each&nbsp;one&nbsp;we&nbsp;had&nbsp;this&nbsp;Application&nbsp;sending&nbsp;one&nbsp;message&nbsp;to&nbsp;a&nbsp;Topic&nbsp;in&nbsp;the&nbsp;Service&nbsp;Bus.<br>One&nbsp;of&nbsp;our&nbsp;goals&nbsp;was&nbsp;to&nbsp;have&nbsp;load&nbsp;balance&nbsp;in&nbsp;the&nbsp;Publisher&nbsp;Application.&nbsp;We&nbsp;went&nbsp;from&nbsp;a&nbsp;1-&gt;3&nbsp;dependency&nbsp;to&nbsp;a&nbsp;1-&gt;&nbsp;1, as you can see in the Figure 2.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="269" src="https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-11-1024x269.png" alt="" class="wp-image-12300" srcset="https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-11-1024x269.png 1024w, https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-11-300x79.png 300w, https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-11-768x202.png 768w, https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-11-1536x403.png 1536w, https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-11-696x183.png 696w, https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-11-1068x280.png 1068w, https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-11-1600x420.png 1600w, https://blogit.create.pt/wp-content/uploads/2021/05/MicrosoftTeams-image-11.png 1840w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Figure 2 &#8211; Architecture Diagram with Azure Service Bus</figcaption></figure>



<p>Which&nbsp;is&nbsp;great&nbsp;and&nbsp;keeps&nbsp;the&nbsp;system&nbsp;scalable&nbsp;and&nbsp;future&nbsp;proof. Our&nbsp;solution&nbsp;became&nbsp;more&nbsp;decoupled&nbsp;in&nbsp;order&nbsp;to&nbsp;keep&nbsp;the&nbsp;Application&nbsp;agnostic&nbsp;to&nbsp;these&nbsp;changes.<br>If&nbsp;you&nbsp;have&nbsp;a&nbsp;similar&nbsp;situation&nbsp;with&nbsp;an Event-Driven Architecture then we totally recommend you to check more about this technology and it&#8217;s features.</p>



<p>We would like to share a link to <a href="https://github.com/Azure/azure-service-bus" target="_blank" rel="noreferrer noopener">Microsoft Azure Service Bus GitHub</a>. Most of the implementations of either the publisher or the subscriber were&nbsp;inspired&nbsp;by&nbsp;this&nbsp;documentation,&nbsp;so&nbsp;make&nbsp;sure&nbsp;you&nbsp;check&nbsp;it&nbsp;out!<br>If&nbsp;you&nbsp;have&nbsp;any&nbsp;questions,&nbsp;please&nbsp;write&nbsp;them&nbsp;down&nbsp;below.</p>



<h2 class="wp-block-heading" id="Additional-Links"><strong>Additional&nbsp;Links</strong></h2>



<p><a href="https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-exceptions" target="_blank" rel="noreferrer noopener">Service&nbsp;Bus&nbsp;Exceptions</a><br><a href="https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-overview" target="_blank" rel="noreferrer noopener">Service&nbsp;Bus&nbsp;Basic&nbsp;Steps</a><br><a href="https://docs.microsoft.com/pt-pt/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues" target="_blank" rel="noreferrer noopener">Tutorial&nbsp;with&nbsp;DotNet</a></p>
<p>The post <a href="https://blogit.create.pt/davidpereira/2021/06/02/case-study-azure-service-bus-and-event-driven-architectures/">Case Study: Azure Service Bus and Event-Driven Architectures</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/davidpereira/2021/06/02/case-study-azure-service-bus-and-event-driven-architectures/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
