Core Concepts
Backpressure and Load Shedding
Keep waiting and running work bounded when requests arrive faster than a service can finish them.
Backpressure tells producers to slow down when a service is near its limit. Load shedding rejects or drops excess work so the service can keep going. A queue can absorb a short burst. If requests keep arriving faster than workers finish them, the queue grows until it reaches its limit or runs out of memory.
Give waiting work a limit
Assume each report takes 100 milliseconds to run and each worker handles one report at a time. Four workers can finish up to 40 reports per second under those assumptions. If 60 requests arrive per second and we admit them all, the waiting queue grows by about 20 requests per second while those rates hold. A larger queue gives the service more places to wait. It still finishes at the same rate. Amazon on queue backlogs
Suppose a caller can afford up to 100 milliseconds of waiting in our example. Give the Reports API four waiting slots as well as its four running slots. At time zero, requests 1 to 4 start, and requests 5 to 8 wait. The ninth request reaches a full queue. The service returns 503 Service Unavailable before it accepts the request. This is load shedding. We refuse excess work early so admitted requests have a better chance of finishing while their results are useful. Google SRE on queue management · HTTP 503
At 100 milliseconds, the first four finish. The four waiting requests start immediately, and their waiting slots open. This queue absorbs a short burst. If the report size or dependency latency varies, a queue of four cannot promise a fixed wait. Measure the waiting time under realistic load, and check each request's remaining deadline before starting expensive work. If the service already accepted work durably, record an eventual outcome according to the API contract. A job that expires still needs a status the caller can read. Google SRE on deadlines
Tell a producer when it can send
A cooperating batch producer can take instructions from the Reports API before offering its next job. The API reserves four waiting slots for the producer and grants four credits, one per reserved slot. The producer has six jobs ready. It sends four and spends one credit per job. It keeps the remaining two jobs locally. The queue holds four waiting jobs while the earlier requests run.
When the earlier requests finish, the four waiting jobs move into the running slots. The API can now grant credits for the freed waiting slots. The producer can send the two jobs it kept. This feedback is backpressure. The downstream signals the producer to slow the rate at which it sends work. A worker pulling only as many jobs as it has free running slots uses the same idea. Reactive Streams on demand signals
At zero credits the producer has to pause new work upstream of its local queue as well, or its own backlog keeps growing. The gate keeps waiting jobs plus outstanding credits within the waiting limit. Issuing a credit reserves space. Spending it converts that reservation into a queued job. Expiring it returns the space. Make each transition atomic at the shared gate and check the credit on arrival, so a late request cannot spend space already given to someone else.
The public HTTP endpoint accepts browser requests into unreserved space only. The API can reject a request at its capacity gate and suggest a delay with Retry-After if it can estimate one. If every browser repeats the rejected request immediately, retries add load just when the queue needs to drain. Wait at least as long as the hint, increase the wait after repeated failures, and add a small random delay so callers spread out their retries. Limit the number of attempts and stop when the request is too late to be useful. For a command with an uncertain outcome, reuse its request ID so the service can find the work it already accepted. HTTP Retry-After · Amazon on retries, backoff, and jitter
Protect the resource that runs the work
Account A17 can be within its Reports API allowance while the shared pool is busy with everyone else's reports. The account limiter answers whether A17 can spend another request from its budget. The capacity gate checks whether the pool can take another job right now. A17 passes the first check and gets 503 at the second if all slots are taken. An account whose allowance has run out gets 429 at the first gate. HTTP 429
If three gateways each allow four jobs to the same four-worker pool, they may send twelve jobs between them. Put the running and waiting caps where all callers share the same count. The pool can admit one more job only if it reserves a place for it before another caller sees the same space.
ChatGPT does this for model work. The design checks the account's request allowance, then reserves a slot for that account and a slot in the model pool before accepting the turn. A browser disconnect can leave the model running. Hold its slot until generation ends or recovery confirms it stopped. This keeps the count tied to the resource doing the work.
Shed where demand is building
Watch how many requests arrive, how many finish, how many are running, and how long the oldest queued request has waited. Queue depth is useful, but four jobs with a slow dependency can hold their places much longer than four jobs in a healthy pool. At the pool level a rising queue age can tell us that a request would miss its deadline even though it fits the queue's space limit. Amazon on overload signals
If jobs have different priorities, protect enough capacity for the ones that need it now. The Batched Inference walkthrough watches Kafka consumer lag, how far its processing position trails incoming records. As lag grows in a model class, it stops accepting background work before interactive requests. This buys time for the pool to catch up or add workers. Record the reasons for rejection and measure how many requests finish within their deadlines. A dashboard of fast responses alone can miss the requests the system refused. Google SRE on priority during overload
See also
- Latency vs Throughput explains how waiting time rises as incoming work approaches what a service can finish.
- Idempotency shows how a retry can find a command that already took effect.
- Rate Limiting sets the allowance each account shares across its requests.
- Messaging and Work Queues follows the life of an accepted job and how it completes after a worker crash.
Used in
- ChatGPT reserves concurrent work before accepting a turn and releases its slot when execution has ended.
- Batched Inference Service uses queue lag to stop accepting less urgent work while GPU capacity catches up.
- Rate Limiter caps simultaneous checks from a hot account to protect the shard for other accounts.
Done reading? Mark it so it sticks in your dashboard.