Try
↑ ↓ move↵ openesc close

Interview prep / Queues as buffers

Senior · Queues as buffers · System design interview question

An API accepts uploads, puts a job on a queue and returns 202. During a spike the queue fills and jobs wait over ten minutes. Design the behaviour under overload.

Sketch your own answer first, then compare it with the one below.

A strong answer

Start with the wait budget. If a result is useless after two minutes, the queue should never hold more than two minutes of work. At a drain rate of 50 jobs a second, that is 6,000 jobs, and anything beyond it only creates stale work.

So bound the queue by that number and make admission explicit. When depth or age passes the threshold, the API should refuse new work quickly, with a 429 or 503 and a Retry-After header, instead of accepting jobs that will expire. Rejecting is cheaper than queueing something that will be discarded later, and it tells clients to slow down.

Then protect what is already accepted. Put a deadline on each job and have consumers skip expired ones. Separate queues or priorities keep paying customers or small jobs from waiting behind bulk ones. Retries from clients need backoff with jitter, or they turn the spike into a sustained overload.

On the capacity side, add autoscaling keyed to queue age, with a ceiling so a spike cannot take down the database the workers hit. Finally, record how many jobs were refused or expired, so the capacity discussion is based on numbers.

Sources

Learn it by running it

The queues as buffers lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms