Home/Labs/202 Accepted Job Lifecycle
All 280 Labs
INTERACTIVE LAB⏳

Sync vs Async API Lab (Interactive)

Run a long export as blocking 200, poll, webhook, or SSE and race it against gateway timeouts and thread starvation. Set job duration and concurrent clients, then replay the same long task over four delivery mechanisms to see who gets a 504, who starves the pool, and how fast the client learns the result.

Sync vs 202 Accepted Job Lifecycle

Run a long export four ways and race the gateway timeout, thread pool, and result-delivery lag.

Client learns at

80s

Connection held

120 ms

Status polls

5

Pool occupancy

1%

Wire timeline (idle — press Submit job)

PENDING → PROCESSING → COMPLETED | FAILED state machine awaits the first request.

Zero held threads; queue depth drives independent worker scaling. Rule of thumb: anything over 2-3s must return 202 + Location + Retry-After, with queue-depth-scaled workers and a 7-day TTL on job records.

How It Works Under the Hood

Any operation over two to three seconds held open on a synchronous HTTP connection becomes an outage vector: load balancers kill it with 504 at 30-60s while the backend grinds on as a ghost computation, and each blocked socket is a worker thread stolen from lightweight CRUD traffic. The 202 Accepted contract flips the model — validate, persist a PENDING job row, publish to a queue, return Location and Retry-After in 20ms. Clients then learn completion through exponential-backoff polling, signed webhooks, or live SSE progress streams, each with distinct firewall and battery implications.

Core Architectural Principles

  • 202 Accepted + Location + Retry-After decouples intake (<20ms) from multi-minute execution.
  • Polling backs off 5s→10s→20s; webhooks need public receivers; SSE streams live progress.
  • Job rows follow PENDING→PROCESSING→COMPLETED/FAILED with a TTL to bound storage.
Interview Round Script

In any video-transcode or bulk-export design, return 202 with a jobs URI and Retry-After before the interviewer asks, scale workers off queue depth rather than HTTP concurrency, and cover failure modes: dead-letter queues, FAILED terminal states, and webhook receivers that must dedupe by job id.

Key Trade-Offs

Async shielding costs clients multi-step state tracking plus queue and status-store infrastructure.

Related Curriculum Chapter

Synchronous vs Asynchronous API Design

Read Full Chapter Blueprint

Explore More Interactive Labs

View All 280 Labs