Yesterday, I had an opportunity to share technical knowledge with my colleagues at Forefront Consulting during our monthly meeting in our division Technology. I was glad to share insights and knowledge about the basics of one of my favorite Azure cloud services, Azure Durable Functions. Interesting questions came up that are worth checking out more.
Well, if you have not worked with Azure development or is not familiar with Azure technologies, probably this article is jargon to you. It would be hard to understand right away what it is. However, if you are curious what it is and how it can help solve some of your application development problems, this cloud service (if you are working with Azure) is worth checking out!
I hope that this article will enlighten you and give you the basics of it. I personally like to share that this great Serverless technology exists!
Serverless Computing is starting to gain its popularity these days, especially in the world of cloud development.
Serverless computing (or serverless for short), is an execution model where the cloud provider (AWS, Azure, or Google Cloud) is responsible for executing a piece of code by dynamically allocating the resources. And only charging for the amount of resources used to run the code. The code is typically run inside stateless containers that can be triggered by a variety of events including http requests, database events, queuing services, monitoring alerts, file uploads, scheduled events (cron jobs), etc. The code that is sent to the cloud provider for execution is usually in the form of a function. Hence serverless is sometimes referred to as “Functions as a Service” or “FaaS”. Following are the FaaS offerings of the major cloud providers:
AWS: AWS Lambda
Microsoft Azure: Azure Functions
Google Cloud: Cloud Functions
While serverless abstracts the underlying infrastructure away from the developer, servers are still involved in executing our functions.(Source:Serverless-Stack.com)
So, Serverless is not really without servers. The infrastructure exists - there are servers behind "Serverless". The only big difference is that the cloud provider like Microsoft Azure takes care of it for you so that you, your organization and development team can focus on solving and creating solutions with these cloud services like a Durable Functions.
Azure Durable Functions is an extension of Azure Functions
Azure Functions is a serverless solution that allows you to write less code, maintain less infrastructure, and save on costs. Instead of worrying about deploying and maintaining servers, the cloud infrastructure provides all the up-to-date resources needed to keep your applications running. You focus on the pieces of code that matter most to you, and Azure Functions handles the rest.
Azure Durable Functions on the other hand are built on top of Azure Functions. It is open-source. It does more than standard Azure Functions can do, especially when you have to develop a serverless long-running stateful workflow from the code along with the Azure Function in a serverless environment.
- Define and write workflows by code
- Create long-running tasks
- Have a need to work with multiple Azure Functions
- If you need to create serverless stateful workflows that require human interaction, monitoring, aggregation and more
- Need to make sure that the status of your workflow is consistent
- Focus on developer productivity
- Auto-scaling capabilities
- Pay only for what you use (Check out Azure Pricing Calculator)
- Integration with other cloud services
Behind the scenes, the Durable Functions extension is built on top of the Durable Task Framework, an open-source library on GitHub that's used to build workflows in code.
Like Azure Functions is the serverless evolution of Azure WebJobs, Durable Functions is the serverless evolution of the Durable Task Framework. Microsoft and other organizations use the Durable Task Framework extensively to automate mission-critical processes. It's a natural fit for the serverless Azure Functions environment.
Client functions are the entry point for creating an instance of a Durable Functions orchestration. They are the starting point of the entire process. Client Functions in Azure Durable Functions can run in response to an event from several sources, an event message posted to queue, HTTP request, or event stream event triggers, and more. Client functions can be written in different programming languages available and supported.
Below is an example of an HTTP Trigger Client that kick starts the orchestrator.
Orchestrator functions describe how actions are executed. It is an important part of Durable Functions. The workflow of actions should be in the order in which they are to run. When you write the orchestration logic in code, it is important that these functions are deterministic.
One great thing about the orchestrator is that it sleeps!
When it sleeps you do not get charge for the service. Stateful workflows solve some problems that normal Azure Functions cannot.
For function chaining pattern for example, the orchestrator sleep while the current activity is doing its tasks. When it is finished, then orchestrator wakes up to start the next activity and so on.
Here is my example of how a simple workflow code looks in an orchestrator.
Learn more about Deterministic APIs
Activity functions are the basic units of work in a durable function orchestration. An activity function contains the actual work performed by the tasks being orchestrated.
Entity functions define operations for reading and updating small pieces of state, known as durable entities.
Entity functions define operations for reading and updating small pieces of state, known as durable entities. Like orchestrator functions, entity functions are functions with a special trigger type, the entity trigger. Unlike orchestrator functions, entity functions manage the state of an entity explicitly, rather than implicitly representing state via control flow. Entities provide a means for scaling out applications by distributing the work across many entities, each with a modestly sized state. Read more about Entity Functions.
Durable Functions have different patterns that are worth checking out.
- Function Chaining
- Fan out/Fan in
- Async HTTP APIs
- Human Interaction
Read more about it Azure Durable Functions Patterns
There are important things to consider when designing and creating your stateful workflows with Durable functions. As mentioned, orchestrator workflows must be deterministic.
Check out the DOs and DONTs when coding your workflow in your orchestrator function.
- Microsoft Azure Functions Documentation https://docs.microsoft.com/en-us/azure/azure-functions/
- Microsoft Azure Durable Functions Documentation https://docs.microsoft.com/en-us/azure/azure-functions/durable/
- Azure Core Tools https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash
- Channel9 on Building Workflows with Durable Task Framework https://channel9.msdn.com/Shows/On-NET/Building-workflows-with-the-Durable-Task-Framework
I hope you learned something and became interested to learn more.
If you like this article, please re-share the knowledge!
Feel free to leave feedback and ask questions.
About Author: Jonah Andersson is a Filipina-Swedish Software Developer who codes full stack system development in C# .NET/NET Core. She currently works as a Software Developer Consultant at Forefront Consulting in Sweden. Jonah is passionate about continuous learning, developing and sharing knowledge about Microsoft Azure cloud technologies. She one of the #AzureHeroes in Sweden. A woman who codes in tech who enjoys writing, advocating gender equality in the tech industry through mentorship and by being role model on her spare time.