Try
↑ ↓ move↵ openesc close

Interview prep / Load shedding and backpressure

Mid · Load shedding and backpressure · System design interview question

How do you choose the size of a bounded request queue?

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

A strong answer

Work backwards from the timeout. A request that joins a queue of N on a server that finishes C requests per second waits about N divided by C seconds before it starts. That wait must be comfortably less than the time the caller will stay, minus the service time itself. This is Little's law at work: the number waiting equals the arrival rate times the wait.

For example, if workers finish 20 a second and callers give up after 2 seconds, a queue of 100 means a wait of 5 seconds, so everything that reaches a worker is already late. The queue should be a fraction of 40, with margin for service time.

The size is fragile. It depends on speed and timeout, and both change. A slow downstream, a cold cache or a noisy neighbour lowers C, and the same N now means a longer wait. So many systems bound the delay and not the length, by dropping requests that have waited too long, or they set the queue small, only enough to absorb a short burst.

So derive the bound from the timeout, and treat the count as a safety net and not as the control.

Sources

Learn it by running it

The load shedding and backpressure 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