Question

Difficulty: HardImplement Durable Functions

A package delivery dispatch system is implemented using Azure Durable Functions. The workflow assigns a driver, waits up to 30 minutes for the driver to accept the assignment via an external event, and dispatches the delivery if accepted. The driver accepts the assignment 10 minutes after it is assigned.

How does the Durable Task Framework execute and replay the orchestrator function to complete this workflow? Order the execution and replay events chronologically from the initial start of the orchestrator to its completion.

  1. 1The orchestrator starts, executes the AssignDriver activity, finds no history for it, schedules the activity, and yields control.
  2. 2The orchestrator restarts, replays AssignDriver from history, schedules the DriverResponse external event and the 30-minute timer, and yields control.
  3. 3The orchestrator restarts, replays history, processes the received DriverResponse event, cancels the timer, schedules the DispatchDelivery activity, and yields control.
  4. 4The orchestrator restarts, replays all historical events, reads the completed DispatchDelivery result from history, and finishes execution.

Answer

The correct chronological order of execution and replay events is: first, the orchestrator starts and schedules the AssignDriver activity; second, it restarts, replays, and schedules both the external event and the timer; third, it restarts upon receiving the external event, cancels the timer, and schedules DispatchDelivery; finally, it restarts, replays all events, and completes execution.
The correct sequence mirrors the stateful replay model of Azure Durable Functions. The orchestrator never blocks; instead, it executes sequentially until it encounters an await, at which point it schedules the activity or event, yields, and shuts down. When the scheduled task completes, the orchestrator is awakened, replays the execution history to rebuild the local state, and continues to the next step.

Step-by-Step Solution

1
Initiate orchestration and schedule the first activity
The AssignDriver activity is queued, and the orchestrator yields control to save resources.
Durable Functions use an asynchronous queue-based model where the orchestrator does not block thread execution while waiting for activities.
2
Replay the first activity and set up concurrent monitoring
The orchestrator replays, retrieves the AssignDriver result, schedules the DriverResponse event and the timer, and yields control.
To wait for either a timeout or an external event, both tasks must be created and monitored concurrently using Task.WhenAny or equivalent.
3
Process external event completion, cancel the timer, and trigger the dispatch
The orchestrator restarts, cancels the active timer, queues the DispatchDelivery activity, and yields control.
Since the driver responded within the limit, the timer task must be cancelled to avoid unnecessary execution, and the next step is scheduled.
4
Replay final steps and close the orchestration
The orchestrator performs a final replay, matches the DispatchDelivery result, and exits successfully.
The orchestrator must run one final time to evaluate the completed DispatchDelivery activity and return the final state.

Key Concept

Durable Functions execution lifecycle, determinism, and event/timer orchestration
Rate this question