Azure Functions - Durable Functions

Build stateful workflows and complex orchestrations in the cloud.

What are Durable Functions?

Durable Functions is an extension of Azure Functions and Azure Logic Apps that lets you write stateful functions and stateful orchestrations in a serverless compute environment. It allows you to define and execute workflows that span across multiple function executions, maintaining their state between invocations.

This is achieved through a powerful programming model that leverages code-first orchestration. You write your orchestration logic as regular code (C#, F#, JavaScript, Python, PowerShell) and the Durable Functions extension handles the complexities of state management, checkpointing, and retries.

Key Concepts

Why Use Durable Functions?

Simplified State Management

Automatically manages state, checkpointing progress and resuming from failures without manual intervention.

Complex Workflows

Easily build intricate workflows like human interaction, dynamic branching, fan-out/fan-in patterns, and long-running processes.

Reliability and Resiliency

Built-in error handling, retry policies, and fault tolerance ensure your workflows complete reliably.

Cost-Effective Serverless

Leverage the pay-as-you-go model of Azure Functions for efficient execution of your stateful logic.

Developer Productivity

Write orchestrations in your preferred language, using familiar programming constructs.

Common Use Cases

Getting Started

To get started with Durable Functions, you'll need an Azure subscription and the Azure Functions tooling installed.

Example Orchestrator (Conceptual C#)

This is a simplified example showing how an orchestrator might call activity functions.


// This is a conceptual example, not runnable code.
// Requires Durable Functions SDK for C#.

using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using System.Threading.Tasks;

public static class SampleOrchestration
{
    [FunctionName("SampleOrchestration")]
    public static async Task RunOrchestrator(
        [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
        // Input can be passed to the orchestration
        string input = context.GetInput();

        // Call an activity function
        var result1 = await context.CallActivityAsync("ActivityFunction1", $"Processing {input}");

        // Make a decision based on the result
        if (result1.Contains("Success"))
        {
            // Call another activity function
            var result2 = await context.CallActivityAsync("ActivityFunction2", result1);

            // Perform a sub-orchestration
            var finalResult = await context.CallSubOrchestratorAsync("SubOrchestration", result2);

            return finalResult;
        }
        else
        {
            // Handle failure
            await context.CallActivityAsync("LogFailure", result1);
            return false;
        }
    }
}
        

For detailed guides, API references, and more code examples, please visit the official Azure Durable Functions Documentation.