wasAsked.

What is the difference between Azure Functions and Durable Functions?

Frequently Asked (All Companies) · Role not specified · technical

Published

Year not specified · Azure

Community answers

Posted by wasAsked editorial collection

Azure Functions is a serverless compute service for running small pieces of event-driven code. Durable Functions is an extension of Azure Functions that adds stateful, long-running workflows written in code. Azure Functions (regular) - Each function is triggered by an event: HTTP request, timer, queue or Service Bus message, Blob upload, Event Grid or Event Hubs event, Cosmos DB change feed. - Stateless: each execution is independent; any state must be stored externally (database, storage). - Best for short, independent tasks: processing a message, resizing an image, a webhook endpoint, a scheduled clean-up job. - Limits: execution time limits depend on the plan (for example 5 minutes by default and 10 maximum on the Consumption plan; HTTP triggers must respond within about 230 seconds). - Coordinating multiple steps manually requires queues, state tables and retry logic. Durable Functions - Adds three function types on top of regular functions: - Orchestrator functions: define a workflow in code (sequence, branching, parallelism, waiting). - Activity functions: do the actual work (call APIs, write to databases). - Entity functions: small, stateful objects (durable entities) such as counters or aggregators. - Plus a client (starter) function that starts and queries orchestrations. - The framework checkpoints progress automatically into a storage backend (Azure Storage by default, or MSSQL or the Durable Task Scheduler). If the process restarts, orchestrations resume where they left off. - Orchestrations can run for days or months, because each step is a short execution, and waiting does not consume compute. Example orchestrator (.NET isolated worker): [Function(nameof(ApproveExpense))] public static async Task<string> ApproveExpense([OrchestrationTrigger] TaskOrchestrationContext ctx) { var expense = ctx.GetInput<Expense>()!; await ctx.CallActivityAsync(nameof(NotifyManager), expense); using var cts = new CancellationTokenSource(); var approval = ctx.WaitForExternalEvent<bool>("ManagerDecision"); var timeout = ctx.CreateTimer(ctx.CurrentUtcDateTime.AddDays(3), cts.Token); if (await Task.WhenAny(approval, timeout) == approval && approval.Result) { cts.Cancel(); await ctx.CallActivityAsync(nameof(PayExpense), expense); return "Paid"; } return "Rejected or timed out"; } Patterns Durable Functions makes easy - Function chaining (step A, then B, then C). - Fan-out/fan-in (run many activities in parallel and aggregate results). - Async HTTP APIs (start a long job and poll its status URL). - Monitoring (polling until a condition is met). - Human interaction (wait for approval with a timeout). - Aggregation with durable entities. Rules for orchestrators - Must be deterministic, because orchestrations are replayed: use ctx.CurrentUtcDateTime instead of DateTime.UtcNow, ctx.NewGuid() instead of Guid.NewGuid(), and do I/O only in activities. When to choose which - Regular Functions: single-step, stateless event handling. - Durable Functions: multi-step workflows, long-running processes, human approvals, parallel processing with aggregation, or sagas with compensation. Interview summary: "Azure Functions run stateless, short-lived event handlers. Durable Functions add orchestrators, activities and entities with automatic checkpointing, enabling reliable stateful workflows that can run for long periods."

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics