Posts

Publisher — Subscriber Pattern with Azure

Image
  We can see in most of the modern applications consists of many modules and those modules requires lot of integrations among those to make the application to complete a business flow. Ex : In an event management system when a new event is registered , that registration module needs to notify the Venue Handling, Speaker Management and ticketing modules. It is very important that we keep publisher and the subscribers decoupled so we can introduce new modules (new features) to the system without changing the existing systems. Also modern systems requires high scalability we need to make sure publisher and subscriber integration happens asynchronously with out waiting. Publisher- subscriber model is one of the most commonly used pattern to solve the above business problem. When is comes azure there are many options for us to select as message broker, each of them seems quite similar to each other but each has its own strengths and weaknesses. Let’s first see what the messaging/ Events ser

Azure Durable Functions #4 – Orchestrator Constraints

There are some constraints when adding code in to the orchestrator code. It is because of the replay behavior in orchestrator. When you adding code in to Orchestrator make sure you follow the following rules. (Not hard to follow  :) ) 1. Orchestrator should be deterministic This means we should not add following type of code in to it. Getting current date time : This is because when it replays value will be changed Generating random numbers or Guids : This is because when it replays value will be changed Getting values from a DB : This is because when replayed values in the DB could be changed If you want to have such values in the orchestrator you could Pass it to orchestrator in the parameter when calling it Create a separate function activity to get the value and call it in the orchestrator 2. Orchestrator should be non blocking No I/O calls or Thread.sleep should be used 3. Orchestrator should never initiate any async operation This is because orchestrato

Azure Durable Functions #3 – Patterns : Fan In Fan Out

Image
Fan In Fan out is one of the main usages of Azure Durable Functions Fan-out/fan-in refers to the pattern of executing multiple functions in parallel, and then waiting for all to finish. Often some aggregation work is done on results returned from the functions. Let’s see how to achieve this pattern using Azure Durable Functions. If this is the first time you creating a durable function please follow my post Here , it will have the steps on how to create a durable function and activity functions. Problem to solve: You have to generate a invoice for a customer, which should include around 20 orders. So First you need to calculate the order amounts for each order then generate the complete invoice. let’s see how to solve this using Azure durable functions Fan In Fan Out Patten Step 1: Add two Activity Functions for orderCalculation & InvoiceGenerations public class OrderCalculationActivity { [FunctionName("OrderCalculationActivity")]

Azure Durable Function #2–Patterns : Function Chaining

Image
let’s discuss some common implementations of Azure Durable Function. If you want to learn what Azure Durable functions are please read my Previous Article Azure Durable Functions #1 Introduction " Function chaining refers to the pattern of executing a sequence of functions in a particular order. Often the output of one function needs to be applied to the input of another function” Problem to solve : You have a workflow with 3 steps you need to pass output of the previous step to the next steps. Lets solve this with Azure Durable Functions. Step 1: Create a HttpTrigger Function This will be the starter function which will call the orchestrator function. Step 2: Add Durable Function Nuget in to your Project Microsoft.Azure.WebJobs.Extensions.DurableTask Step 3: Add a new Function with Trigger Type – Durable Function Orchestrator Once you add the function you would see it comes with set of code for you. [FunctionName("Orchestrator")]

Azure Durable Functions #1 Introduction

Image
Azure Durable Functions are extension of Azure functions which let you write stateful functions in a serverless environment. Let’s discuss some key points about durable functions in this post. Why Durable Functions? Azure Durable functions came in to picture to solve some scenarios which was difficult to solve using regular azure functions. Issue 1 : Solving Fan in Fan Out Pattern Suppose you have an option in your application where user can select a particular customer and select to generate the invoice for a particular period and send customer and email. Customer would have around 50-75 orders and orders will have custom logics to handle based on order type. So you need to perform logic and calculate the order amount then sum the total amount. So basically you need to achieve following scenario. Solving such a pattern is not that easy with regular function. Issue 2 : Exception Handling in Function chain. You have a function chain. where you use azure queue to pass

Azure Function Binding Declaration Types

If you are familiar with azure function you may already know there are many types of binding. If you are new for azure function bindings you can read more details here . When adding an output binding for your function code there are two ways of doing it. 1. Declarative Binding 2. Imperative Binding Declarative Binding Suppose we have a CosmosDB output Binding. In Declarative Binding we can specify the binding details in the Run method parameter. This is the most common way most of us using public static class WriteOneDoc { [FunctionName("WriteOneDoc")] public static void Run ( [QueueTrigger("todoqueueforwrite")] string queueMessage, [CosmosDB( databaseName: "ToDoItems", collectionName: "Items", ConnectionStringSetting = "CosmosDBConnection")] out dynamic document, ILogger log) { document = new { De

Store your Event streams in Azure Event Hub

Image
Scenario : Suppose you have a CRM system where you manage all your Customer relationships. There will be 1000 of users connected in this system. You need to have a activity feed panel which will be visible in user’s home page where he can see the activities happening in their company. Ex: New appointment is added with a Customer who I am working with New Document has been added So you need to capture all the events triggering in your CRM system , process them and store to show in user’s activity feed pane. Problem to Solve: There will be thousands of events happening at a second so we need a proper messaging service to store the events which will auto scale with the events load and which enables batch processing and parallel processing. Solution: There are many storage options in azure which could solve the problem we have on hand. Picking what suits best is the tricky part. Lets compare few options available a pick the best. 1. Azure Service Bus Azure Service Bus mainly serving for en