Question

Difficulty: MediumImplement Durable Functions

You are developing a data synchronization solution using Azure Durable Functions. The solution must implement the Monitor pattern to periodically poll the status of an external import process until it finishes.

Arrange the steps in the correct chronological order of execution for a single complete loop of the monitoring workflow, starting from the client request.

  1. 1The HTTP-triggered client function starts a new orchestrator instance and returns an HTTP 202 response with status query endpoints.
  2. 2The orchestrator function calls the status-checking activity function for the first time.
  3. 3The orchestrator function creates a durable timer to schedule a wake-up after determining that the import is still running.
  4. 4The Durable Functions runtime wakes up the orchestrator function and replays execution history to restore the orchestrator's state.
  5. 5The orchestrator function calls the status-checking activity function a second time, receives a completion status, and terminates.

Answer

The correct sequence of events starts with the HTTP client initiating the orchestration ('client_start'), followed by the orchestrator querying the initial status via an activity ('first_poll'). Since the status is incomplete, the orchestrator sets a durable timer ('timer_scheduled'). Upon timer expiration, the runtime replays the history to restore the orchestrator state ('history_replay'). Finally, the orchestrator resumes, performs the final poll, and completes the workflow ('final_poll').
The correct sequence mirrors the stateful replay architecture of Durable Functions implementing the Monitor pattern. The client initiates the process, creating the instance. The orchestrator calls the activity function for the first status. If incomplete, it creates a durable timer and shuts down. When the timer fires, the runtime restarts the orchestrator, replaying history to reach the current state. Finally, the orchestrator executes the next step, calls the activity again, finds the task complete, and terminates.

Step-by-Step Solution

1
Initiate the orchestration flow.
The client function starts the orchestrator instance and returns a status query response containing endpoints.
An orchestration must be started by a client function using the client binding.
2
Execute the first poll operation.
The orchestrator calls the activity function to fetch the current status.
Orchestrators cannot perform direct I/O, so they must call activity functions to query external endpoints or systems.
3
Schedule the pause interval using a durable timer.
The orchestrator yields execution by creating a durable timer.
To implement non-blocking polling and avoid hosting charges during idle time, the orchestrator uses a durable timer rather than standard thread sleeps.
4
Replay execution history upon timer expiration.
The runtime restarts the orchestrator function and replays past events from the Azure Storage history table.
Durable Functions use event sourcing; when waking up from a timer, the function restarts and replays history to reconstruct its local variables and state.
5
Perform the final status check and complete.
The orchestrator issues the final status query activity and completes the workflow upon detecting success.
Once the condition is met, the orchestrator finishes executing its logic, marking the overall instance as completed.

Key Concept

Monitor Pattern in Azure Durable Functions
Rate this question