Durable Functions
Azure Durable Functions is an extension of Azure Functions that enables you to write stateful functions in a serverless compute environment. Think of it as a way to orchestrate multiple Azure Functions into longer-running, reliable workflows.
Let me break this down into key concepts:
1 Core Components
a) Orchestrator Function
- This is like a conductor in an orchestra
- It defines the workflow and coordinates the execution of other functions
- Important: It must be deterministic (same input = same output every time)
- In your code, it's coordinating the processing of address data
[Function(nameof(WebHook))]
public static async Task<List<string>> RunOrchestrator(
[OrchestrationTrigger] TaskOrchestrationContext context)
b) Activity Functions
- These are the actual work units
- They perform the operations (like database calls, HTTP requests, etc.)
- They can be non-deterministic and perform I/O operations
- In your example, it's saving an address to a database
[Function(nameof(NewAddress))]
public async Task<string> NewAddress([ActivityTrigger] Address address, FunctionContext executionContext)
c) Client Function (Starter)
- This is the entry point that kicks off an orchestration
- Often triggered by an HTTP request, timer, or other trigger
- Creates a new instance of the orchestration
[Function("WebHook_HttpStart")]
public async Task<HttpResponseData> HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
[DurableClient] DurableTaskClient client,
FunctionContext executionContext)
2. Key Benefits
a. State Management
- Unlike regular Azure Functions, Durable Functions maintain state between executions
- They can pause and resume, waiting for external events or timeouts
b. Reliability
- Built-in checkpointing and replay mechanisms
- If a function fails, it can pick up where it left off
- Automatic retry of failed operations
c. Patterns Support
- Function Chaining (like in your example)
- Fan-out/Fan-in (parallel processing)
- Async HTTP APIs
- Monitoring
- Human interaction patterns
3. Real-world Analogy
Think of it like organizing a wedding:
- The Orchestrator is the wedding planner who coordinates everything
- Activity Functions are the vendors (caterer, photographer, etc.)
- The Client Function is like the initial meeting where you start planning the wedding
4. Common Use Cases
a. Process Automation
- Order processing
- File processing
- Approval workflows
b. API Integration
- Long-running operations with multiple steps
- Systems that need to coordinate multiple services
c. Complex Data Processing
- ETL operations
- Data validation and transformation pipelines
5. Important Considerations
a. Orchestrator Constraints
- Must be deterministic
- Shouldn't perform I/O operations directly
- Should delegate actual work to the activity functions
b. Monitoring
- Built-in support for tracking orchestration status
- Each instance has a unique ID for tracking
c. Error Handling
- Can implement retry policies
- Can handle exceptions at both orchestration and activity levels
No files yet, migration hasn't completed yet!