Soru

Zorluk: ZorImplement Durable Functions

You are developing a compliance audit workflow for a legal technology firm using Azure Durable Functions in C# (.NET Isolated process). You write the following orchestrator function to verify a batch of documents against a policy:

csharp
[Function("ComplianceAuditOrchestrator")]
public static async Task<string> Run(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
var request = context.GetInput<AuditRequest>();

using (var client = new HttpClient())
{
var response = await client.GetAsync($"https://api.legalcorp.com/rules/{request.PolicyId}");
if (!response.IsSuccessStatusCode)
{
throw new Exception("Failed to retrieve policy rules.");
}
}

var tasks = new List<Task<bool>>();
foreach (var doc in request.Documents)
{
tasks.Add(context.CallActivityAsync<bool>("ScanDocumentActivity", doc));
}

var results = await Task.WhenAll(tasks);
return results.All(r => r) ? "Passed" : "Failed";
}

During testing in a high-volume staging environment, you notice that the orchestrator behaves non-deterministically, occasionally fails with orchestrator validation errors, and performs redundant HTTP calls to the external policy API.

Which modification should you apply to resolve these issues and ensure the orchestrator is deterministic?

  1. Move the HTTP request logic to a separate activity function and call it using the orchestration context.Cevap
  2. B
    Wrap the HTTP request logic inside a local helper method annotated with the activity trigger attribute and call the helper method directly.
  3. C
    Replace the parallel execution of activity tasks with sequential execution using a loop to avoid socket exhaustion on the direct HTTP calls.
  4. D
    Configure the Azure Function App to run on a Dedicated (App Service) hosting plan to ensure the direct HTTP call does not timeout.

Cevap

Move the HTTP request logic to a separate activity function and call it using the orchestration context.
Moving the HTTP request logic to a separate activity function and executing it via the orchestration context is correct. Orchestrator functions in Azure Durable Functions must be deterministic. Direct network calls using classes like HttpClient will execute on every replay, leading to side effects and non-deterministic execution failures. By using an activity function, the Durable Functions runtime records the result of the HTTP call in the orchestration history, returning the cached result during replays without re-executing the call.

Adım Adım Çözüm

1
Analyze the orchestrator code for determinism violations.
Identify that the direct instantiation of HttpClient and the network call to retrieve policy rules are non-deterministic operations.
Durable orchestrator functions replay to rebuild their state. Direct I/O operations will re-execute during replays, which violates determinism.
2
Refactor the non-deterministic operation into an activity function.
Create a new activity function dedicated to performing the HTTP call to retrieve the rules.
Activity functions execute once, and their results are recorded in the orchestration history to be replayed deterministically.
3
Invoke the activity function using the orchestration context.
Replace the inline HttpClient code block in the orchestrator with context.CallActivityAsync.
This registers the task in the execution history, ensuring that replays use the cached result instead of executing another HTTP call.

Anahtar Kavram

Orchestrator determinism requirements in Azure Durable Functions
Bu soruyu puanla