Durable Orchestrations - Azure Functions (2023)

  • Article
  • 12 minutes to read

Durable Functions is an extension ofAzure functions. You can use oneOrchestrator-Rolleto orchestrate the execution of other persistent functions within a function app. Orchestrator functions have the following properties:

  • Orchestrator functions define workflows of functions using procedural code. No declarative schemas or designers are needed.
  • Orchestrator functions can call other persistent functions synchronously and asynchronously. The output of called functions can be reliably stored in local variables.
  • Orchestrator functions are durable and reliable. Execution progress is checked automatically when the function "waits" or "gives". The local state is never lost when the process is recycled or the virtual machine is restarted.
  • Orchestrator roles can take a long time. The total useful life of aorchestration instancethey can be seconds, days, months or endless.

This article gives you an overview of Orchestrator features and how they can help you solve various application development challenges. If you're new to the types of functions available in a Durable Functions application, read theTypes of Persistent Functionsfirst article.

orchestration identity

Everyoneexampleof an orchestration has an instance identifier (also known asinstance identifier). By default, each instance ID is an automatically generated GUID. However, instance IDs can also be any user-generated string values. Each orchestration instance ID must be unique withintask center.

Here are some rules about instance IDs:

  • Instance IDs must be between 1 and 256 characters long.
  • Instance IDs must not start with@.
  • Instance IDs must not contain/,\,#, Ö?Characters.
  • Instance IDs cannot contain control characters.


In general, it is recommended to use automatically generated instance IDs whenever possible. User-generated instance IDs are intended for scenarios where there is a one-to-one mapping between an orchestration instance and an application-specific external entity such as an order or document.

The instance ID of an orchestration is a required parameter for mostInstance Management Operations. They are also important for diagnosis, such asBrowse orchestration trace datain Application Insights for analysis or troubleshooting purposes. For this reason, it is recommended to store the generated instance IDs in an external location (e.g. in a database or in the application logs) where they can be easily referenced later.


Orchestrator functions maintain their execution state by using reliableEvent-Sourcingdesign pattern. Rather than storing the current state of an orchestration directly, the Durable Task Framework uses an append-only store to record the entire series of actions that the function orchestration performs. An add-only store has many advantages over "dumping" the entire runtime state. Benefits include increased performance, scalability, and responsiveness. You also get ultimate consistency for transactional data and full audit trails and logs. Test reports support reliable compensation measures.

Durable Functions uses event sourcing transparently. Behind the scenes thatWait(Re#) itto produce(JavaScript/Python) in an orchestrator function returns control of the orchestrator thread to the Durable Task Framework dispatcher. In the case of Java, there is no special language keyword. Call instead.Wait()in a task, control of a returns to the dispatcherthrowable. The dispatcher then writes to memory any new actions that the orchestrator function has scheduled (such as calling one or more child functions or scheduling a persistent timer). The transparent commit action updates the orchestration instance execution history by adding any new events to the store, similar to an add-only record. Similarly, the commit action creates messages in memory to schedule actual work. At this point, the orchestrator function can be unloaded from memory. By default, Durable Functions uses Azure Storage for runtime state storage, but othersStorage providers are also supported.

When more work is assigned to an orchestration function (for example, when a response message is received or a persistent timer expires), the orchestrator wakes up and runs the entire function again from the beginning to recreate the local state. When your code tries to call a function (or perform some other asynchronous work) during playback, the Durable Task Framework queries the execution history of the current orchestration. If you find thatactivity functionalready executed and returned a result, reflects the result of this function and the orchestrator code continues to run. Replay continues until the function code ends or until you schedule a new asynchronous job.

(Video) The Different Patterns of Azure Durable Functions with Jonah Andersson


In order for the replay pattern to work correctly and reliably, the Orchestrator function codedeterministic. Non-deterministic orchestrator code can cause run-time errors or other unexpected behavior. For more information on orchestrator function code limitations, seeOrchestrator function code limitationsDocumentation.


When an orchestrator function emits log messages, the replay behavior can result in duplicate log messages being emitted. Watch themregistrationTopic for more information about why this behavior occurs and how to fix it.

history of orchestration

The Durable Task Framework's event-sourcing behavior is closely related to the Orchestrator function code that you write. Suppose you have an activity chain orchestration function, e.g. For example, the following orchestration function:

  • C#
  • JavaScript
  • Felshaken
  • Power Shell
  • Java
[FunctionName("HelloCities")]Public Static Asynchronous Task<List<string>> Execute( [Orchestrierungsauslöser] IDurableOrchestrationContext-Kontext){ var output = new List<string>(); output.Add(await context.CallActivityAsync<string>("SayHello", "Tokyo")); Outputs.Add(await context.CallActivityAsync<string>("SayHello", "Seattle")); Outputs.Add(await context.CallActivityAsync<string>("SayHello", "London")); // gibt ["Hallo Tokio!", "Hallo Seattle!", "Hallo London!"] zurück.

Whenever an activity function is scheduled, the Durable Task Framework checks the execution status of the function in a durable storage backend (Azure Table storage by default). This condition is calledhistory of orchestration.

history table

In general, the Durable Task Framework does the following at each checkpoint:

  1. Save execution history to persistent storage.
  2. Queues messages for functions that the orchestrator wants to invoke.
  3. Queues messages to the orchestrator itself, e.g. B. Persistent timer messages.

Once the checkpoint is complete, the orchestrator function can be removed from memory until more work needs to be done.


(Video) S204 - Azure Durable Functions for serverless .NET orchestration - Jeff Hollan

Azure Storage does not provide transaction guarantees between storing data in table storage and queuing. To handle errors thatLong-lived capabilities Azure Storageprovider usedany consistencyPattern. These patterns ensure that no data is lost if a crash or connection loss occurs in the middle of a checkpoint. Alternative storage providers, such asDurable Functions MSSQL-Speicheranbieter, can provide greater guarantees of consistency.

When you're done, the function history shown above will look like the following table in Azure Table Storage (abbreviated for clarity):

partition key (instance id)event typetime stampEntryNameResultCondition
eaee885bExecution started2021-05-05T18:45:28.852ZNullHello cities
eaee885bscheduled task2021-05-05T18:45:32.670ZSay hello
eaee885bCompleted Orchestrator2021-05-05T18:45:32.670Z
eaee885bFinished homework2021-05-05T18:45:34.201Z"""Hello Tokyo!"""
eaee885bscheduled task2021-05-05T18:45:34.435ZSay hello
eaee885bCompleted Orchestrator2021-05-05T18:45:34.435Z
eaee885bFinished homework2021-05-05T18:45:34.763Z"""¡Hallo Seattle!"""
eaee885bscheduled task2021-05-05T18:45:34.857ZSay hello
eaee885bCompleted Orchestrator2021-05-05T18:45:34.857Z
eaee885bFinished homework2021-05-05T18:45:34.919Z"Hello London!"""
eaee885bCompleted Orchestrator2021-05-05T18:45:35.044Z
eaee885bExecution complete2021-05-05T18:45:35.044Z"[""Hallo Tokio!"",""Hallo Seattle!"",""Hallo London!""]"Finished

A few notes about the column values:

  • partition key: Contains the instance ID of the orchestration.
  • event type: Represents the type of event. You can find detailed descriptions of all kinds of historical eventshere.
  • time stamp: The UTC timestamp of the historical event.
  • Name: The name of the called function.
  • Entry: The JSON-formatted input for the function.
  • Result: The output of the function; that is, its return value.


While useful as a debugging tool, do not rely on this table. It is subject to change as the Durable Functions extension evolves.

Each time the function resumes after waiting for a task to complete, the Durable Task Framework runs the orchestrator function from scratch. On each iteration, it queries the execution history to see if the current asynchronous task is complete. If the execution history shows that the task has already been completed, the framework reflects the result of that task and moves on to the next task. This process continues until all execution history has been replayed. Once the current execution history was replayed, the local variables were reset to their previous values.

features and patterns

The following sections describe the features and patterns of orchestrator functions.


Orchestrator functions can call activity functions, but also other orchestrator functions. For example, you can create a larger orchestration from a library of orchestrator functions. Or you can run multiple instances of an orchestrator function in parallel.

For more information and examples seesub-orchestrationsArticle.

long-lasting Hours

Orchestrations can be scheduledlong-lasting Hoursto implement delays or to configure timeout handling for asynchronous actions. Use persistent timers in orchestrator functions instead of native language "sleep" APIs.

For more information and examples seelong-lasting HoursArticle.

external events

Orchestrator functions can wait for external events to update an orchestration instance. This Durable Functions feature is often useful for handling human interactions or other external callbacks.

(Video) Interacting with Orchestrations in Azure Durable Functions (#236)

For more information and examples seeexternal eventsArticle.

error handling

Orchestrator functions can use the error-handling features of the programming language. existing patterns likeattempt/captureThey are supported by the orchestration code.

Orchestrator functions can also add retry policies to the activity or sub-orchestrator functions they call. If a sub-orquesterer function or activity fails with an exception, the specified retry policy can automatically delay execution up to a specified number of times and try again.


When an unhandled exception occurs in an orchestrator function, the orchestration instance completes in aIt failedTo express. An orchestration instance cannot be retried after it has failed.

For more information and examples seeerror handlingArticle.

Critical sections (Durable Functions 2.x, currently .NET only)

Orchestration instances are single-threaded, so you don't have to worry about race conditions.Withinan orchestration. However, race conditions are possible when orchestrations interact with external systems. Orchestrator functions can be defined to mitigate race conditions when interacting with external systemscritical sectionsusing aLockAsyncMethod in .NET.

The following sample code shows an orchestrator function that defines a critical section. Include the critical sectionLockAsyncMethod. This method requires passing one or more references to apermanent unit, which permanently manages the lock state. Only a single instance of this orchestration can run the code in the critical section at a time.

[FunctionName("Synchronize")] Public Static Asynchronous Task Synchronization([Orchestration Trigger] IDurableOrchestrationContext context){ var lockId = new EntityId("LockEntity", "MyLockIdentifier"); using (await context.LockAsync(lockId)) { // critical section: you can only enter one orchestration at a time }}

IsLockAsyncacquires the permanent lock(s) and returns adisposablewhich ends the critical section when disposed of. ThisdisposableThe result can be used together with auseblock to get a syntactical representation of the critical section. When an orchestrator function enters a critical section, only one instance can run that block of code. Any other instance trying to enter the critical section will be blocked until the previous instance exits the critical section.

The critical sections feature is also useful for coordinating changes to persistent entities. For more information about critical sections, seePermanent Units "Coordination of Units"him.


(Video) Azure Durable Functions: Part 2 Orchestrations

Critical sections are available in Durable Functions 2.0 and later. Currently only .NET orchestrations implement this feature.

Invoking HTTP endpoints (Durable Functions 2.x)

Orchestrator functions cannot perform I/O operations as described inOrchestrator function code limitations. The typical workaround for this limitation is to wrap any code that needs to perform I/O operations in an activity function. Orchestrations that interact with external systems often use activity functions to make HTTP calls and return the result to the orchestration.

  • C#
  • JavaScript
  • Felshaken
  • Power Shell
  • Java

Orchestrator functions can use the to simplify this general patternCallHttpAsyncmethod to call the HTTP APIs directly.

public static asynchronous task [FunctionName("CheckSiteAvailable")]CheckSiteAvailable ([OrchestrationTrigger] IDurableOrchestrationContext context){ Uri url = context.GetInput<Uri>(); // Send an HTTP GET request to the specified endpoint Response DurableHttpResponse = await context.CallHttpAsync(HttpMethod.Get, url); if ((int)response.StatusCode == 400) { // Here comes the error code handling }}

In addition to supporting basic request/response patterns, the mechanism supports automatic handling of common asynchronous HTTP-202 query patterns and also supports authentication using external servicesManaged Identities.

For more information and detailed examples, seeHTTP functionsArticle.


Calling HTTP endpoints directly from orchestrator functions is available in Durable Functions 2.0 and later.

Pass multiple parameters

It is not possible to pass multiple parameters directly to an activity function. The recommendation is to pass an array of objects or compound objects.

  • C#
  • JavaScript
  • Felshaken
  • Power Shell
  • Java

In .NET you can also useWerttupelobjects. The following example uses new features ofWerttupeladded withrepeat #7:

[FunctionName("GetCourseRecommendations")]Public Static Asynchronous Task<Object> RunOrchestrator( [OrchestrationTrigger] IDurableOrchestrationContext context){ string major = "ComputerScience"; int collegeyear = context.GetInput<int>(); object CourseRecommendations = await context.CallActivityAsync<object>( "CourseRecommendations", (major, universityYear)); return CourseRecommendations;}[FunctionName("CourseRecommendations")]public static async Task<object> Mapper([Activity Trigger] IDurableActivityContext input){ // parse the student major and year input (string Major, int UniversityYear) studentInfo = entrance. GetInput<(string, int)>(); // Get and return course recommendations by major and year of study return new { major = studentInfo.Major, universityYear = studentInfo.UniversityYear, addedCourses = new [] { "Introduction to .NET Programming", "Introduction to Linux", " Becoming an Unternehmer" } };}

Next Steps

Orchestrator Code Limitations

(Video) Durable Functions #10: How to Write Safe Orchestrations


Which durable function manages the durable orchestration? ›

You can use an orchestrator function to orchestrate the execution of other Durable functions within a function app. Orchestrator functions have the following characteristics: Orchestrator functions define function workflows using procedural code.

What is orchestration in azure functions? ›

The orchestration client binding enables you to write functions that interact with orchestrator functions. These functions are often referred to as client functions. For example, you can act on orchestration instances in the following ways: Start them. Query their status.

What are durable functions in azure? ›

Durable Functions is an extension of Azure Functions that lets you write stateful functions in a serverless compute environment. The extension lets you define stateful workflows by writing orchestrator functions and stateful entities by writing entity functions using the Azure Functions programming model.

What is the difference between azure functions and durable functions? ›

Durable Functions is an extension of Azure Functions. You can use Durable Functions for stateful orchestration of function execution. A durable function app is a solution that's made up of different Azure functions. Functions can play different roles in a durable function orchestration.

Which is an orchestration tool of Azure? ›

Azure Kubernetes Service (AKS) is a fully managed Kubernetes container orchestration service in Azure that simplifies deployment and management of containerized applications. AKS provides elastic provisioning, fast end-to-end deployment, and advanced identity and access management.

How are durable functions triggered? ›

Azure Durable Functions can be invoked by any trigger provided by Azure Functions. These triggers include HTTP, blob storage, table storage, Service Bus queues, and more. They can be triggered manually by someone with access to them, or by an application. The preceding diagram shows a couple of triggers as an example.

What are two orchestration tools? ›

There are many container orchestration tools that can be used for container lifecycle management. Some popular options are Kubernetes, Docker Swarm, and Apache Mesos. Kubernetes is an open source container orchestration tool that was originally developed and designed by engineers at Google.

What are three parts of orchestration in cloud configuration? ›

Models of Cloud Orchestration

The multi-cloud configuration is a more difficult, but also more powerful model. Software-as-a-Service (SaaS), Platform-as-a-Service (PaaS), and Infrastructure-as-a-Service (IaaS) are the three delivery models for cloud services in general (IaaS).

Is orchestration the same as automation? ›

Orchestration is more complex than automation. It coordinates tasks, integrates systems, makes decisions based on outputs, and adapts to changing conditions. The goal of orchestration is to provide an overall view of automation technologies across the enterprise including low-code, RPA, AI, and legacy systems.

What is orchestrator management? ›

Orchestrator is a workflow management solution for the data center. With Orchestrator you can automate the creation, monitoring, and deployment of resources in your environment.

What is orchestration in Azure data Factory? ›

Azure Data Factory orchestrates the movement and transformation of data between various data stores and compute resources. You can create and schedule data-driven workflows (called pipelines) that can ingest data from disparate data stores.

What are orchestration systems? ›

An Orchestration System provides automated configuration, coordination and management of complex computing networks, systems and services. These systems are designed to reduce the time and manual manipulation required to align a business' applications, data and infrastructure.

Which of the following best describes the role of the orchestrator function in a workflow? ›

What best describes the role of the Orchestrator function in a workflow? It's used for describing how actions are executed and the order in which actions are executed.


1. An introduction to Azure Durable Functions
(Gwyneth Peña-Siguenza)
2. Deep dive in Durable Functions - Laurent Bugnion - NDC Oslo 2021
(NDC Conferences)
3. Serverless but Stateful! - Azure Durable Functions Are AWESOME!
(Nick Proud)
4. Durable Functions 2.0 - Serverless Actors, Orchestrations, and Stateful Functions
(Microsoft Visual Studio)
5. Function Orchestration in Azure
(Microsoft Reactor)
6. Windows Azure Durable Functions - Enabling long running function orchestrations.


Top Articles
Latest Posts
Article information

Author: Lilliana Bartoletti

Last Updated: 23/08/2023

Views: 5850

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Lilliana Bartoletti

Birthday: 1999-11-18

Address: 58866 Tricia Spurs, North Melvinberg, HI 91346-3774

Phone: +50616620367928

Job: Real-Estate Liaison

Hobby: Graffiti, Astronomy, Handball, Magic, Origami, Fashion, Foreign language learning

Introduction: My name is Lilliana Bartoletti, I am a adventurous, pleasant, shiny, beautiful, handsome, zealous, tasty person who loves writing and wants to share my knowledge and understanding with you.