202 Accepted
The request has been accepted for processing, but the processing has not been completed.
Usually happens because:
- ☑ Queuing heavy computations (like video
- ☑ Asynchronous webhook calls passing messages
🔍 Quick Checklist:
Meaning
The HTTP 202 Accepted status code indicates that the request has been received but not yet acted upon. It is non-committal, meaning that there is no way for the HTTP server to later send an asynchronous response indicating the outcome of the request. It is primarily used for batch or background tasks.
Root Causes
- Queuing heavy computations (like video transcoding or report generation).
- Asynchronous webhook calls passing messages to message brokers (RabbitMQ/Kafka).
| Cause | Frequency |
|---|---|
| Queuing heavy computations (like video | ⭐⭐⭐⭐⭐ |
| Asynchronous webhook calls passing messages | ⭐⭐⭐⭐ |
Common Mistakes
- Keeping client HTTP connections open synchronously during 10-minute transcoding tasks (resulting in timeouts).
- Failing to provide a tracking token or polling endpoint to check status.
How to Fix
Framework-Specific Examples
Triggering Celery-like queues and returning 202 Accepted in Express.
app.post('/api/jobs', (req, res) => {
res.status(202).json({ jobId: 'job-123', status: 'queued' });
});Server Configuration Examples
Increasing upstream proxy timeouts for asynchronous endpoints.
proxy_read_timeout 600;Prevention
- Implement a robust asynchronous message queue architecture (e.g., Celery, Redis Queue, BullMQ).
- Setup short connection timeout defaults to force background job delegation.
Frequently Asked Questions (FAQ)
Q: How do client applications track 202 status progress?
Usually, the response payload provides a 'monitorUrl' or job ID. The client sends recurring GET requests to that URL to check if the job is 'processing', 'completed', or 'failed'.
Q: What happens if the background task fails?
Since the connection was already closed with 202, the server status endpoint will simply display 'failed' during client polling.
Q: Is 202 Accepted suitable for sending emails?
Yes, dispatching emails is a classic background job that should return 202 Accepted immediately to prevent blocking UI interactions.
Q: Should a 202 response carry headers like Retry-After?
Yes, servers can include a Retry-After header indicating how many seconds the client should wait before polling the status monitor URL.