Durable Functions

Azure Durable Functions: COAE pattern, application patterns, orchestrator constraints, DTFx backends, bindings, and timer triggers.

Resources

  • Monitor scenario — Weather Watcher sample 1
  • DurableFunctionsMonitor: TaskHubNames 2, setup and run 3, Standalone mode 4
  • Create a long-running serverless workflow with Durable Functions 5
  • SPARK Conference Durable Functions Demo 6
  • azure-functions-core-tools — command line tools for Azure Functions 7
  • Work with Azure Functions Core Tools 8
  • Microsoft.Azure.WebJobs.Extensions.DurableTask NuGet package 23

COAE Pattern

Durable Functions are built around four function types:

  • Client function — entry point that starts orchestrations
  • Orchestrator function — defines the workflow as code
  • Activity function — performs a single unit of work
  • Entity function — manages durable state (Durable Entities)

Application Patterns

Pattern Description
Function Chaining a sequence of functions executes in order, output feeds the next
Fan-Out/Fan-In multiple functions execute in parallel, then aggregate results
Async HTTP APIs coordinates long-running operations with external clients via polling
Monitor recurring process that observes and reacts to external state changes
Human Interaction pauses workflow waiting for an external event (approval, etc.)
Aggregator (entity) aggregates event data over time into a single addressable entity

Orchestrations

  • Orchestrators can call activity functions, other orchestrators (sub-orchestrations), wait for external events, and use HTTP and timers
  • Sub-orchestrations support composition and parallel fan-out across child workflows

Entity Functions

Durable Entities provide a state management primitive:

  • Addressable by entity ID (entity name + key)
  • Support operation-based access (signal and call)
  • Entities serialize between operations — one operation at a time per entity
  • Two programming models: function-based and class-based

DTFx Backends

  • DurableTask.AzureStorage — default backend, least expensive
  • DurableTask.Netherite — combines Azure Event Hubs with FASTER 9, 10x throughput over Azure Storage
  • DurableTask.SqlServer — runs everywhere, multitenant

Task Hubs

A task hub is a logical container for storage resources used by orchestrations and entities:

  • Orchestrator and entity instances interact within the same task hub
  • Default backend uses Azure Storage queues, tables, and blobs scoped to a single task hub name

Instance Management

  • Query all instances, query with filters, send events to instances
  • Terminate, rewind, suspend, and resume instances
  • Purge instance history

Important Orchestrator Limitations

Orchestrator code is replayed on every rehydration to restore all local state (local variables, etc).

  • Follows the Event Sourcing stateful pattern
  • Function calls are never replayed — the outputs are remembered

This requires the orchestrator code to be deterministic:

  • Rule #1: Never write logic that depends on random numbers, DateTime.Now, Guid.NewGuid(), etc.
  • Rule #2: Never do I/O directly in the orchestrator function
  • Rule #3: Do not write infinite loops
  • Rule #4: Use the built-in workarounds for rules #1, #2, and #3

Code Constraints

  • No Thread.Sleep or Task.Delay — use CreateTimer
  • No DateTime.Now or DateTime.UtcNow — use CurrentUtcDateTime
  • No random — pass random values from activity functions
  • No environment variables — pass configuration from activity functions

Versioning

  • Side-by-side — deploy new version alongside old; route new instances to new code
  • Slot swap — deploy to staging slot, then swap
  • Avoid breaking changes to serialized orchestration state

Bindings

Trigger / Non-Trigger Bindings

  • Orchestration Trigger Binding: triggers orchestrator functions, polls control-queue, partition-aware, handles return values
  • Activity Trigger Binding: triggers activity functions, polls work-item queue, stateless, handles return values
  • Orchestrator Client: output binding, start new orchestrator instances, terminate instances, send event notifications, fetch instance status

Azure Storage

  • Queues: scheduled execution of activity functions
  • Table Storage: <taskhub>History contains execution history of all activities ran by orchestrator. <taskhub>Instances contains all the orchestrator instances ever started.
  • Blob Storage: used when Queues/Table Storage hits size limits

Actors/Monitor Pattern

Eternal Orchestrations

public static async Task Run(DurableOrchestrationContext ctx)
{
    int counterState = ctx.GetInput<int>();

    string operation = await ctx.WaitForExternalEvent<string>("operation");

    if (operation == "incr")
    {
        counterState++;
    }
    else if (operation == "decr")
    {
        counterState--;
    }

    ctx.ContinueAsNew(counterState);
}
public static async Task Run(DurableOrchestrationContext ctx)
{
    var jobInfo = ctx.GetInput<JobInfo>();

    while (ctx.CurrentUtcDateTime < jobInfo.ExpiryTime)
    {
        string status = await ctx.CallActivityAsync<string>("GetStatus", jobInfo);
        if (status == "Completed")
        {
            await ctx.CallActivityAsync<string>("SendAlert", jobInfo);
            break;
        }

        DateTime nextCheck = ctx.CurrentUtcDateTime.AddSeconds(30);
        await ctx.CreateTimer(nextCheck, CancellationToken.None);
    }
}

Official Documentation

  • What are Durable Functions? 10 — application patterns (chaining, fan-out/fan-in, async HTTP, monitor, human interaction, aggregator)
  • Durable Functions types and features 11
  • Durable orchestrations 12 — orchestration identity, reliability, history
  • Sub-orchestrations 13
  • Entity functions 14 — entity ID, operations, access, and coordination
  • Developer’s guide to durable entities in .NET 15 — definition, requirements, dependency injection, function-based syntax
  • Bindings for Durable Functions 16 — orchestration, activity, entity triggers and host.json
  • Task hubs 17
  • Manage instances 18 — start, query, terminate, send events, rewind, purge
  • Timers 19 — custom timeout and delay on IDurableOrchestrationContext
  • Orchestrator function code constraints 20
  • Durable Functions versions overview 21
  • Implement Durable Functions 22 — MS Learn module
  • Microsoft.Azure.WebJobs.Extensions.DurableTask 23
  • Guide for running C# Azure Functions in an isolated process 24

Timer Triggers

  • Timer trigger for Azure Functions 25
  • Dynamically set schedule in Azure Function 26
  • Create a function in the Azure portal that runs on a schedule 27
  • Azure Functions — Timer Triggers — Configurable Scheduled Expressions 28
< «