Try
↑ ↓ move↵ openesc close

Interview prep / Queues as buffers

Senior · Queues as buffers · System design interview question

How would you decide how big a queue should be?

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

A strong answer

Start from the latency you can accept, not the memory you have. By Little's law, the wait of a full queue is about its capacity divided by the drain rate. Pick the longest wait after which a message is still useful, and multiply by the drain rate.

Check the other side too. The queue should be big enough to hold the longest burst you expect, given how fast consumers drain it. If the two requirements conflict, the consumers are too slow, and the fix is capacity.

The limit itself should be a deliberate policy. Watch queue age as well as depth, and alarm when the queue stays full. The sizing assumes bounded bursts and service times without heavy tails, so if either fails the numbers are optimistic.

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