ASP.NET Core Web API Interview Question #167

Why should long-running work not normally execute inside an HTTP request?

Testing, HttpClient, Integration Testing, Background Services & Deployment Senior Advanced

Quick Interview Answer

Long-running work keeps the request open, consumes resources, increases timeout risk, and couples client connectivity to the completion of the job. For lengthy or retryable operations, the API can accept the request, enqueue durable work, and return a job identifier.

Detailed Explanation

Long-running work keeps the request open, consumes resources, increases timeout risk, and couples client connectivity to the completion of the job. For lengthy or retryable operations, the API can accept the request, enqueue durable work, and return a job identifier.

The client can then poll a status endpoint or receive completion through another appropriate mechanism.

Code Example

POST /api/reports

HTTP/1.1 202 Accepted
Location: /api/jobs/8f23...

{
  "jobId": "8f23..."
}