How do you handle long-running async operations in REST APIs?

Answer

Long-running operations (video processing, report generation, batch imports) should not block the HTTP connection. The accepted pattern is the 202 Accepted response: the API immediately returns 202 with a job ID and a link to poll status: { "jobId": "abc123", "statusUrl": "/jobs/abc123" }. The client polls GET /jobs/abc123, which returns the job status (pending, processing, completed, failed). On completion, the response includes a link to the result: { "status": "completed", "resultUrl": "/reports/xyz" }. The alternative to polling is webhooks — the client registers a callback URL and the server POSTs to it when the job finishes. Webhooks are more efficient than polling but require the client to expose a public HTTPS endpoint. A third option is Server-Sent Events (SSE) for streaming progress updates.