Build stateful, reliable, long-running applications on serverless.
Learn how Durable Functions enable stateful orchestrations and client-callable, long running, or stateful http-endurable patterns in Azure 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:
Follow these steps to create your first Durable Function:
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;
}
}
}
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.
Dive deeper into specific patterns and advanced features:
Explore the Full Documentation