Question

Difficulty: MediumImplement Durable Functions

You are developing a serverless workflow using Azure Durable Functions. You need to sequence the execution and replay steps of a basic orchestration that starts, runs a single activity function, and completes. Move the events to the correct order in which they occur during this execution lifecycle.

  1. 1The client function calls StartNewAsync (or equivalent SDK start method) to initiate a new orchestrator instance.
  2. 2The orchestrator function executes until it reaches an await call to an activity function, scheduling that activity in the queue.
  3. 3The orchestrator function yields control, suspends execution, and checkpoints its progress to the storage provider.
  4. 4The scheduled activity function executes on an available worker and stores its completion result in the history provider.
  5. 5The orchestrator function is re-triggered, replays the history from the beginning to restore state, and continues past the completed activity.

Answer

The correct order of events is: client function initiates the orchestrator instance, the orchestrator executes and schedules the activity function, the orchestrator yields control and suspends execution, the activity function executes and stores its result, and the orchestrator replays history to restore state and continue.
The correct order follows the standard Durable Functions event sourcing replay pattern: the client initiates the orchestrator; the orchestrator executes, schedules the activity, and yields control; the activity executes on a worker; and finally, the orchestrator wakes up, replays history, and continues execution with the activity result.

Step-by-Step Solution

1
Initiate the orchestration instance.
The client function calls StartNewAsync, placing a start message in the control queue.
Durable Functions orchestrations must be started by a client function using the client binding.
2
Execute the orchestrator and schedule the activity.
The orchestrator begins execution and runs until the await statement, scheduling the activity in the work-item queue.
The orchestrator runs single-threaded code up to the first asynchronous operation, creating execution history.
3
Yield and sleep the orchestrator.
The orchestrator yields control, writes its state to the storage table, and goes to sleep.
Durable Functions optimize resource usage by not keeping orchestrators active while waiting for activities to complete.
4
Execute the activity function.
A worker picks up the activity, executes it, and writes the output back to the history storage.
Activities run separately from the orchestrator, and their output must be persisted to allow the orchestrator to rebuild state.
5
Wake up and replay the orchestrator.
The orchestrator is re-enqueued, restarts execution from the beginning, and uses history to reconstruct state and skip re-executing the completed activity.
The orchestrator relies on event sourcing (replay) to ensure determinism and recover local variables/state without repeating activities.

Key Concept

The execution replay lifecycle of Durable Functions ensures state persistence and scalability by suspending and reconstructing the orchestrator state from execution history.
Rate this question