1:1 mentoring with Big Tech AI engineers
System Design

Event-Driven Async

How slow agent work leaves the request path: the timers that decide sync, stream or job, the 202 job contract, at-least-once queues with leases and dead-letter routing, backpressure in queue age, and delivery by poll, SSE or webhook.

Last updated

Production11 min readFirst readScaling 10k to 1MRate Limiting & Cost

After this section you can

  • Choose sync, stream or job from the timers on the request path
  • Configure a queue so a slow agent run is not executed twice
  • Classify a failure and route it to retry, pause or the dead-letter queue
23

Event-Driven Async

Keep slow agent work off the request path: choose sync, stream or job, and run each job once in effect.

Key idea

A request waits only as long as its shortest timer. Keep it synchronous when p95 is under about half that timer, stream it when a person is watching, and make anything longer a job: a 202 and a handle, then a queue.

The API answers in milliseconds; the worker runs the model later
Clientsends the request APIaccepts in ms202 + job_id Queueholds the job Workerruns the model Result storestatus and output 1timers on the path 2the 202 contract 3lease 4failed jobs 5queue age 6poll, SSE or webhook

Blue request, teal the API that accepts, purple state, amber the model, green the answer. Badges match the section’s steps 1 to 6. Pans sideways on a phone.

Related

More in System Design

Get full access to all 149 sections with code examples, diagrams, and interactive animations.

Unlock Premium