Running a long process in a standard Azure Function hits the 5-10 minute timeout. Durable Functions allows you to write stateful workflows in code. The most powerful pattern is Fan-Out/Fan-In.
The Scenario
You need to resize 10,000 images uploaded to Blob Storage.
[FunctionName("Orchestrator")]
public static async Task RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext context)
{
var blobs = await context.CallActivityAsync<List<string>>("GetBlobList", null);
var tasks = new List<Task<string>>();
foreach (var blob in blobs)
{
// Fan-Out: This schedules 10,000 functions in parallel!
tasks.Add(context.CallActivityAsync<string>("ResizeImage", blob));
}
// Fan-In: Wait for all to finish
await Task.WhenAll(tasks);
// Aggregation
await context.CallActivityAsync("SendReport", tasks.Select(t => t.Result).ToList());
}
Behind the scenes, the Durable Task Framework manages the Azure Storage Queues to track the state of every single function execution. It creates a robust checkpointing system automatically.
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.