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?
- Move the HTTP request logic to a separate activity function and call it using the orchestration context.Answer
- BWrap the HTTP request logic inside a local helper method annotated with the activity trigger attribute and call the helper method directly.
- CReplace the parallel execution of activity tasks with sequential execution using a loop to avoid socket exhaustion on the direct HTTP calls.
- DConfigure the Azure Function App to run on a Dedicated (App Service) hosting plan to ensure the direct HTTP call does not timeout.