ASP.NET Core Web API Interview Question #191
How should a Web API handle long-running report generation?
Senior API Design, Architecture, Scalability & Production Scenarios Senior Advanced
Quick Interview Answer
Do not keep a normal HTTP request open for a report that may take minutes. Create a job record, enqueue durable work, return 202 Accepted with a status location, and process the report asynchronously.
Detailed Explanation
Do not keep a normal HTTP request open for a report that may take minutes. Create a job record, enqueue durable work, return 202 Accepted with a status location, and process the report asynchronously.
The job endpoint can expose Queued, Running, Completed, and Failed states. Completed output should be stored securely and downloaded through an authorized endpoint or time-limited URL.
Code Example
var job = await _reports.EnqueueAsync(request, token);
return AcceptedAtAction(
nameof(GetReportJob),
new { id = job.Id },
new { job.Id, job.Status });