<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Armand Jordaan on Medium]]></title>
        <description><![CDATA[Stories by Armand Jordaan on Medium]]></description>
        <link>https://medium.com/@armandjordaan6?source=rss-792c6fc8066e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sx4SBdbVQYQFCY86XeN3RQ.png</url>
            <title>Stories by Armand Jordaan on Medium</title>
            <link>https://medium.com/@armandjordaan6?source=rss-792c6fc8066e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 13:45:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@armandjordaan6/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Part 1: Introduction to Azure Container Apps]]></title>
            <link>https://itnext.io/part-1-introduction-to-azure-container-apps-3e879343ae9b?source=rss-792c6fc8066e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e879343ae9b</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[azure-container-apps]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Armand Jordaan]]></dc:creator>
            <pubDate>Sun, 06 Nov 2022 06:42:12 GMT</pubDate>
            <atom:updated>2022-11-14T19:22:36.337Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yhq7VEPqnpdEKb5-on9EWQ.png" /></figure><h4>Series: Building microservices using Azure Container Apps and Terraform</h4><h4><strong>Series:</strong></h4><ul><li><a href="https://itnext.io/part-0-adding-some-spicy-to-microservice-vs-monolith-4303c869684f">Part 0: Adding some spice to Microservice vs Monolith</a></li></ul><h3>Introduction</h3><p>Looking for an alternative to Azure App Services for containers, but not too excited about the costs of an AKS cluster, or looking for an unopinionated hosting platform that’s straightforward to use for your containers?</p><p>This and more will be covered in this series on Building Microservices with Azure Container Apps and Terraform.</p><blockquote>I will be using Dotnet, C#, and docker for these services. But as mentioned if your code can run in a container then do not fear. In this brief introduction I attempted to summarise the MSDN documentation, but I do recommend giving it a read: <a href="https://learn.microsoft.com/en-gb/azure/container-apps/?ocid=AID3042118">Azure Container Apps documentation | Microsoft Learn</a></blockquote><h3>What Are Azure Container Apps?</h3><p>It is a serverless application-centric hosting service that is unopinionated about the programming model or language deployed to it, as long as your code is packaged in a container. Container apps are built on top of the Kubernetes ecosystem but you the developer do not maintain or learn all the intricacies of Kubernetes, its maintenance, or all the underlying orchestrators and infrastructure.</p><p>Under the hood, container apps run on Azure Kubernetes Services (AKS) with integration with Distributed application runtime (Dapr), Envoy, and Kubernetes Event Driven Autoscaling (KEDA).</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F8843762&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fnoice-nice-click-gif-8843762&amp;image=https%3A%2F%2Fmedia.tenor.com%2FH6sjheSkU1wAAAAN%2Fnoice-nice.png&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/e74a5b6f0f02731d3e345ba2ca2d65bb/href">https://medium.com/media/e74a5b6f0f02731d3e345ba2ca2d65bb/href</a></iframe><h3>Use Cases</h3><p>As mentioned, Microservice is a prime use case but there are others such as:</p><ul><li>An application that needs to consume messages from a queue and requires to scale as the volume increases by spinning up/down instances based on the number of messages.</li><li>Long-running background processes.</li><li>HTTP message processing which can be split based on a % between instances. i.e., revision 1 gets 80% of the traffic and revision 2 gets 20% of the traffic.</li><li>I have even seen some teams migrate their Azure Function into Container Apps.</li></ul><h3>Features</h3><ul><li>Supports Managed Identities</li><li>Custom Domains</li><li>Encrypted traffic between apps</li><li>VNET integration</li><li>Health Probes</li><li>AAD and other social account authentication integration</li><li>Environment Secrets</li><li>Scaling based on scale triggers</li><li>Configured to expose services internally or external</li><li>Control over the app’s number of vCPUs and RAM.</li></ul><h3>How Does It Work?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F15451183&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fsettings-machines-modern-technology-gif-15451183&amp;image=https%3A%2F%2Fmedia.tenor.com%2F47CdzeuFFLIAAAAC%2Fsettings-machines.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b7dd6bf72c10fb478f52c89723e3deb/href">https://medium.com/media/7b7dd6bf72c10fb478f52c89723e3deb/href</a></iframe><p>Ok, so the first thing you are going to be working with and shipping containers, so naturally you will need some sort of container registry like Azure Container Registry.</p><p>When creating an Azure Container App you are required to specify a <strong>Container Apps Environment</strong> and place it in a region. This is used as a secure boundary around one or more container apps that communicate with each other and <strong>share </strong>a virtual network, Dapr, and logging. Note the apps in this environment would be writing to the same Log Analytics workspace. At the time of writing, you can’t have an environment over multiple regions or VNETs, thus it’s region &amp; VNET specific.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*Nt5k001dmVoH0n1IGuZiFA.png" /><figcaption>Illustration: Creating an Azure Container Apps Environment</figcaption></figure><p>Inside the Azure Container Apps Environment is where your Container Apps live. Each Container App consists of a Revision, Replica, and Container(s).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hVQI95JL7h1kppRGOwxFcw.gif" /><figcaption>Illustration: Azure Container Apps Environment</figcaption></figure><h4>Revision</h4><p>Is an immutable snapshot of a container app version. The 1st revision is created upon the 1st deployment. The app can run in a single or multi-revision mode and retain up to 100 revisions. With revisions, it’s possible to split HTTP traffic between them. Revisions are the core of the Container Apps application lifecycle</p><p>In <strong>single revision</strong> mode only one revision is active at a time and when a new revision becomes available it replaces the current revision. In <strong>multi-revision</strong> mode, multiple revisions are running concurrently beside each other.</p><p>Changes to the container app fall into either <strong>application/revision-scope </strong>changes.</p><ul><li><strong>Revision-Scope</strong>: Changes only affect a specific revision and are triggered through:<br> — Container configuration and image changes<br> — Revision Suffix<br> — Scale rules for the container app</li><li><strong>Application-Scope</strong>: Changes which are applied to all revisions <strong>but</strong> do not create a new revision and are triggered through:<br> — Secret value changes (Note: you need to restart the revision before it recognizes the change)<br> — Revision Mode Changed<br> — Dapr settings<br> — Private container registry credential changes<br> — Ingress changes such as: turning it on/off | traffic splitting rules | labels</li></ul><blockquote>Note: When making a <strong>revision-scope</strong> change then a new revision is automatically created. You can only affect a revision through <strong>application-scope</strong> change because a revision is immutable, and these changes will be applied globally.</blockquote><h4>Revision Labels</h4><p>With Container Apps you can split a % of your inbound HTTP traffic between multiple revisions of the app, but what happens if you want to create a revision and give that specific URL to say some test users? This is where labels come in, they are means by which you can direct external traffic to a specific revision. To switch the traffic between revisions using labels you need to set the revision mode to multiple and update the label against your targeted revision.</p><p>An example here is a container app with revision mode set to multiple where <em>revision-3</em> has a label assigned <em>test-users</em>. The URL for the revision with the label would be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*vJL4k6pggM4udBjvXVRsVA.png" /><figcaption>Illustration: Example of revisions with the use of labels</figcaption></figure><pre><a href="https://capp-blog-eu-west---test-users.greenplant-a864fe65.westeurope.azurecontainerapps.io/">https://capp-blog-eu-west---test-users.greenplant-a864fe65.westeurope.azurecontainerapps.io/</a></pre><p>This is useful because when you move the label to another revision the URL would remain the same.</p><blockquote>Note:<br>- You can choose to use a label, traffic splitting, or both.<br>- Only one label can be applied to a revision.<br>- Traffic splitting isn’t required to use a label</blockquote><h4>Container(s)</h4><p>Azure Container Apps manages Kubernetes for us and takes care of the orchestration. As mentioned earlier you can run either a single container or multiple containers in a sidecar pattern in a single container app.</p><p>Containers from any public or private container registry can be used as well as any Linux-based x86–64 container image.</p><p>When configuring a container app you need to specify the container registry, the resources (vCPU/RAM), any volume mounts, and the container image name and you can specify health probes.</p><p>Later in this series, we will dive into health probes, those familiar with Kubernetes would recognize these 3:</p><ul><li>Liveness</li><li>Readiness</li><li>startup</li></ul><p>Container apps support Managed Identities and late we will see how to setup up a managed Identity between Azure Container Registry and the Container Apps as well as between a Container App and Azure App Configuration.</p><p>Important to note that if your app tries to run a process that requires root then the application running inside the container would throw a runtime error and only Linux-based container images are supported.</p><h4>Application Life Cycle</h4><p>There are 4 life cycle states of a Container App: Deployment, Update, Deactivate, and Shutdown.</p><ul><li>Upon 1st deployment, a new revision is automatically <em>created </em>and set to active.</li><li>When a container app is <em>updated</em> a new revision is created.</li><li>You can <em>deactivate</em> a revision or choose to automatically deactivate old revisions</li><li><em>Shutdown</em> occurs when: App Scales in, is being deleted, or is being deactivated</li></ul><h3>Pricing</h3><p>Billing is broken up into two types of charges:</p><ul><li><strong>Resource Consumption</strong>:<br> — The vCPU/RAM allocated is billed on a per-second basis</li><li><strong>HTTP Requests</strong>:<br> — The number of HTTP request your app receives.</li></ul><p>At the time of writing you do get some free stuff per calendar month per subscription:</p><ul><li>The first 180,000 vCPU-seconds</li><li>The first 360,000 GiB-seconds</li><li>The first 2 million HTTP requests</li></ul><p>If your container app has no replicas running, then no consumption charges are incurred. But when you have replicas and revisions running, they are billed at an active rate. Microsoft does point out that a replica can enter an idle state which is then billed at a reduced rate.</p><p>On top of the resource consumption, you will be billed with request charges based on the HTTP requests received. worth pointing out that at the time of writing this is set the first 2 million requests are free per subscription per calendar month.</p><h3>Summary</h3><p>Kubernetes comes with a steep learning curve and Azure Container Apps make it easier for developers to take advantage of those features without having to invest the cost and time upfront to get started with Kubernetes or AKS. It’s a great model for hosting your microservices and getting your team to focus on delivering customer value faster.</p><p>Our investigation continues in the next section <em>Introduction to Terraform</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F15306641&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fpokemon-detective-pikachu-pikachu-pokemon-magnifying-glass-gif-15306641&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fl1nLaFPxV7EAAAAC%2Fpokemon-detective-pikachu-pikachu.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/86b49fb04c7588f1b58f4a6f7cf0982e/href">https://medium.com/media/86b49fb04c7588f1b58f4a6f7cf0982e/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e879343ae9b" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/part-1-introduction-to-azure-container-apps-3e879343ae9b">Part 1: Introduction to Azure Container Apps</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 0: Adding some spice to Microservice vs Monolith]]></title>
            <link>https://itnext.io/part-0-adding-some-spicy-to-microservice-vs-monolith-4303c869684f?source=rss-792c6fc8066e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4303c869684f</guid>
            <category><![CDATA[azure-container-apps]]></category>
            <category><![CDATA[opinion]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[monolithic-architecture]]></category>
            <dc:creator><![CDATA[Armand Jordaan]]></dc:creator>
            <pubDate>Sat, 05 Nov 2022 17:37:59 GMT</pubDate>
            <atom:updated>2022-11-14T19:22:02.070Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UMVet1jaiWZ-xrF5NIZRKg.png" /></figure><h4>Series: Building microservices using Azure Container Apps and Terraform</h4><h4>Series:</h4><ul><li><a href="https://medium.com/@armandjordaan6/part-1-introduction-to-azure-container-apps-3e879343ae9b">Part 1: Introduction to Azure Container Apps</a></li></ul><h3>Introduction</h3><p>In my capacity as a Dotnet developer I have worked with various teams, companies, and industries, and I have met some crazy characters but some brilliant professionals as well. Often I found the debate within these teams where there is a developer who is against anything new that is not their monolith application from 10 years ago vs a developer who is waiving hands above head to get the team to move to microservices.</p><p>In this article, I will give my opinion and it will get spicy, and there will be disagreement and it’s ok to have healthy disagreements. :D</p><h3>So, Your Team Is Considering Microservices?</h3><p>Please upgrade your codebases to the latest long-term supported version of Dotnet. Be nice to your new hires and have decent automated CI/CD pipelines and no manual Powershell scripts to move code between environments or even worse continue to RDP to VMs and copy your DLLs to the new new new directory. Don’t be that legacy team that fears the new and dismisses innovation.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F4932540&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Ffilthy-frank-its-time-to-stop-stop-clock-time-gif-4932540&amp;image=https%3A%2F%2Fmedia.tenor.com%2FdcUV9BomZLIAAAAC%2Ffilthy-frank-its-time-to-stop.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae7fd678165af15e49c609a97661c6e8/href">https://medium.com/media/ae7fd678165af15e49c609a97661c6e8/href</a></iframe><p>Microservices won’t fix your culture, or your bad coding habits, or overnight solve your scaling problems, just worsen them. You have to get clear on your organization’s communication structure and what value your product provides to the customer. Clearly define your domain and your bounded contexts.</p><p>Whatever your reason to change architecture you, your team, the executive, and the stakeholders all have to be on the same page. Failure to do so will lead to misalignment, and constant change in priorities and your team will neither get the budget nor time. If there is a team member not on board they will become a hazard to your project and will sabotage the project. If your business does not care about anything technical and just wants new features, i.e., the company is a feature factory then you are in for a crazy time like changing the engine and tires while the vehicle is traveling at high speeds. All is not lost and there are patterns and practices to deal with these challenges.</p><p>Finally, whether you are new dev or an old-grey beard dev get comfortable with failure and learn to fail fast. You can’t afford to code for months and only have one release day or week every other month. The cost of finding out the value you thought you are delivering is not aligned with what the customer wanted might sink your company. Close the feedback loop with your customer and get that feedback to your dev team asap.</p><h3>The Spice Must Flow</h3><p>If you explain your system like this and want to go the microservices route:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F16881825&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fcrazy-talking-invetigating-mad-explain-gif-16881825&amp;image=https%3A%2F%2Fmedia.tenor.com%2FaaFMIawDTHgAAAAC%2Fcrazy-talking.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e25192b6a7381c8891264b01f4445cf/href">https://medium.com/media/3e25192b6a7381c8891264b01f4445cf/href</a></iframe><p>You are in for a rough time friend. My recommendation is either to start anew, but it’s expensive and will take time. Or go clean up your data, get crystal clear on your domain, bounded contexts, and value offer then come back to relook microservices.</p><p>Before you grab your favourite Reddit keyboard and come after me let’s put ego aside and cut the BS:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F26264603&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fnailsandny-gif-26264603&amp;image=https%3A%2F%2Fmedia.tenor.com%2F4eGrSXYQmEsAAAAC%2Fnailsandny.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/230751944a43323bc8b7870d5982d2ee/href">https://medium.com/media/230751944a43323bc8b7870d5982d2ee/href</a></iframe><ul><li>Code split into separate projects while everything still points to the same DB is not microservices, it’s a distributed monolith.</li><li><em>“I have rolled my own pub-sub using a shared DB</em>”. Don’t do this, please use a message or event bus which is decoupled from your services.</li><li>Naming your services after Marvel or DC characters is not showing off your intellectual capacity but rather your lack thereof and it’s annoying AF. Be clear and concise with your naming on why this service exists and what it does.</li><li>Don’t be the guy: <em>“but Netflix and Spotify do…”</em>. No, chances are your company is nowhere near this scale and will not have the dev capacity to build &amp; maintain 500 services in a given quarter.</li><li>If you are starting in a new unknown domain where there is lots of experimentation and high code churn then a small monolith might be a better call as you can move faster however aim to refactor it into MS architecture once the domain has revealed itself and you are looking to scale your code, dev team, and product at scale.</li></ul><blockquote>Getting it wrong would result in years of balancing refactoring and product deliverables while struggling to scale your team and platform.</blockquote><ul><li>No, microservices or any cloud service will not solve your scaling and performance issues when your code is unoptimized and the whole system is a big ball of yarn.</li><li>Going from monolith to microservices is a process that does not happen overnight and comes with a refactoring cost.</li><li>Refactoring and breaking apart code are easier than doing it with a single massive database where it has no source control and relies heavily on domain-stored procs which in turn are interconnected with each other and other DBs.</li><li><em>“Making a change in module A leads to an unrelated break-in Module Z”</em>, then you have a classic monolith issue with tight coupling and your DDD has unintended side effects. This will be a thorn in your side when refactoring to microservices later, fix it if you can.</li><li><em>“It’s one architectural style vs the other”</em>. No, it’s about time, cost, and quality. Each has its own trade-offs and needs to be clearly understood before going to business with an architecture plan.</li></ul><p>The good news is if you are stuck on the monolith from hell you have options.</p><p>If your system is not at this level required then Azure App Services might be an alternative and is a mature cloud service with great documentation you can do a gradual migration to containers, runs on IIS, and comes in a few variants. First, get your system off of VMs and manual deployments to free up the budget and dev time for refactoring.</p><p><em>“You hold on for 1 minute there sir”</em>, my monolith architecture is perfect and adheres to all the software architecture acronyms you can throw at it.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F9206883&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Flike-a-sir-drink-meme-gif-9206883&amp;image=https%3A%2F%2Fmedia.tenor.com%2FczTFhTiW17YAAAAC%2Flike-a-sir-drink.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/a99e9c9902c66facc3f29031130411cf/href">https://medium.com/media/a99e9c9902c66facc3f29031130411cf/href</a></iframe><p>Great stuff, you get a gold star and your migration path should be relatively straightforward as long as you continue to follow best practices when breaking the monolith apart.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F3892850&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fproud-of-you-proud-ron-swanson-parks-and-rec-gif-3892850&amp;image=https%3A%2F%2Fmedia.tenor.com%2F3bomxY28__gAAAAC%2Fproud-of-you-proud.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0470af64c7642bf1ddd043fc8400ab38/href">https://medium.com/media/0470af64c7642bf1ddd043fc8400ab38/href</a></iframe><h3>In closing</h3><p>To be clear, I prefer to work in a microservice architecture and have seen the increased rate of delivery, stability, and redundancy contribute to successful products that were critical for business growth. In my career thus far I have yet to come across a perfect monolith many developers rant and rave about. But I have also seen some bad microservice implementations and most of the time it was a failure due to broken down communication between the business, developers, and customers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4303c869684f" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/part-0-adding-some-spicy-to-microservice-vs-monolith-4303c869684f">Part 0: Adding some spice to Microservice vs Monolith</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Overview: Azure load balancing]]></title>
            <link>https://itnext.io/overview-azure-load-balancing-5827da0bf14d?source=rss-792c6fc8066e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5827da0bf14d</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[azure-traffic-manager]]></category>
            <category><![CDATA[load-balancer]]></category>
            <category><![CDATA[azure-application-gateway]]></category>
            <category><![CDATA[azure-dns]]></category>
            <dc:creator><![CDATA[Armand Jordaan]]></dc:creator>
            <pubDate>Sat, 05 Nov 2022 17:00:16 GMT</pubDate>
            <atom:updated>2022-11-10T11:00:19.828Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p_e76ytRgBCzB3dV0bOjCw.png" /></figure><h4>What are the different types of Azure Load balancer services?</h4><h3>Why write another load balancer article?</h3><p>At the time of writing, I am preparing for my Azure Fundamentals exam. Now I have been working with Azure both in a professional and personal capacity as a developer for some time now. When looking at all the types of services I found the naming conventions of the Azure load-balancing &amp; Gateway products a bit confusing, what they do, and when to use which.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F13199396&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fwhy-huh-but-why-gif-13199396&amp;image=https%3A%2F%2Fmedia.tenor.com%2FKjJTBQ9lftsAAAAN%2Fwhy-huh.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/63bffa149d6f9ea436175bf1dd732041/href">https://medium.com/media/63bffa149d6f9ea436175bf1dd732041/href</a></iframe><h3>Who might find this useful?</h3><p>People who are new to Azure or just looking for a quick overview. There are some great references online and the Azure portal does offer a wizard/questionnaire on deciding a load-balancing solution to fit your solution.</p><h4>What is a load balancer?</h4><p>A basic use case, say you have a single VM or instance of an application and there are peak traffic times, or it is a critical service that if its only instance becomes unavailable bad things will happen. Or you want to set up specific routing rules and security over all your inbound traffic at a regional or global level. This is where a load balancer comes in. It assists with traffic distribution, should an instance of a backend service fail traffic is routed away and sent to the next available healthy instance of that service.</p><p>At the highest level, it is a piece of software that routes inbound traffic and distributes it across its backend instances. It can be exposed publicly, privately or both depending on the service. Works with the concept of a frontend and backend where the frontend is either services/machines making calls to it and its backend which are the services or VMs registered with the load balancer to have the traffic distributed to them. It can also act as a single-entry point in the system. Note that the types of Azure load balancers you choose would also depend on your system’s geographical distribution such as global, single, or multi-region.</p><p>The type of protocol the traffic is served over would influence the type of load balancer you choose. This is where the OSI model comes in, even if you are just a developer creating business applications, I strongly recommend you get familiar with the OSI Model. For the purposes of this article, we are only interested in layer-4 and layer-7.</p><p>For reference:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60007eda2e383cfebf5eaa24c105dd76/href">https://medium.com/media/60007eda2e383cfebf5eaa24c105dd76/href</a></iframe><h4>What will influence the type of solution?</h4><p>Factors to consider when deciding on a load-balancing solution include:</p><ul><li>Are all the services running in the cloud or is this a hybrid cloud environment?</li><li>Is the traffic being sent to your application over external (public internet) or internal (within the VNet or over VNet peering) or maybe both?</li><li>At which layer of the OSI model (layers 4 or 7) do you require the traffic to be balanced?</li><li>The system’s geographical distribution i.e., global, single, or multi-region.</li></ul><h4>Types of Load balancers</h4><p>At the time of writing, this is the list of load-balancing services, and I would like to point out that there is a lot more detail to each of these services I do encourage consulting the official documentation on each, if studied all together it can get overwhelming especially if you have never worked in a cloud environment before. So for now the brief summaries will do.</p><h4>Layer — 4</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/100/1*Tu_cuK5o_0NU5vz1xP8yoQ.png" /></figure><h4>Azure Load Balancer</h4><p>Most commonly used with a pool of VMs as the backend with features such as routing rules, a traffic manager, port forwarding, and health probes. Here you’d route traffic based on port or IP address. It comes in 3 SKUs: Standard, Basic, and Gateway Load balancer.</p><p>At the time of writing, there is a <a href="https://learn.microsoft.com/en-us/azure/load-balancer/cross-region-overview">Cross-region load balancer</a> feature which is in preview which enables the load balancer to balance across regions and not a single region.</p><h4>Layer — 7</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/100/1*gTY-OqinTgwfBjbig8uHPA.png" /></figure><h4>Azure Application Gateway</h4><p>A service that is region specific and must be deployed in a VNET. Its backend can be VMs, Azure App Service and variants, IP FQDN, and in the Kubernetes world on the Standard_v2 and WAF_v2 SKUs, it could be configured as an Azure Gateway Ingress controller to be deployed into your AKS cluster.</p><p>Supports auto-scaling, end-to-end encryption, zone redundancy, multi-site hosting URL rewriting, SSL termination, and health probes, and be configured to work with a Web Application Firewall (WAF). Important to point out Application gateway is a single point of entry and can be configured to be public or public + private. What I mean by this is you can’t deploy an application gateway into your VNET and only have private VNET services access it with no public endpoint.</p><p>Supports: HTTP/ HTTPS/ HTTP2/ FTP/ SMTP and web sockets traffic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/100/1*TN_Jj_3lthrG5iEXyEwQbQ.png" /></figure><h4>Azure Front Door</h4><p>It is a global load balancer, here you can add on Azure CDN and WAF. It has 3 SKUs: standard, classic, and premium. Here you would have it handle global traffic and route it down to your region-specific load balancers. Its features are similar to the Application Load Balancer but come with a cache, traffic acceleration, URL rewrite/redirect, DDOS protection, end-to-end TLS encryption, and geo-filtering.</p><p>This is for when multi-region support is required and the need to manage large amounts of traffic which usually comes with a medium to a large business that requires high availability, redundancy, security, and services being requested from all over the world. Not a service you’d set up for a very small business or side project due to cost.</p><h4>DNS</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/100/1*DusJ6meGHQqMZ1QPjZNtxA.png" /></figure><h4>Azure Traffic Manager</h4><p>Is a globally scalable DNS routing service. It would route inbound requests to your DNS alias to the configured routing criteria. The key concept here is that your destination needs to be public.</p><p>An example would be you have multiple applications in different regions and maybe some on-premises domains and you want to set up a single DNS record usually a CNAME and have Traffic manager route traffic to each of the configured downstream routes.</p><h4>Summary</h4><p>Load balancers assist with <strong>security</strong>, <strong>redundancy</strong>, <strong>high availability</strong>, <strong>scaling</strong>, encryption, <strong>health probes</strong>, and <strong>routing rules</strong> to name a few. I would say it is something to strongly consider in a production environment if the aforementioned attributes are important to your application or customers. You can review Microsoft’s more detailed <a href="https://learn.microsoft.com/en-us/azure/architecture/guide/technology-choices/load-balancing-overview">overview</a> of solutions and how to combine them to get the best load-balancing solution for your system.</p><p>Thanks for taking the time out of your busy day to either read or skim over this article, your feedback is most welcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5827da0bf14d" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/overview-azure-load-balancing-5827da0bf14d">Overview: Azure load balancing</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CQRS & Mediator Part 2: Domain scaffolding with Roslyn API and Dotnet CLI]]></title>
            <link>https://itnext.io/cqrs-mediator-part-2-domain-scaffolding-with-roslyn-api-and-dotnet-cli-7c99b5b011f?source=rss-792c6fc8066e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c99b5b011f</guid>
            <category><![CDATA[mediatr]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[cqrs]]></category>
            <category><![CDATA[mediator-pattern]]></category>
            <category><![CDATA[roslyn]]></category>
            <dc:creator><![CDATA[Armand Jordaan]]></dc:creator>
            <pubDate>Mon, 10 Feb 2020 05:49:53 GMT</pubDate>
            <atom:updated>2020-02-10T08:04:07.562Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fYUK9H4TJ9gWiyA1x_hUOA.jpeg" /><figcaption>Waterfall at Jewel of Changi, Singapore</figcaption></figure><blockquote>In part 2 we will be building a dotnet CLI tool which follows the CQRS and Mediator patterns to auto generate commands, queries, responses and handlers in the domain layer using Roslyn API for code generation. <a href="https://github.com/ArmandJ77/CQRSAndMediator-Scaffolding">Git Repo</a></blockquote><h3>Series</h3><ul><li><a href="https://itnext.io/why-and-how-i-implemented-cqrs-and-mediator-patterns-in-a-microservice-b07034592b6d">CQRS &amp; Mediator Part 1: <br>Why and how I implemented CQRS and Mediator patterns in a microservice</a></li><li><a href="https://medium.com/@armandjordaan6/cqrs-mediator-part-2-domain-scaffolding-with-roslyn-api-and-dotnet-cli-7c99b5b011f">CQRS &amp; Mediator Part 2: <br>Domain scaffolding with Roslyn API and Dotnet CLI</a></li></ul><h3>Problem</h3><p>The most glaring challenge of the CQRS pattern is to overcome the number of classes a developer is required to create and can become cumbersome when constantly creating queries, commands, handlers, and response objects.</p><p>To solve this problem, this article will walk you through the process of creating a command-line scaffolding tool that can accept parameters such as the pattern type, concern, and operation. Resolve the paths and name of the domain in which directory we are executing the CLI command. Not only should it create the corresponding CQRS classes, but it will also add the class inheritance and implement the handle function of the IRequestHandler interface with the correct method signature.</p><p>This tool will enable less friction and context switching when creating the objects and perform the method wire ups correctly with the correct naming conventions, thus providing the developer with consistency across the domain and enable them to focus on the implementation rather than the abstraction.</p><p>In short. Enable developers to automate the repetitive and innovate in the unknown.</p><h3>Tooling</h3><p>If you are already familiar with the below concepts and tools skip ahead to the solution section for the code break down.</p><p><strong>What is the Dotnet CLI?</strong></p><blockquote>The .NET Core command-line interface (CLI) is a cross-platform tool chain for developing .NET applications. The CLI is a foundation upon which higher-level tools, such as integrated development environments (IDEs), editors, and build orchestrators, can rest. — <a href="https://docs.microsoft.com/en-us/dotnet/core/tools/?tabs=netcore2x">MSDN</a></blockquote><p>Opinion: I prefer a UI over command line but the Dotnet CLI is a really powerful tool and yes for the Visual Studio users(myself included)the IDE is powerful with a rich feature set and advanced tooling support but at time of writing VS on windows still does not handle multi-project solutions all that well when it comes to load and build speeds — dies a little inside every time when opening a monolith with VS. :(</p><p><strong>What is NuGet?</strong></p><blockquote>An essential tool for any modern development platform is a mechanism through which developers can create, share, and consume useful code. Often such code is bundled into “packages” that contain compiled code (as DLLs) along with other content needed in the projects that consume these packages. — <a href="https://docs.microsoft.com/en-us/nuget/what-is-nuget">MSDN</a></blockquote><p><strong>What is Roslyn?</strong></p><p>It is the .NET compiler platform AKA Roslyn, it provides C#/ Visual basic, developers with access to the .Net compiler and rich code analysis APIs. Like most of the Dotnet world, this is open source and can be found at <a href="https://github.com/dotnet/roslyn">GitHub</a>.</p><p>The API we will be working with is <em>Microsoft.CodeAnalysis </em>and <em>Microsoft.CodeAnalysis.CSharp. </em>Like most APIs/libraries, there is a learning curve and it is quite intimidating when you first start, however after looking at some implementation examples and classic RTFM it works like any other API having its concepts and ways of work.</p><h3>Patterns</h3><h4>Fluent Interface Pattern</h4><p>In short, it is a type of builder pattern that allows for the collection of data by specifying a list of functions on an object using method chaining.</p><p>This can be implemented as follows:</p><p>Usage:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/928a5e22797af38f086dbbb480b4df75/href">https://medium.com/media/928a5e22797af38f086dbbb480b4df75/href</a></iframe><p>Implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7ddcc51250420a41bbb61e010d48e7d/href">https://medium.com/media/b7ddcc51250420a41bbb61e010d48e7d/href</a></iframe><p>What stands out from this pattern is that you can use the interface return types to define specific logic paths, thus I’d recommend you to first define the interfaces and how the logic will flow and review each possibility.</p><p>For a more detailed break down of this pattern I recommend Dimitrie Tataru’s article on <a href="https://assist-software.net/blog/design-and-implement-fluent-interface-pattern-c">How to Design and Implement the Fluent Interface Pattern in C#</a></p><h3>Usage</h3><p><strong>Installation:</strong></p><pre>dotnet tool install --global CQRSAndMediator.Scaffolding</pre><p><strong>Breakdown of concepts and commands:</strong></p><p>Show help information:</p><pre>scaffold -h</pre><h4>Command Parameters:</h4><p>Concern: Name of the domain area you are working in i.e Orders, People, Invoice, etc.</p><pre>-c|--concern &lt;NAME&gt;</pre><p>Operation: Name of the action you are taking in your concern i.e GetById, GetPagedResult for queries or Create, Patch, Update for commands.</p><pre>-c|--concern &lt;NAME&gt;</pre><p>OperationType: The type of CQRS operation you are scaffolding i.e command or query</p><pre>-ot|--operationtype &lt;TYPE&gt;</pre><p>GroupBy: Specify how to group the domain actions. Either by <em>concern</em> or <em>operation</em>: Group domain objects by [C] for concerns or [O] for operations, defaults to concerns</p><pre>-g|--groupBy &lt;TYPE&gt;</pre><p>By concern: i.e group by concern when parameters are -c Orders -o GetById</p><p>-ot query</p><pre>| YourDomainLayer<br>    | Orders<br>        | Handlers<br>            | OrdersGetByIdHandler.cs<br>        | Responses<br>            | OrdersGetByIdResponse.cs<br>        | Queries<br>            | OrderGetByIdQuery.cs</pre><p>By operation i.e group by the operation when parameters are -c Orders -o GetById -ot query -g O</p><pre>| YourDomainLayer<br>    | Handler<br>        | OrdersGetByIdHandler.cs<br>    | Responses<br>        | OrdersGetByIdResponse.cs<br>    | Queries<br>        | OrderGetByIdQuery.cs</pre><p><strong>Note: <br></strong>The tool requires that the project is set up already and that the actions are executed in the top-level directory of where your domain layer directory is located.</p><p><strong>Example commands:</strong><br>Use case scaffold out the CRUD domain for an invoice:</p><p>The create command when grouping by concern</p><pre>scaffold -c Invoices -o Create -ot command</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ti1jhWMrXgnpjoQvk5btA.png" /><figcaption>Scaffold the InvoicesCreateCommand</figcaption></figure><p>The get by id query when grouping by concern</p><pre>scaffold -c Invoices -o GetById -ot query</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k4OHohh2lmPx4ypHfzmFVg.png" /><figcaption>Scaffold the OrdersGetByIdQuery</figcaption></figure><p>The GetPaged query when grouping by operation</p><pre>scaffold -c Orders -o GetPaged -ot query -g o</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e3_7vELTsQouORK4tlZU9w.png" /><figcaption>Scaffold the OrdersGetPaged</figcaption></figure><p>The OrderCancelledCommand when grouping by operation</p><pre>scaffold -c Orders -o Cancelled -ot command -g o</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cqdR7DdY8rYaH0KMoacNaw.png" /><figcaption>Scaffold the OrderCancelledCommand</figcaption></figure><p>Using CRUD operations is just an example without having to explain complexities and rules around a specific domain language. At the end of the day, the CQRS pattern doesn&#39;t care if it is a CRUD operation or a complex domain rule it all comes down to a command or a query.</p><h3>Solution</h3><p>We will be taking a look at the NuGet package’s project and how it has been implemented. The tool will be executed in Part 1’s solution structure thus will only focus on the output and not deep dive into the domain setup of the targeted solution’s domain layer. See <a href="https://itnext.io/why-and-how-i-implemented-cqrs-and-mediator-patterns-in-a-microservice-b07034592b6d">part 1</a>.</p><h4>Structure:</h4><p>I chose not to split the project into multiple layers of libraries, instead opted for a simpler subdirectory structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*m78XiSsTX7vz-urEnGyHhw.png" /><figcaption>Dotnet CLI project structure</figcaption></figure><ul><li><strong>Program.cs:</strong> Application entry point.</li><li><strong>Builders:</strong> Contains the implementation of the fluent interface pattern of the ClassAssembler.cs</li><li><strong>Infrastructure:</strong> Contains the definition of the fluent interface pattern which wraps our implementation of the Roslyn API.</li><li><strong>Models:</strong> Contains general object structures used across the application</li><li><strong>Enums:</strong> Contains general types used across the application</li><li><strong>nupkg:</strong> Contains the NuGet package information generated for each version and is uploaded to NuGet.org to update the package to the latest version — may automate the project build with Github Actions at a later date.</li></ul><h4><strong>Code Deep Dive:</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41958dbaaf753883102d3ded43333ac4/href">https://medium.com/media/41958dbaaf753883102d3ded43333ac4/href</a></iframe><p>Line 14–39: Initialization of command input parameters.</p><p>Line 43–77: Input parameter validation</p><p>Line 79: Invoke a response builder class to scaffold out the response directory and supporting classes in the targeted domain.</p><p>Line 81–95: Add logical split on Operation Type, then invoke the Query Builder object to scaffold out the query directory and supporting objects in the targeted domain.</p><p>Line 97: Invoke the Handler builder object to assemble and create the handler class for our targeted domain.</p><p><strong>Note</strong>: <em>Log</em> is a static object containing <em>Error(string)</em> and <em>Info(string)</em> functions used throughout the application to standardize log messages.</p><h4><strong>Builders:</strong></h4><p>The idea of this layer is to abstract the Roslyn API implementation from its usage. All 4 builders have the same pattern.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00fe3bd4c67dc9a93eee5eb5115fb7d1/href">https://medium.com/media/00fe3bd4c67dc9a93eee5eb5115fb7d1/href</a></iframe><p>The most complex use case of the ClassAssembler.cs, it is important to note that line 24–43 is where we make use of our fluent interface pattern. This is replicated to the other 3 builders each passing parameters to the ClassAssembler based on the use case.</p><p>Line 12–16: Logical split to build the name of the command/query object used on line 39.</p><p>Line 18–22: Logical split to build up the commands/queries namespace which needs to be added at the top of the handler class. Uses the utility function on line 46–51.</p><p>Line 25: Provide basic configuration details and the instantiation of the ClassAssember.</p><p>Line 26: Pass a list of Namespaces to add to the top of the Handler.cs class i.e import using directive as per Roslyn API.</p><p>Line 35: Creates the namespace declaration. A similar example would be equivalent to the line 6 but with the generated namespace name.</p><p>Line 36: Creates a class declaration.</p><p>Line 37: Specify which interfaces to inherit from.</p><p>Line 41: Instruct the ClassAssembler to implement the IRequestHandler’s handle function.</p><p>Line 42: Instructs the ClassAssembler to add the class metadata to the namespace and then adds the namespace metadata to Roslyn’s SyntaxFactory. Then convert the syntaxFactory node to a string, creates the directories as specified per the operation type and writes out the C# object to disk.</p><h4><strong>ClassAssembler:</strong></h4><p><strong>Initialization:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/078c7503ff82797759ee2d7d60971ff6/href">https://medium.com/media/078c7503ff82797759ee2d7d60971ff6/href</a></iframe><p>Line 7: Called from the builders to start the process.</p><p>Line 1–5: The only constructor for the ClassAssembler.</p><p>Line 3: Creates/assigns a new instance of the DomainSettingsModel to the private _settings property. This DomainSettingsModel builds up all the directories and metadata about the targeted Domain’s projects absolute path, domain name, domain absolute path, etc.</p><p><strong>Namespace addition and creation:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3a2721072c273ab18dbe007ef203834/href">https://medium.com/media/d3a2721072c273ab18dbe007ef203834/href</a></iframe><p>Line 1–9: Is responsible for adding/importing all the namespaces the class we are trying to create will use. i.e <em>using System</em> or using YourDomainName.Orders.Handlers.</p><p>Line 14–27: Will create the namespace for the current class which is being generated.</p><p><strong>Class Creation:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64910203fb8f8dc7c4f38185266bb082/href">https://medium.com/media/64910203fb8f8dc7c4f38185266bb082/href</a></iframe><p>Line 4–5: Create a new public class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9333f1c61a670a365fab6e571fbb8af9/href">https://medium.com/media/9333f1c61a670a365fab6e571fbb8af9/href</a></iframe><p>Line 8–9: Adds the types to inherit from the class declaration.</p><p>The <em>ImplementMediatorHandler</em> function is specific to the handler builder.</p><p>Line 16: Declare and add to the function’s syntax that it should throw a not implemented exception. This of course where you would add your handler’s implementation detail.</p><p>Line 17–21: Create an array that would contain the parameter list of the method signature along with the parameter name and its type.</p><p>Line 23–26: Declare a method named “Handle”, that is public, with our specified parameter list(17–21) and the method’s body syntax(line16).</p><p>Line 28: Add the method declaration to the class that we are building.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4cb81b251525d4a7ed1fae76a9a1dfe/href">https://medium.com/media/e4cb81b251525d4a7ed1fae76a9a1dfe/href</a></iframe><p>Line 3: Add the generated class to the namespace.</p><p>Line 5: Add the namespace to the SyntaxFactory.</p><p>Line 7: Get Syntaxfactory as a string.</p><p>Line 11–23: Build up directory structures based on the operation type and grouping strategy.</p><p>Line 25: Write out the C# file to the directory with the string from line 7.</p><p>Line 28: Reset the _class, _namespace, and _syntaxfactory to null.</p><h3>Conclusion</h3><p>Building code generation tools with the Roslyn API is a dream, no more T4 template weirdness, and poor code editor support. — if you haven&#39;t worked with T4 templates consider yourself lucky. Should you find yourself building an API once in awhile using these patterns then this tool is just overkill, however when you need to output a high amount of features and build out various microservices that would benefit from these patterns then a code generation tool might assist greatly.</p><p>The future of this tool is not known yet. However, there is potential. Like pointing the scaffolding command to a DB entity and scaffold the entire CRUD operation right up to the stack to the controller layer, a CLI command to add a filter to a handler, or scaffold out the objects required to publish/subscribe from a message queue.</p><h3>Resources</h3><p><a href="https://assist-software.net/blog/design-and-implement-fluent-interface-pattern-c">How to design and Implement the Fluent Interface Pattern in C# — Dimitrie Tataru</a></p><p><a href="https://github.com/natemcmaster/CommandLineUtils/blob/master/README.md">CommandLineUtils</a></p><p><a href="https://carlos.mendible.com/2017/03/02/create-a-class-with-net-core-and-roslyn/">Create a class with .NET core and Roslyn</a></p><p><a href="https://www.infoq.com/articles/dotnet-core-template-engine/">Using the .NET Core Templating Engine to Create Custom Templates and Projects</a> — <a href="https://www.infoq.com/profile/Matt-Ellis/">Matt Ellis</a></p><p><a href="https://docs.microsoft.com/en-us/dotnet/core/tools/?tabs=netcore2x">.NET Core command-line interface (CLI) tools</a></p><p><a href="https://docs.microsoft.com/en-us/nuget/what-is-nuget">An introduction to NuGet</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c99b5b011f" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/cqrs-mediator-part-2-domain-scaffolding-with-roslyn-api-and-dotnet-cli-7c99b5b011f">CQRS &amp; Mediator Part 2: Domain scaffolding with Roslyn API and Dotnet CLI</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why and how I implemented CQRS and Mediator patterns in a microservice.]]></title>
            <link>https://itnext.io/why-and-how-i-implemented-cqrs-and-mediator-patterns-in-a-microservice-b07034592b6d?source=rss-792c6fc8066e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b07034592b6d</guid>
            <category><![CDATA[cqrs]]></category>
            <category><![CDATA[mediatr]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[mediator-pattern]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <dc:creator><![CDATA[Armand Jordaan]]></dc:creator>
            <pubDate>Tue, 21 Jan 2020 18:54:10 GMT</pubDate>
            <atom:updated>2020-11-06T11:52:56.751Z</atom:updated>
            <content:encoded><![CDATA[<h3>CQRS &amp; Mediator Part 1: Why and how I implemented CQRS and Mediator patterns in a microservice</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hwb4RVZWnjjeZS7oW7QIDQ.jpeg" /></figure><blockquote>This post looks at why I chose the CQRS and mediator patterns, which libraries to use, multi-layered project structure, setup and how to apply them in a microservice context. <a href="https://github.com/ArmandJ77/CQRSAndMediator-Microservice">Git Repo</a></blockquote><h3>Series</h3><ul><li><a href="https://medium.com/@armandjordaan6/why-and-how-i-implemented-cqrs-and-mediator-patterns-in-a-microservice-b07034592b6d">CQRS &amp; Mediator Part 1: <br>Why and how I implemented CQRS and Mediator patterns in a microservice</a></li><li><a href="https://medium.com/@armandjordaan6/cqrs-mediator-part-2-domain-scaffolding-with-roslyn-api-and-dotnet-cli-7c99b5b011f">CQRS &amp; Mediator Part 2: <br>Domain scaffolding with Roslyn API and Dotnet CLI</a></li></ul><h3>Context</h3><p>But why though I hear you ask? Having worked with bloated domain classes where multiple functions are used to modify state and implement domain rules became increasingly difficult to debug, extend and review. Often I found that a business rule function implements multiple sub-rules that are repeated somewhere in the domain. Multiple layers of complex abstraction in an attempt to share the functionality or multiple developers implemented their strategies each advocating for different patterns and practices. But the largest challenge was that the codebase was in constant flux with ever-changing domain requirements from the business.</p><h3>Problem</h3><p>Some services start as CRUD apps but over time domains became more complex more rules but then developers change roles and the new one decides to either re-write the services or starts a complex refactor process which delays deliverable even further.</p><p>One of the bloated domain manager code smells is an increasing parameter list when injecting multiple interfaces.</p><p>Business logic grouped by domain concern e.g an Order Manger class containing every action possible on an order of which one of the functions would modify the state of another manager class.</p><p>Following the flow of a business rule would lead you to step through multiple managers and function across domains with no clear way to interpret the exact intention.</p><p>Testing becomes convoluted having to mock multiple interfaces when you simply want to test just that one new function. Some developers take short cuts an assume the huge manger test class will test it at some point thus making tests incomplete.</p><p>No validation on inbound requests done at the API level. Instead, the request is allowed to pass through the middleware layer, API layer and only validated in the manger’s action function. This causes bloated action functions and an essay of validation rules before getting to write the actual domain rule.<br> — This is time-consuming and annoying.</p><h3>Patterns</h3><p>Given the above, I had a look at the following patterns to refactor the service.</p><p><strong>CQRS Pattern</strong></p><p>In short, this pattern allows you to separate your create/update operations(commands) from your reads(queries) each returning their response models for clear segregation of each action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_9FxL9PqRbP6_y_tw95oxQ.png" /><figcaption>Example of CQRS with a single-tier project with the basic operation</figcaption></figure><p>This pattern can be applied in other cases whereby the API is split into two separate microservices, one for commands and the other for reads.</p><p>This is beyond the scope of this article but encourages you to check out this <a href="https://docs.microsoft.com/en-us/azure/architecture/patterns/cqrs">MSDN</a> article for more detail.</p><p>Some caveats, it does create overhead with regards to moving the logic from a centralized domain object into multiple action objects with a single handler function. But this creates a standard across your domain allowing you to build scaffolding templates on top of it.</p><p>In a later article, I will be building a dotnet CLI tool that will scaffold out the required classes thus leaving the developer to purely focus on solving the business problem.</p><p><strong>Mediator Pattern</strong></p><p>By promoting loose coupling this pattern implements a mediator object where other objects communicate with it rather than each other.</p><p>Given the example, the mailroom acts as the mediator for communications between the inbound letters and routes them to the correct destination.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1wteJCDw0Ix2jg7dHPPRCg.png" /><figcaption>Mailroom example of the Mediator pattern</figcaption></figure><p>I’d recommend this <a href="https://sourcemaking.com/design_patterns/mediator">site</a> for a detailed explanation, also great as a quick reference guide to various other patterns.</p><p>For example, we will not be rolling our mediator, instead, we will use the <a href="https://github.com/jbogard/MediatR">MediatR</a> library written by Jimmy Bogard also famous for creating the auto mapper library.</p><h3>Solution</h3><p>Build a dotnet core microservice targeting 3.1 to demonstrate the patterns. Whereby we move towards a more vertical architecture i.e break apart the bloated controller function into a sort of action class each implements a single function called handler and lets the MediatR library facilitate the communication between these handlers.</p><p>We will only be focusing on the API and Domain layers as the Test and DB layers are standard implementations you’d find in most dotnet core apps.</p><h4>Structure:</h4><p>It may be considered a best practice for more complex applications to break their services into a multi-layered project. One of the best trade-offs of using this is the clear separation of concern and that a change in one layer should not have to cause major architectural changes in another. Recommend this <a href="https://youtu.be/5OtUm1BLmG0">talk</a> for a broader overview of clean architecture and <a href="https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882">Clean Code by Robert C. Martin</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*Ja97m26_WVFYhu64JdvulQ.png" /><figcaption>Multi-layer Solution Structure</figcaption></figure><h4>API Layer</h4><p>API NuGet Packages</p><p><strong>API level validation:</strong></p><pre>Install-Package FluentValidation -Version 8.6.1<br>Install-Package FluentValidation.AspNetCore -Version 8.6.1<br>Install-Package FluentValidation.DependencyInjectionExtensions -Version 8.6.1</pre><p><strong>MediatR:</strong></p><pre>Install-Package MediatR -Version 8.0.0<br>Install-Package MediatR.Extensions.Microsoft.DependencyInjection -Version 8.0.0</pre><p><strong>JsonPatch:</strong></p><pre>Install-Package Microsoft.AspNetCore.JsonPatch -Version 3.1.0<br>Install-Package Microsoft.AspNetCore.Mvc.NewtonsoftJson -Version 3.1.0</pre><p><strong>Setup.cs</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f2ae12ecf26ce8596c288b6ba204073/href">https://medium.com/media/5f2ae12ecf26ce8596c288b6ba204073/href</a></iframe><p>Line 16:<br>Register Validation Filter middleware to the MVC request pipeline.</p><p>Line 18–21:<br>Register Fluent Validation classes that implement the AbstractValidator&lt;T&gt; classes.</p><p>Line 20:<br>Configure Fluent Validation to load from the Microservices.Logic assembly. Any validation class can be passed as &lt;T&gt;.</p><p>Line 26:<br>Load Domain settings and services.</p><p>Line 28:<br>Register classes which implements the IRequest&lt;T&gt; and IRequestHandlers&lt;TRequest,TResponse&gt; interfaces.</p><p>Line 30:<br>Add validation middleware within the MediatR request pipeline. It works on the same principles as regular middleware. This will provide domain-level validation when going from one handler to another while using the same validation class as the API level validation.</p><p><strong>Filters:</strong></p><p>A standard implementation of a Fluent validation middleware class whereby we check if the request’s model state is valid, extract the error messages and then instantiate own defined <em>ErrorResponse/ErrorModel</em> objects populated with the model state error message before instantiating a new <em>BadRequestObjectResult</em> with the <em>errorResponse </em>and return.</p><p>ValidationFilter.cs</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d52657e7a0925e3b2f52bb5c3f4ad8d/href">https://medium.com/media/1d52657e7a0925e3b2f52bb5c3f4ad8d/href</a></iframe><p>Should the inbound model contain any invalid properties we return at the middleware level without paying the processing costs of the request being validated down in the domain manager and reducing the constant need to write null checks and other mundane validation operations. Instead, we focus only on the domain rules and their requirements.</p><p>Once in the domain layer, we will take a look at reusing the Fluent Validation classes to ensure validation occurs when invoking a handler from another i.e domain level validation.</p><p><strong>Controllers:</strong></p><p>Like most examples you’ll find online we will start with a basic CRUD implementation i.e <em>OrdersController. </em>in the domain layer, I’ll discuss how to leverage more advanced features and where we can leverage the handlers.</p><p>OrdersController.cs</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b22590f725c716a17dbb9f1c785a62d/href">https://medium.com/media/4b22590f725c716a17dbb9f1c785a62d/href</a></iframe><p>Line 15–20:<br>The first thing you’ll notice is that the only dependency we inject here is the <em>IMediator </em>interface which the controller methods use to pass our commands and queries to. Mediator would resolve these requests to the correct handlers in the domain layer.</p><p>Lines 25, 33 &amp; 48:<br>Initialize and instantiate the query/command objects with the request parameters.</p><p>Lines 26, 34, 41 &amp; 49:<br>Invoke the send function on the <em>IMediator </em>interface to resolve the command/query to the corresponding handler.</p><p>Lines 27, 35, 42 &amp; 50:<br>Format response and return results.</p><h4>Logic/Domain Layer</h4><p>You might call it the logic layer or domain layer its the same thing, the place where all your domain rules live and where your hourly rates get generated from. Let’s be honest here doesn’t matter how advanced or how many patterns and practices your service implement chances are the money to be made is in the domain and not in communication or infrastructure setup.</p><p>This layer is where I believe the most money gets lost concerning time and refactoring costs. A domain that is not built for change or one where the business rules are in constant change will penultimately lead to costly refactors and wasted time to market.</p><p>I have found that developers also tend to spend in my opinion a break of 70/30 of their time in the initial phase more focused on project setup and infrastructure than the initial domain rules when they work in an environment where there are no project templates or core development support team present.</p><p>But why would I need a project template or this “core team” you speak off, as a service owner I want to build everything from the ground up because every domain is different and I need full autonomy in the service?</p><p>Great question! firstly the core team concept may be addressed in a future article as there are various factors like budget, personal/project constraints, etc. However, I believe that well-structured project templates which contain structure, middleware setup and installed internal/external NuGet packages will dramatically increase the effectiveness of your teams when looking at scaling your architecture as it gives the team lead or architect team somewhat of an oversite and assurance that most projects are getting started on the right foot. Yes, there are instances where the domain is either to unknown or hyper-specialized that a project template would get in the way. However, these projects are likely to be handled by senior devs and architects having experience in the area.</p><p>BUT enough opinion, let’s dive into the domain setup:</p><p><strong>NuGet Packages:</strong></p><pre>Install-Package FluentValidation -Version 8.6.1<br>Install-Package MediatR -Version 8.0.0<br>Install-Package Microsoft.AspNetCore.JsonPatch -Version 3.1.0</pre><p><strong>Project Structure:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*GtsNHNtKlUEfX-FsQOhLng.png" /><figcaption>Domain structure</figcaption></figure><p><strong>Note:</strong></p><ul><li>In the model directory, there is a OrderPatch Model which is not part of the CQRS pattern. It is used within the Patch function to apply the inbound changes to and used for comparison between the original order and the new changes.</li><li>As for the object mapping strategy, I have gone with extension functions on the <em>Order </em>entity located in the <em>Mappers.OrderMapper.cs.</em> the rule is to add mapping function here that is used in multiple handlers else instantiate and initialize the mapping in the handler function as it will only be utilized there. Other strategies may include the use of object-to-object mapping libraries such as <a href="https://automapper.org/">Automapper</a> or a custom implementation.</li></ul><p><strong>Config:</strong></p><p>ConfigureServiceCollectionExtensions.cs</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8ce2c9d166b8061c709de397b14d2ee/href">https://medium.com/media/d8ce2c9d166b8061c709de397b14d2ee/href</a></iframe><p><strong>Response, Commands &amp; Queries:</strong><br>Both are standard classes each implementing <em>MediatR’s IRequest&lt;TResponse&gt;</em> interface where the <em>TResponse is a standard C# </em>class i.e</p><p>OrderResponse.cs</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82d7aaae1a2509e7f867bfd1e4870373/href">https://medium.com/media/82d7aaae1a2509e7f867bfd1e4870373/href</a></iframe><p>GetOrderByIdQuery.cs</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fa622ab3bfe9a2bfaec73c1ec86d00a/href">https://medium.com/media/5fa622ab3bfe9a2bfaec73c1ec86d00a/href</a></iframe><p><strong>Handlers:</strong></p><p>PatchOrdersHandler.cs</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ea1af5bc18a7ef2249872bbdd4c2d2b/href">https://medium.com/media/6ea1af5bc18a7ef2249872bbdd4c2d2b/href</a></iframe><p>Each handler implements the <em>IRequestHandler&lt;TRequest,TResponse&gt; </em>interface. In this example, the handler will take in a <em>PatchOrderCommand </em>and return an <em>OrderResponse object</em>.</p><p>Additionally, this example implements the <em>BaseHandler</em> class which exposes the <em>DbContext </em>and the <em>IMediator </em>properties.</p><p><strong>Domain level validation:</strong></p><p>So earlier I mentioned this and the way it is being implemented is with the use of middleware within the MediatR request pipeline and Fluent Validation’s <em>AbstractValidator&lt;T&gt;</em> base class implementation in the <em>Validators</em> directory</p><p>Domain level validation with MediatR</p><h3>Conclusion</h3><p>Moving towards a more vertical architecture as benefits in its simplicity whereby a developer when making changes can fully focus on one tier of the architecture at a time. The domain becomes an uncluttered mess by limiting side effects and a clear intention of business rules comes to mind.</p><p>The largest trade-off which can be seen more as an annoyance is the amount of object creation. In the next article, I will be taking a look at the Roslyn APIs to build a dotnet CLI tool to scaffold out all the detail of a new handler leaving you as a developer to focus on the domain implementation and not be distracted by the infrastructure setup.</p><h3>Resources</h3><ul><li><a href="https://youtu.be/SUiWfhAhgQw">Vertical Slice Architecture — Jimmy Bogard</a></li><li><a href="https://youtu.be/Zygw4UAxCdg">Clean Architecture with ASP.NET Core 2.2 — Jason Taylor</a></li><li><a href="https://youtu.be/DngAZyWMGR0">Making Architecture Matter — Martin Fowler</a></li><li><a href="https://youtu.be/2JzQuIvxIqk">Validation using MediatR’s Pipeline Behaviours and FluentValidation | Clean .Net Core — Nick Chapsas</a></li><li><a href="https://youtu.be/YzOBrVlthMk">Clean ASP.NET Core API using MediatR and CQRS — Nick Chapsas</a></li><li><a href="https://lostechies.com/jimmybogard/2015/05/05/cqrs-with-mediatr-and-automapper/">CQRS with MediatR and AutoMapper</a></li><li><a href="https://medium.com/@ducmeit/net-core-using-cqrs-pattern-with-mediatr-part-1-55557e90931b">Using CQRS pattern with MediatR Part 1 — Duc Ho</a></li><li><a href="https://medium.com/@ducmeit/net-core-using-cqrs-pattern-with-mediatr-part-2-cc55763e83f0">Using CQRS pattern with MediatR Part 2 — Duc Ho</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b07034592b6d" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/why-and-how-i-implemented-cqrs-and-mediator-patterns-in-a-microservice-b07034592b6d">Why and how I implemented CQRS and Mediator patterns in a microservice.</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>