Try
↑ ↓ move↵ openesc close

Interview prep / Queues as buffers

Junior · Queues as buffers · System design interview question

A bounded queue is full and another message arrives. What are your options?

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

A strong answer

There are three common choices. Block the producer, so the send waits for room. Drop the newest message, which refuses the arrival. Drop the oldest, which evicts the head to make room.

Blocking loses nothing but moves the delay upstream. Dropping the newest protects the work already accepted. Dropping the oldest keeps the freshest data, which suits readings that are replaced by newer ones.

Fit the choice to the data. Orders cannot be dropped, while a position update can. Returning an error to the caller is a fourth option: it is dropping, but the caller can see it.

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