You are developing an Azure Durable Functions application in C# using the .NET Isolated worker model. You write the following orchestrator function to manage an order processing workflow:
csharp
[Function("ProcessOrderOrchestrator")]
public static async Task RunOrchestrator(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
var orderId = context.GetInput<string>();
var status = await context.CallActivityAsync<string>("CheckStatus", orderId);
var trackingId = Guid.NewGuid().ToString();
await context.CallActivityAsync("ProcessPayment", new { OrderId = orderId, TrackingId = trackingId });
}
Which line of code in this orchestrator function violates the determinism constraints of Durable Functions?
- Avar orderId = context.GetInput<string>();
- Bvar status = await context.CallActivityAsync<string>("CheckStatus", orderId);
- var trackingId = Guid.NewGuid().ToString();Cevap
- Dawait context.CallActivityAsync("ProcessPayment", new { OrderId = orderId, TrackingId = trackingId });
Cevap
The statement generating the tracking ID using Guid.NewGuid()
The statement `var trackingId = Guid.NewGuid().ToString();` violates the determinism constraints of Durable Functions orchestrator functions. Orchestrator functions must be deterministic because they are replayed from the beginning of the execution history to rebuild the state of the orchestration. Generating a new GUID via `Guid.NewGuid()` produces a different value on every replay, leading to non-deterministic execution paths and runtime errors. Instead, the orchestrator should use `context.NewGuid()` to safely generate a random identifier that yields the same value during replays.
Adım Adım Çözüm
Anahtar Kavram
Durable Functions Orchestrator Code Constraints and Determinism