Bird
Raised Fist0
Azurecloud~10 mins

Durable Functions for workflows in Azure - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

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
Process Flow - Durable Functions for workflows
Start Workflow Trigger
↓
Orchestrator Function
↓
Call Activity Function 1
↓
Wait for Activity 1 Completion
↓
Call Activity Function 2
↓
Wait for Activity 2 Completion
↓
Complete Workflow
↓
Return Result to Caller
The workflow starts with a trigger, then the orchestrator calls activity functions one by one, waits for each to finish, and finally completes the workflow returning the result.
Execution Sample
Azure
async function orchestrator(context) {
  const result1 = await context.callActivity('Activity1');
  const result2 = await context.callActivity('Activity2');
  return result1 + result2;
}
This orchestrator function calls two activities in order, waits for each to finish, then returns the combined result.
Process Table
StepActionFunction CalledWaitingResultNext Step
1Start workflow triggerOrchestratorNoN/ACall Activity1
2Call Activity1Activity1YesN/AWait for Activity1 completion
3Activity1 completesActivity1No5Call Activity2
4Call Activity2Activity2YesN/AWait for Activity2 completion
5Activity2 completesActivity2No10Complete workflow
6Return combined resultOrchestratorNo15End
💡 Workflow ends after all activities complete and orchestrator returns combined result.
Status Tracker
VariableStartAfter Step 3After Step 5Final
result1undefined555
result2undefinedundefined1010
combinedResultundefinedundefinedundefined15
Key Moments - 3 Insights
Why does the orchestrator wait after calling an activity function?
The orchestrator pauses to wait for the activity function to complete and return a result before moving on, as shown in steps 2 and 4 in the execution_table.
Can the orchestrator call multiple activities at the same time?
Yes, but in this example it calls them one after another to keep the workflow simple and ordered, as seen in the sequential calls in the execution_table.
What happens if an activity function fails?
The orchestrator can retry or handle errors, but this example assumes success to keep the flow clear, focusing on waiting and result collection.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of result1 after step 3?
A5
Bundefined
C10
D15
💡 Hint
Check the 'Result' column at step 3 where Activity1 completes.
At which step does the orchestrator call Activity2?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'Function Called' column to find when Activity2 is called.
If Activity1 returned 7 instead of 5, what would be the final combinedResult?
A12
B17
C15
D10
💡 Hint
combinedResult is the sum of result1 and result2 as shown in variable_tracker.
Concept Snapshot
Durable Functions orchestrate workflows by calling activity functions in order.
The orchestrator waits for each activity to finish before continuing.
Results from activities can be combined and returned.
This enables reliable, stateful workflows in the cloud.
Full Transcript
Durable Functions let you build workflows that run in the cloud. A workflow starts with a trigger that calls an orchestrator function. The orchestrator calls activity functions one by one. It waits for each activity to finish before moving on. Each activity returns a result. The orchestrator can combine these results and return a final output. This process ensures the workflow is reliable and can handle long-running tasks. The execution table shows each step: starting the workflow, calling activities, waiting, and completing. Variables like result1 and result2 track activity outputs. Beginners often wonder why the orchestrator waits; it does so to keep the workflow ordered and consistent. They also ask about parallel calls and error handling, which are possible but not shown here. The visual quiz tests understanding of variable values and step order. This summary helps beginners see how Durable Functions manage workflows step-by-step.

Practice

(1/5)
1. What is the main purpose of Durable Functions in Azure?
easy
A. To create virtual machines
B. To store large amounts of data
C. To monitor network traffic
D. To manage long-running workflows reliably

Solution

  1. Step 1: Understand Durable Functions role

    Durable Functions are designed to handle workflows that take a long time and need to be reliable.
  2. Step 2: Compare options

    Options A, B, and D describe other Azure services, not Durable Functions.
  3. Final Answer:

    To manage long-running workflows reliably -> Option D
  4. Quick Check:

    Durable Functions = Manage workflows reliably [OK]
Hint: Durable Functions = reliable long workflows [OK]
Common Mistakes:
  • Confusing Durable Functions with storage services
  • Thinking Durable Functions create VMs
  • Assuming Durable Functions monitor networks
2. Which of the following is the correct way to define an orchestrator function in Azure Durable Functions?
easy
A. function orchestrator(context) { /* workflow code */ }
B. function activity(context) { /* workflow code */ }
C. async function orchestrator(context) { /* workflow code */ }
D. async function activity(context) { /* workflow code */ }

Solution

  1. Step 1: Identify orchestrator function syntax

    Orchestrator functions must be async to support awaiting activity calls.
  2. Step 2: Differentiate activity and orchestrator functions

    Options C and D define activity functions, not orchestrators.
  3. Final Answer:

    async function orchestrator(context) { /* workflow code */ } -> Option C
  4. Quick Check:

    Orchestrator = async function [OK]
Hint: Orchestrators are async functions [OK]
Common Mistakes:
  • Using non-async function for orchestrator
  • Confusing activity function syntax with orchestrator
  • Omitting async keyword
3. Given the following orchestrator code snippet, what will be the output if the activity function returns 'Hello'?
const result = yield context.callActivity('SayHello');
return result + ' World!';
medium
A. "Hello World!"
B. "World! Hello"
C. "Hello"
D. "World!"

Solution

  1. Step 1: Understand callActivity result

    The activity function returns 'Hello', which is assigned to result.
  2. Step 2: Concatenate strings

    The orchestrator returns result + ' World!', so 'Hello' + ' World!' = 'Hello World!'.
  3. Final Answer:

    "Hello World!" -> Option A
  4. Quick Check:

    Result + ' World!' = 'Hello World!' [OK]
Hint: callActivity returns value used in concatenation [OK]
Common Mistakes:
  • Reversing string order
  • Returning only activity result without addition
  • Ignoring yield keyword effect
4. Identify the error in this orchestrator function code:
async function orchestrator(context) {
  const result = context.callActivity('Task');
  return result;
}
medium
A. Function should not be async
B. Missing await or yield before callActivity
C. Incorrect function name
D. callActivity should be called outside orchestrator

Solution

  1. Step 1: Check callActivity usage

    callActivity returns a promise and must be awaited or yielded inside orchestrator.
  2. Step 2: Identify missing await/yield

    The code calls callActivity without await or yield, causing incorrect behavior.
  3. Final Answer:

    Missing await or yield before callActivity -> Option B
  4. Quick Check:

    callActivity needs await/yield [OK]
Hint: Always await or yield callActivity in orchestrator [OK]
Common Mistakes:
  • Forgetting await/yield on callActivity
  • Thinking async keyword is wrong here
  • Misplacing callActivity outside orchestrator
5. You want to create a workflow that calls two activity functions in sequence and combines their results. Which orchestrator code correctly implements this?
hard
A. const result1 = await context.callActivity('Activity1'); const result2 = await context.callActivity('Activity2'); return result1 + ' & ' + result2;
B. const result1 = context.callActivity('Activity1'); const result2 = context.callActivity('Activity2'); return result1 + ' & ' + result2;
C. const result1 = await context.callActivity('Activity1'); const result2 = context.callActivity('Activity2'); return result1 + ' & ' + result2;
D. const result1 = context.callActivity('Activity1'); const result2 = await context.callActivity('Activity2'); return result1 + ' & ' + result2;

Solution

  1. Step 1: Understand sequential calls in orchestrator

    Each callActivity must be awaited to get the actual result before next call.
  2. Step 2: Check options for proper await usage

    Only const result1 = await context.callActivity('Activity1'); const result2 = await context.callActivity('Activity2'); return result1 + ' & ' + result2; awaits both calls, ensuring correct sequence and result combination.
  3. Final Answer:

    const result1 = await context.callActivity('Activity1');\nconst result2 = await context.callActivity('Activity2');\nreturn result1 + ' & ' + result2; -> Option A
  4. Quick Check:

    Await both activities for correct sequence [OK]
Hint: Await each callActivity for sequential results [OK]
Common Mistakes:
  • Not awaiting callActivity causing promises instead of results
  • Mixing awaited and non-awaited calls
  • Returning promises instead of strings