Posts

Showing posts from February, 2019

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 orchest...

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...