DEV Community

Cover image for Azure Durable Functions - Developing Serverless Stateful Workflow
Jonah Andersson 👩🏻‍💻
Jonah Andersson 👩🏻‍💻

Posted on • Updated on

Azure Durable Functions - Developing Serverless Stateful Workflow

Knowledge Sharing Azure Durable Functions at my workplace

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.

What is Serverless and What are Azure Durable Functions?

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!

What is Serverless?

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

What are Azure Durable Functions?

Azure Durable Functions is an extension of Azure Functions

Azure Functions - 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 Microsoft Azure Functions handle the rest.

Azure Durable Functions on the other hand are built on top of Azure Functions. 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 Functions in a serverless environment.

Major Benefits of Using Azure Durable Functions

  • Define and write workflows by code
  • Create long-running tasks
  • Solves the need to work with multiple Azure Functions
  • Create serverless stateful workflows that require human interaction, wait for external events, monitoring, aggregation and more
  • Solve the 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 and APIs

Azure Durable Task Framework - The Technology Behind

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.

Major Components in Azure Durable Functions

Alt Text

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.

Alt Text

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.

Alt Text

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.

Alt Text

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.

Alt Text

Entity Functions is a recent addition to Azure Durable Functions. Although these feature is only available in Durable Functions 2.0 and above. They are currently supported in .NET and JavaScript (as of this date this articles publication).

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 Patterns

Durable Functions have different known patterns that are worth checking out.

  • Function Chaining
  • Fan out/Fan in
  • Async HTTP APIs
  • Monitor
  • Human Interaction

Read more about it in depth Azure Durable Functions Patterns

Best Practices of Developing Durable Functions (Orchestrator)

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.

Alt Text

Further Reading and Learning Resources

I hope you learned something and became interested to learn more.

If you like this article, please re-share the knowledge! There’s power in sharing knowledge.

Feel free to leave feedback and ask questions. Connect!


About Author: Jonah Andersson is a Filipina-Swedish Software Engineer who codes full stack system development in C# .NET, Microsoft Certified Azure Developer, Microsoft MVP for Azure, Mentor and AzureHeroes Inclusive Leader. 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. 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.

Follow me Twitter, connect via my LinkedIn, visit my website

Top comments (0)