Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Durable Functions Orchestration Patterns
📖 Scenario: You are building a cloud application that needs to run multiple tasks in a reliable and organized way. You will use Azure Durable Functions to create an orchestration that manages these tasks step-by-step.
🎯 Goal: Create a Durable Functions orchestration that runs three activities in sequence, passing data between them, and returns the final result.
📋 What You'll Learn
Create an orchestration function named OrchestratorFunction.
Create three activity functions named ActivityOne, ActivityTwo, and ActivityThree.
Call the activity functions in sequence inside the orchestration.
Pass the output of each activity as input to the next.
Return the final result from the orchestration.
💡 Why This Matters
🌍 Real World
Durable Functions help build reliable cloud workflows that manage multiple steps, like order processing or data pipelines, ensuring tasks run in order and recover from failures.
💼 Career
Understanding Durable Functions orchestration is valuable for cloud developers and architects working with Azure to build scalable, fault-tolerant applications.
Progress0 / 4 steps
1
Create the activity functions
Create three activity functions named ActivityOne, ActivityTwo, and ActivityThree. Each function should accept a string input and return a string output that appends its name to the input. For example, ActivityOne should return the input plus the string "-ActivityOne".
Azure
Hint
Define three async functions with the exact names and return the input string plus their function name.
2
Create the orchestration function
Create an orchestration function named OrchestratorFunction that accepts a context parameter. Inside it, create a variable input_name and set it to the string "Start".
Azure
Hint
Define an async function named OrchestratorFunction with context parameter and set input_name to "Start".
3
Call activity functions in sequence
Inside OrchestratorFunction, call ActivityOne using context.call_activity with input_name as input and save the result to result_one. Then call ActivityTwo with result_one and save to result_two. Finally, call ActivityThree with result_two and save to result_three.
Azure
Hint
Use await context.call_activity to call each activity with the correct input and save the output to the specified variables.
4
Return the final result from orchestration
At the end of OrchestratorFunction, return the variable result_three as the orchestration result.
Azure
Hint
Use a return statement to send back result_three from the orchestration.
Practice
(1/5)
1. What is the main role of an orchestrator function in Azure Durable Functions?
easy
A. To perform the actual work like processing data
B. To coordinate and manage the workflow of multiple tasks
C. To store data permanently in the cloud
D. To send notifications to users
Solution
Step 1: Understand the function types in Durable Functions
Durable Functions use orchestrator functions to manage workflows and activity functions to perform tasks.
Step 2: Identify the role of the orchestrator function
The orchestrator function controls the order and timing of tasks but does not do the actual work itself.
Final Answer:
To coordinate and manage the workflow of multiple tasks -> Option B
Quick Check:
Orchestrator = workflow manager [OK]
Hint: Orchestrator controls flow; activity does the work [OK]
Common Mistakes:
Confusing orchestrator with activity function
Thinking orchestrator stores data
Assuming orchestrator sends notifications
2. Which of the following is the correct way to call an activity function named ProcessOrder from an orchestrator function in C#?
easy
A. await context.CallActivityAsync("ProcessOrder", orderId);
B. context.CallActivity("ProcessOrder", orderId);
C. await CallActivityAsync("ProcessOrder", orderId);
D. context.CallActivityAsync("ProcessOrder");
Solution
Step 1: Recall the syntax for calling activity functions
In Durable Functions, the orchestrator calls activities using await context.CallActivityAsync with the function name and input.
Step 2: Check each option for correctness
await context.CallActivityAsync("ProcessOrder", orderId); uses the correct method with await, context, function name, and input parameter.
Final Answer:
await context.CallActivityAsync("ProcessOrder", orderId); -> Option A
A. An array with results from TaskA and TaskB in order
B. A single result from TaskB only
C. An empty array
D. A promise object instead of results
Solution
Step 1: Analyze the code execution flow
The orchestrator calls TaskA and waits for its result, then calls TaskB and waits for its result, pushing both into the outputs array.
Step 2: Understand the return value
Since both calls are awaited, outputs will contain the results of TaskA and TaskB in order.
Final Answer:
An array with results from TaskA and TaskB in order -> Option A
Quick Check:
Awaited calls return results in array [OK]
Hint: Await each call to get results in order [OK]
Common Mistakes:
Assuming only last result is returned
Thinking outputs is empty without awaits
Confusing promise with resolved value
4. You wrote this orchestrator function in C#:
public async Task<string> RunOrchestrator(IDurableOrchestrationContext context)
{
var result = context.CallActivityAsync<string>("DoWork", null);
return result.Result;
}
What is the problem with this code?
medium
A. It calls the wrong method for activity
B. It correctly returns the activity result
C. It misses the await keyword causing a compile error
D. It blocks the orchestrator causing a deadlock
Solution
Step 1: Identify async call usage
The code calls CallActivityAsync but does not await it, instead accesses result.Result synchronously.
Step 2: Understand deadlock risk in orchestrators
Accessing Result blocks the thread and can cause deadlocks in async orchestrator functions.
Final Answer:
It blocks the orchestrator causing a deadlock -> Option D
Quick Check:
Use await, not .Result, to avoid deadlocks [OK]
Hint: Always await async calls in orchestrators [OK]
Common Mistakes:
Using .Result instead of await
Ignoring async method patterns
Assuming synchronous access works fine
5. You want to run three activity functions Task1, Task2, and Task3 in parallel and wait for all to finish before continuing. Which orchestrator pattern correctly achieves this in JavaScript Durable Functions?
hard
A. await context.callActivity('Task1');
await context.callActivity('Task2');
await context.callActivity('Task3');
Step 1: Understand parallel execution in JavaScript
To run tasks in parallel, start them without awaiting immediately, collect promises, then await all together.
Step 2: Analyze each option
const tasks = [
context.callActivity('Task1'),
context.callActivity('Task2'),
context.callActivity('Task3')
];
const results = await Promise.all(tasks); creates an array of promises and awaits them all with Promise.all, running tasks concurrently.
Final Answer:
Use Promise.all with array of activity calls for parallel execution -> Option C
Quick Check:
Parallel = start all, then await all [OK]
Hint: Use Promise.all to await multiple tasks in parallel [OK]