Try
↑ ↓ move↵ openesc close

Interview prep / Load shedding and backpressure

Senior · Load shedding and backpressure · System design interview question

A request passes through a pipeline of three stages that cost 1 ms, 10 ms and 100 ms of CPU. The pipeline is overloaded. Where should you shed, and why does it matter?

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

A strong answer

Shed at the first stage, before any work is spent. The reason is arithmetic. A request dropped at stage 3 has already used 1 + 10 = 11 ms of work that gets thrown away. At 1,000 dropped requests a second that is 11 CPU seconds a second of pure waste, enough to saturate more than ten cores. A request dropped at stage 1 wastes nothing.

Look at the costs too. The last stage is by far the most expensive, so it is the real bottleneck, and it should set the admission rate for the whole pipeline. If stage 3 handles 50 a second, there is no point letting more than about 50 through stage 1. The first stage needs to know the last stage's state: through a credit, a queue-delay signal, or a rejection that is passed back up.

Use bounded queues between stages, so a full queue at stage 3 stops work at stage 2 and so on back to the front. That is backpressure moving upstream. Without bounds, the middle queues fill with work that will never finish.

The exception is when only the late stage knows enough to decide, for example because the request's cost or class is not known until it has been parsed. Then do the cheap parse early, and shed as soon as the information exists.

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