Question

Difficulty: Very hardImplement Durable Functions

You are developing a nightly data aggregation pipeline using Azure Durable Functions (.NET Isolated process). The orchestrator function is triggered daily to collect sales reports from multiple regional API endpoints, consolidate them, and write the summary to a database.

The orchestrator code is defined as follows:

csharp
[Function("AggregateDailySalesOrchestrator")]
public static async Task<SalesSummary> Run(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
var regions = await context.CallActivityAsync<List<string>>("GetActiveRegions", null);

var tasks = new List<Task<RegionReport>>();
foreach (var region in regions)
{
tasks.Add(context.CallActivityAsync<RegionReport>("FetchRegionReport", region));
}

// Fan-out: wait for all parallel fetch operations to complete
var reports = await Task.WhenAll(tasks);

// Fan-in processing
var summary = new SalesSummary { RunId = Guid.NewGuid().ToString() };
foreach (var report in reports)
{
if (report.Timestamp >= DateTime.UtcNow.AddHours(-24))
{
summary.TotalRevenue += report.Revenue;
}
}

await context.CallActivityAsync("SaveSummaryToDatabase", summary);
return summary;
}

During testing under heavy loads, you observe that the `FetchRegionReport` activity function occasionally takes up to 1212 minutes to complete due to slow external APIs, resulting in execution failures. The Function App is currently deployed to an Azure Functions Consumption plan.

Which action must you take to ensure that the orchestration runs successfully, executes without timeouts, and produces deterministic results?

  1. A
    Keep the Function App on the Consumption plan since Durable orchestrators automatically split and checkpoint tasks to bypass the 1010-minute limit; in the orchestrator code, replace Guid.NewGuid() with context.NewGuid() and replace DateTime.UtcNow with context.CurrentUtcDateTime.
  2. B
    Migrate the Function App to a Premium plan to support the 1212-minute activity execution duration; in the orchestrator code, keep Guid.NewGuid() and DateTime.UtcNow as they are because determinism constraints only apply to activity invocation calls.
  3. Migrate the Function App to a Premium plan to support the 1212-minute activity execution duration; in the orchestrator code, replace Guid.NewGuid() with context.NewGuid() and replace DateTime.UtcNow with context.CurrentUtcDateTime.Answer
  4. D
    Migrate the Function App to a Premium plan to support the 1212-minute activity execution duration; in the orchestrator code, replace Guid.NewGuid() with context.NewGuid() but keep DateTime.UtcNow because the runtime automatically captures and replays DateTime values from the history log.

Answer

Migrate the Function App to a Premium plan to support the 1212-minute activity execution duration; in the orchestrator code, replace Guid.NewGuid() with context.NewGuid() and replace DateTime.UtcNow with context.CurrentUtcDateTime.
Upgrading the hosting plan to a Premium plan allows activity functions to run up to 3030 minutes (or unbound), preventing timeouts during the 1212-minute external API calls. Additionally, replacing Guid.NewGuid() and DateTime.UtcNow with context.NewGuid() and context.CurrentUtcDateTime guarantees that the orchestrator function remains deterministic during replays, preventing runtime mismatches or execution errors.

Step-by-Step Solution

1
Analyze the hosting plan execution limits for the activity function.
Identify that the Consumption plan has a maximum timeout of 1010 minutes, which causes the 1212-minute activity execution to fail.
To allow the activity function to run for 1212 minutes, the app must be migrated to a plan supporting longer execution, such as the Premium plan.
2
Evaluate the orchestrator function code for determinism violations.
Identify that Guid.NewGuid().ToString() and DateTime.UtcNow are non-deterministic APIs.
Orchestrator code is replayed multiple times to rebuild its state, so all operations inside the orchestrator must return the exact same result on every execution.
3
Replace non-deterministic APIs with Durable-safe alternatives.
Use context.NewGuid() for unique identifier generation and context.CurrentUtcDateTime for fetching the replay-safe current time.
The Durable runtime intercepts these context-specific APIs and records their initial outputs in the execution history, ensuring consistent results during replays.

Key Concept

Durable Functions orchestrator constraints and hosting plan execution limits
Estimated Time:3m 0s
Rate this question