Try
↑ ↓ move↵ openesc close

Interview prep / Load shedding and backpressure

Senior · Load shedding and backpressure · System design interview question

When would you serve a queue newest first, and what does it cost?

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

A strong answer

Under overload a first-in first-out queue serves the oldest requests first, which are the ones most likely to have been abandoned. The newest request has waited least, so its caller is the most likely to still be there. Serving the newest first, which is LIFO, means the work that gets done is work somebody wants. An adaptive version uses FIFO while the queue is short and switches to LIFO when it gets long, so ordinary operation is still fair.

The cost is fairness and consistency. Old requests sit at the bottom and may never be served, so some callers get nothing while others get fast answers. If the same callers keep landing at the bottom, they lose every time. Requests that depend on each other can be served out of order. It also needs something to clear out the requests that have expired, or the pile grows without limit.

It fits interactive requests where a stale answer is worthless, such as a page load. It is a poor fit where order matters, such as a sequence of writes from one user.

Pair it with a cap on waiting time, so the starved requests are discarded cleanly instead of piling up.

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