Api Design medium
A video processing API takes 5 minutes to complete. The client calls POST /videos/process. What's the best response pattern?
- A Keep the HTTP connection open for the full 5-minute duration to ensure the client receives the final success or failure message synchronously.
- B Return a 202 Accepted status with a background job ID and a status endpoint, allowing the client to poll for completion or receive a webhook.
- C Immediately return a 200 OK status to the client and assume the underlying storage layer will eventually achieve consistency once the task is finished.
- D Abort the request with an error code, as RESTful APIs are strictly designed for synchronous operations that complete within standard proxy timeout limits.
Answer: B. Return a 202 Accepted status with a background job ID and a status endpoint, allowing the client to poll for completion or receive a webhook.
For long-running operations, blocking the HTTP connection is poor practice (timeouts, resource holding). The standard pattern is to return **202 Accepted**, indicating the request is valid and processing has started. The response should include a location (e.g., a status endpoint) where the client can poll for the result or register a webhook for notification.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- You're designing a REST API for a blog. Which endpoint best represents 'get all comments for post 123'?
- A client wants to update only the 'status' field of an order, leaving other fields unchanged. Which HTTP method is most appropriate?
- A client calls POST /users with valid data, and the user is created. What status code should the server return?
- A client retries a failed 'POST /payments' request due to network timeout. The server receives the request twice. Without idempotency handling, what can happen?
- An API returns 10,000 products. Returning all in one response is impractical. Which pagination approach is simple and stateless?
- Your API serves both mobile apps and third-party integrations. Which authentication method is most appropriate?