Azure Functions Advanced

Durable patterns: fan-out, approvals and status APIs

Most Durable Functions workflows use a handful of patterns: chaining steps, fanning out work in parallel, long-running HTTP APIs, monitors, waiting for a human, and durable entities for small pieces of state.

Durable Functions patterns
  1. ChainingStep A, then B, then C, passing results along.
  2. Fan-out/fan-inRun many activities in parallel and combine results.
  3. Async HTTP APIReturn 202 and a status URL for long jobs.
  4. MonitorCheck a condition on a schedule until it is met.
  5. Human interactionWait for an approval event with a timeout.
  6. EntitiesSmall objects with state, updated one at a time.

Most workflows combine two or three of these.

Fan-out and fan-in

Start many activities at once, then wait for all of them. The work spreads across instances and the orchestrator combines the results.

C#
[Function(nameof(BuildReport))]
public static async Task<int> BuildReport([OrchestrationTrigger] TaskOrchestrationContext context)
{
    string[] regions = await context.CallActivityAsync<string[]>(nameof(GetRegions));

    var tasks = regions.Select(r => context.CallActivityAsync<int>(nameof(CountOrders), r));
    int[] counts = await Task.WhenAll(tasks);

    await context.CallActivityAsync(nameof(SaveReport), counts.Sum());
    return counts.Sum();
}

Waiting for a human, with a timeout

WaitForExternalEvent pauses the workflow, at no compute cost, until someone raises the event through the client API. A durable timer gives up after a deadline.

C#
using var cts = new CancellationTokenSource();
Task<bool> approval = context.WaitForExternalEvent<bool>("Approval");
Task timeout = context.CreateTimer(context.CurrentUtcDateTime.AddDays(3), cts.Token);

if (await Task.WhenAny(approval, timeout) == approval)
{
    cts.Cancel();
    await context.CallActivityAsync(approval.Result ? "PublishPost" : "RejectPost", postId);
}
else
{
    await context.CallActivityAsync("EscalateToManager", postId);
}

The other patterns

  • Function chaining: call activities one after another, passing each result to the next step.
  • Async HTTP API: start a long job and return 202 with a status URL; the client polls until it is done. This is the fix for the HTTP response time limit.
  • Monitor: a loop with durable timers that checks something until a condition is met, such as a job finishing or a price dropping.
  • Durable entities: small, addressable objects with state, such as a counter or a per-user rate limit, updated one operation at a time.
  • Sub-orchestrations and ContinueAsNew: split big workflows and restart eternal ones so their history stays small.

Practical tips

Keep inputs and outputs small; pass ids, not big payloads, because everything is saved to history.

Activities can run more than once, so keep them idempotent.

Use the task retry options on CallActivityAsync for transient failures inside a workflow.

Interview question

How would you implement an approval step that times out after three days with Durable Functions?

In the orchestrator I start WaitForExternalEvent for the approval and a durable timer for three days, then await Task.WhenAny. If the approval wins, I cancel the timer and continue; if the timer wins, I escalate or cancel. The approver's app raises the event through the Durable client. The instance uses no compute while waiting.

Your progress is saved only in this browser.

Want the full details? Read the official Microsoft documentation for this topic.