Serverless workflow orchestration – Azure Durable Function

Marcin Niesyn | Cloud Services | 29.11.2021


Business process automation is a natural transformation that most companies have to get on board with. It is not an easy process, as it requires knowledge and experience. But the battle is not yet lost! In this article, I would like to present the Azure Durable Function solution, an Azure Function Extension, which will allow you to proceed smoothly throughout the development process. Read on to find out more about serverless workflow orchestration.

What is Azure Durable Function?

Usually, the system we develop isn’t just “a set of functionalities or modules” (Function-as-a-Service), but rather “a set of multiple functionalities and modules influencing one another, dependent and interacting”. Thanks to the Azure Durable Functions, we are able to master this process. Azure Durable Function is the orchestrator controlling the entire business process, meaning our workflow. Durable Function is an extension of Azure Functions which allows you to optimize processes in a serverless environment.

Azure Durable Function consists of 3 basic types of blocks:

serverless workflow orchestration azure

Client Function

A kind of starter that gets the process up and running. It is most often triggered by an http request, adding a record to the database, uploading a file, etc.

Orchestrator Function

The process that controls our workflow – this is where we set up the sequence of steps in the process.

Activity Function

A specific functionality, e.g. retrieving a record from a database, sending an e-mail, issuing an invoice, etc.

Let’s explore Azure Durable Functions in practice

For the purposes of the article, let’s assume that we run a web fashion store, and after the payment has been credited, we want to present the customer with possible color versions and, once the decision has been made, close the order. The initial process would look like this:

serverless workflow orchestration azure

Now let’s try to answer the following questions:

  • How can we monitor what stage of the process the client is at?
  • How can we spot any errors?
  • Can we retry the step in the event of an error?
  • Can we parallelize the steps?
  • How can we receive confirmation of the event, i.e. the customer’s choice?

As you can see, there are a number of problems. The process is not perfect and cannot be easily controlled. Let’s get started and make sure it’s done right!
We begin with the ‘starter’:

serverless workflow orchestration

We have created a function that is triggered by an http request and receives information about the order. Its key element is the type object IDurableOrchestrationClient, which starts the selected process.

Azure Durable Functions – now let’s use the orchestrator

In its initial, simplified form, it might just look like this:

Azure Durable Functions

As you can see, it’s a place from which we can control the entire ordering process.
To put it very simply, without diving into too much detail, the individual steps of the process, i.e. the Activity Function, can look like this:

Azure Durable Functions

Let’s make modifications to find clear answers to the questions previously asked:

Azure Durable Functions
Azure Durable Functions

Now we can see the significant changes:

  • By using the method CallActivityWithRetryAsync we are able to repeat the step in case of an error.
  • Thanks to using the Fan-out Fan-in pattern, we made it possible to generate color versions much faster by parallelizing the processes.
serverless workflow orchestration azure
  • As you can see, through orchestration, we can easily use the construction Task. WhenAll to achieve the above goal.
  • By using the pattern Human Interaction we have managed to simulate the system waiting for user confirmation within a given period of 24 hours.
serverless workflow orchestration azure

The last question is: how do we monitor the state of the process? By default, after starting the orchestrator, we get a set of links to the list of workflow operations:

Azure orchestrator

So to monitor the current status of the process, just call statusQueryGetUri and as a result, you will get, for example:

Azure orchestrator

We see that the process is now over and it can be considered completed.

Benefits of Durable Functions

  • Durable Functions are based on Microsoft Azure – a platform that is used by hundreds of thousands of people on a daily basis.
  • Azure Durable Function can work in serverless mode, popularly known as pay-as-you-go – that is, you pay only for the time you use the service.
  • You can scale it freely depending on the load. There is no need to implement or set anything. The function will scale to such an extent as to speed up the task execution as much as possible.
  • Each functionality can be divided into separate, independently developed modules.
  • You can write each functionality (function) using a given language, e.g. C #, Java, JavaScript, Python etc.

Azure serverless functions – summary

To sum up, thanks to the use of Azure Durable Function, you can freely create complicated workflows and fully control them. Native functions can work with the entire cloud ecosystem, so the possibilities of expansion are endless. What’s more, there is an option to use containers of functions in the on-premise environment – but that’s a matter for a separate article.

The author of the post is:

Every day actively involved in the project implementation for JCommerce clients. He has been working in the profession for over 10 years. Specializes in solutions for web applications. After hours karate man, swimmer, dad.

Add comment: