Azure Functions Durable Functions

Build stateful, reliable, long-running applications on serverless.

Orchestrate Complex Workflows

Learn how Durable Functions enable stateful orchestrations and client-callable, long running, or stateful http-endurable patterns in Azure Functions.

What are Durable Functions?

Durable Functions is an extension of Azure Functions that lets you write stateful functions and orchestrations in a serverless environment. It helps you manage the complexity of state, error handling, and retries in distributed applications.

With Durable Functions, you can implement patterns such as:

Getting Started with Durable Functions

Follow these steps to create your first Durable Function:

  1. 1
    Set up your development environment: Install the Azure Functions Core Tools and your preferred IDE (like Visual Studio Code). Ensure you have .NET, Node.js, or Python installed.
  2. 2
    Create a new Azure Functions project: Use the Functions Core Tools to initialize a new project and select the Durable Functions extension.
  3. 3
    Define your orchestration and activities: Write your orchestration logic (e.g., a C# class or a Python script) and the individual activity functions it calls.
  4. 4
    Run locally: Start the Azure Functions host locally to test your durable functions.
  5. 5
    Deploy to Azure: Publish your function app to Azure and configure the necessary storage account for state management.

Code Examples

1. Orchestrator Function (C#)

This orchestrator function chains together multiple activity functions.

// MyOrchestrator.cs using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.DurableTask; using Microsoft.Extensions.Logging; namespace FunctionApp { public static class MyOrchestrator { [FunctionName("MyOrchestrator")] public static async Task RunOrchestrator( [OrchestrationTrigger] IDurableOrchestrationContext context, ILogger log) { log.LogInformation("Starting orchestration..."); // Call activity functions var result1 = await context.CallActivityAsync("SayHello", "Tokyo"); var result2 = await context.CallActivityAsync("SayHello", "London"); var result3 = await context.CallActivityAsync("SayHello", "Paris"); var parallelResults = new List { result1, result2, result3 }; // Call another activity with the results var finalResult = await context.CallActivityAsync("ProcessResults", parallelResults); log.LogInformation($"Orchestration completed with result: {finalResult}"); return finalResult; } } }

2. Activity Function (C#)

This activity function performs a specific task.

// SayHello.cs using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.DurableTask; using Microsoft.Extensions.Logging; namespace FunctionApp { public static class SayHello { [FunctionName("SayHello")] public static string Run([ActivityTrigger] string name, ILogger log) { log.LogInformation($"Saying hello to {name}."); return $"Hello, {name}!"; } } }

Note: For detailed examples in Node.js, Python, and PowerShell, please refer to the official Azure Functions documentation.

Key Concepts

Next Steps

Dive deeper into specific patterns and advanced features:

Explore the Full Documentation