Overview
Azure Functions has picked up popularity because of their serverless nature. State management is still challenging with traditional Azure Functions so Microsoft went ahead to provide Azure Durable Functions.
I played with Azure durable functions to deal with a particular scenario and thought to share my experience.
Fan-out/fan-in
The scenario which took my interest in particular is Fan-out/fan-in. We basically parallelize the single operation to wait for all operations to complete and get the aggregated result. In simple words let’s say we are running shopping site and i want to check the status of my orders for last one week that are still in pending state or have been delivered.
Since we may be using external courier service and they may have API to provide us the real time tracking. If the count of orders that i am interested in last one week is 500, and each order status check from external API takes one seconds , you can imagine how much time i need to get the status of all my orders in realtime.
To deal with this scenario we can run the status check API function in parallel and aggregate the results.
My Experience
I created 2 function Apps to understand azure durable functions.
Mock API
My First azure function application simply mocking long running operation. Don’t dare writing code like this 🙂 . This is simply Http trigger azure function.
My Second Function App has 2 durable functions “Serial” and “Parallel”
Both the functions are trying to call the long running mock API (shown in previous step). Lets discuss one by one
Serial Function
As you can see below the Orchestration function is calling “extrnalAPICALLSerial” activity function. Which in turn is calling our Mock API azure function 100 times in a loop and waiting on result for each call.
I published azure function and here’s the result of serial function , and you can clearly see it took around 3mins 26 seconds , which is way too long and that too for only 100 records.
Parallel Function
Next I decided to to Fan out/Fan in using azure durable function and paralleize the tasks.
You can see below i am calling the same API 100 times but this time i am putting them all in tasks array and waiting on them all to complete.
You can see from result below that we are able to complete the function in only 17 seconds. That’s really a drastic change .
This simple example show how powerful durable function are and we can use them in many similar scenarios .
Resources
You can find more about durable functions and patterns here.
Can this be implemented for not durable Azure functions?