Azure Durable Functions - An Overview

Using Azure Functions, we can quickly develop and deploy small pieces of code in the Azure Cloud environment. We can create the functions using any language or environment as per our choice. During the development of processes, we do not need to consider the building of an application or the infrastructure configuration. The function's runtime is always associated with the hosting and scaling of our code as events or Triggers, which can be an HTTP request or any other types like timers, messages, database-related, etc. 

What is a Durable Function?

Azure Durable Functions act as an extension of the Azure Function, which helps us operate long-lasting, stateful operations in the Azure environment. With the help of Durable functions, we can implement the state in the Azure Functions stateless pattern. By default, Azure maintains the infrastructure to support the information related to the state. Therefore, we can use the Durable Functions to implement the long-running workflow. In this way, we can use the benefit of the serverless hosting model. The Durable Functions framework manages the activity monitoring, synchronization, and run time issues. Duration Functions help us implement the complicated stateful process in a serverless environment.

In other words, the Azure Durable Function behaves like an extended version of the Azure Function. Using Azure Durable functions, we can develop a stateful function-based workflow in a serverless environment. We can build this stateful workflow by using different types of functions which perform various types of activities, and this type of function is known as the orchestrator function. The azure function is always considered a Software Switch since it takes data from the input parameters, processes the data, and performs the appropriate action. In the case of Durable Function, instead of using a single function as a switch, it always takes a series of functions and acts as a single unit, then builds in the workflow to manage the actions and handling waits pausing the function for the final decision. 

One of the significant benefits of the Azure function is its consumption-based or per-second-based costing model. It means we need to pay only for what we use. The same model also carries into the Durable Functions. Here also, we charged when the workflow was running. However, there is no charge calculated if the workflow is paused for waiting for some input data. When the workflow is broken, Durable Functions holds its state externally so that once the workflow is again started, it can pick up the state value and carry on the process.

Why are Durable Functions required?

So, before discussing the Durable functions application patterns, first, we need to understand the importance of the Azure Durable Functions. Then, this section will discuss the different advantages of the Azure Durable Functions. 

  1. With the help of Azure Durable Functions, we can develop an event-driven mechanism. The Durable function can wait asynchronously for different external events during the execution process. Then, after that external event, it can perform a series of tasks related to that particular event.
  2. In the Durable function, we can define our workflow in the code. In this process, we can understand the entire picture of what workflow will do. For this, we do not require to analyze the multiple functions.
  3. If the workflow contains any multi-step tasks or events, then there is a probability that some of the functions need to be executed in parallel. So, with the help of Durable Function frameworks, we can quickly implement the fan-in part of a fan-out-fan-in pattern. So, in Durable functions, parallel running events implementation can do easily, and also, we can perform the scale-out to bring the potential for speedup of the system.
  4. In process workflow, sometimes we need to wait for the execution of some external events or responses by the users or any external system to perform the following operation like sending or processing information. But the, at the time, we need to maintain some time interval that related response must be received within the mentioned time duration. Using Durable Functions, we can implement this type of functionality directly. It detects that the mentioned orchestration has stopped due to some operational response. It can also take some action to move it again or send an alert to the system administrator related to that delay.
  5. With the help of Durable Functions, we can easily manage the workflow states for us. We can implement complex workflows without using any database to maintain the shape. For example, if we want to use the database, we can use it to update the state of our business entities for tracking purposes. But we do not need to manage the state of the orchestration process in the database. The Durable Functions can handle it on its own. 
  6. In Durable Functions, we can find out the current state of the workflow processing by using the query status API. These APIs helps us to identify whether the orchestration is still running condition or not. Also, the query status API provides the showHistory flag, which provides the history of the workflow. It can help us identify where it got up before it struck or failed. 
  7. As the Durable Functions developed on top of the existing Azure Function models, we can benefit from the serverless pricing model. First, however, we need to pay for the time when our functions are running. Also, our orchestration functions invocations will be a rapid process to wake up, decide what next step in the workflow to execute, and go back to sleep mode until the next step is not completed.
  8. Finally, developing and testing the entire workflow in the local environment is possible before deploying it on the cloud for Durable Functions. We can use the whole debugging experience of stepping through the orchestration and activity functions. Also, after the workflow publishes for the Azure Cloud, we can use the Application Insights Integration, which provides us access to Function App telemetry and logs.

Duration Functions Application Patterns

We can divide the Azure Durable Functions into three different function types,

  • Client Function – In Azure Durable Function workflow, Client Function acts as an entry point. Client Function helps us to create an instance of a Durable Functions Orchestration. Client Function can be run as a response to any event from different sources like a new HTTP request arrives, a new message posted in a message query, etc. We can write and develop the Client Function in any supported language.
  • Orchestrator Function – The Orchestrator Function describes how the actions will be executed and maintain the order of the function execution. We can develop the Orchestrator logic using either C# or JavaScript language.
  • Activity Function – Activity Function acts as a basic unit of work within a duration function orchestration. The activity function contains the work performed by the orchestrated tasks. 

While we try to implement the Azure Durable Functions, we can follow different types of workflow patterns. These workflow patterns as below – 

  • Function Chaining – The defined workflow will execute in a sequence of functions in a mentioned order in this application pattern. The output of one function will act as an input for the following function in the sequence. The output of the final function is treated as a generated result. 

function chaining

  • Fan Out/Fan in – In this application pattern, multiple functions will be run parallel, and workflow will wait until all the function execution is completed. After that, we can collect all the results of the parallel execution function from computing the final results. 

function fan our or fan in

  • Async HTTP API – This pattern can be applied to solve the problem of communication state for a long-running operation with any external clients. An HTTP call can be executed for the long-running action in this workflow. After that, it can redirect the client to a status endpoint. So that the client can know when the operation is finished by calling this endpoint. 

http apis

  • Monitor – With the help of this pattern, we can implement a systematic process within a workflow, like checking for a state change. For example, we can use this pattern to poll until the mentioned specific conditions are matched. 

azure function monitor

  • Human Interaction – In this application pattern, we can implement automated processes that also involve some human/user interactions. A manual workflow within an automated process is always risky because people are not always available and not highly responsive, just like computers. So, we can incorporate the human interaction with the help of timeout and compensation logic. If the human fails to interact correctly within a specified response time, an automated process will execute on behalf of the human interactions. Any approval process is a perfect example of a process involving human interaction.

user interactions

Like Azure Durable Functions, Logic Apps is also an Azure Service that provides a serverless workload. Azure Durable Function mainly provides a powerful serverless compute option through which we can develop and run the custom logic. In the case of Azure Logic Apps, it is better to use for integrating Azure Services and components for the cloud environment. We can use the technology layer to implement complex orchestrations or can create them us. With the help of Azure Durable Functions, we can develop orchestrations workflow by writing code and using the Durable Functions extension. In the case of Azure Logic Apps, we can create orchestrations by using the design surface or editing the configuration files. The below tables demonstrate the key differences between the Azure Durable Functions and Azure Logic Apps. 

Task Azure Logic Apps Azure Durable Functions
Development Code Design – First Approach (declarative) Code First Approach (imperative)
Connectivity We can use an extensive collection of connectors. Can perform the Enterprise Integration Pack for B2B. Also, we can build custom connectors. We can use the available built-in binding types. Also, we can write down the code for custom bindings.
Actions Available large no of collection of ready-made actions. We can integrate custom logic by using custom connectors. Here each activity is an Azure Function. We can write code for the activity functions.
Monitoring Can monitor by using Azure Portal and Azure Monitor Logs. Can monitor by using Azure Application Insights.
Management Supports Azure Portal, REST API, PowerShell, Visual Studio, Visual Studio Code Extension. Supports REST API, PowerShell, and Visual Studio.

Conclusion

This article discussed the basic concept of Azure Durable Functions. Also, we discussed durable functions, why we need to use Azure Durables functions, and different application patterns related to the Azure Durable Functions. Any queries, suggestions, or feedback related to this article are welcome.