Try
↑ ↓ move↵ openesc close

Interview prep / Queues as buffers

Junior · Queues as buffers · System design interview question

Producers write 100 messages a second to a queue that holds 1,000. The consumers finish 80 a second. How long until it is full, and what then?

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

A strong answer

The queue grows by the gap between the two rates: 100 minus 80 is 20 messages a second. Starting empty, it holds 1,000 after 1,000 / 20 = 50 seconds.

After that the queue is full and every extra message needs a decision. Block the producer, refuse the newest, or evict the oldest. None of these makes the consumers faster. The 20 a second that cannot be handled is still there, and it now shows up as blocked callers or dropped messages.

The useful reading is that a bigger queue only buys time. At 10,000 slots the same arithmetic gives 500 seconds, which is a longer warning and a longer wait for every message at the back. The fix is on the rate side: five more messages a second from each consumer, a fifth consumer if each does 20 a second, or less work arriving.

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