Saltar al contenido principal

Saying No on Time: Backpressure and Bounded Queues Under Overload

· 10 min de lectura
Clustron Team
Ingeniería de Sistemas Distribuidos

Every server has a rate it can sustain — some number of operations per second it can actually complete — and sooner or later something will ask it for more. A traffic spike, a thundering-herd retry storm, a batch job someone kicked off at the wrong time: the arrival rate climbs above the service rate, and now the system has a decision to make. Not a decision it makes consciously, but one baked into its design, and the one that decides whether a brief overload is a blip or an outage.

The tempting answer is to accept everything and queue what you cannot serve yet. It feels like the responsible, graceful choice — nothing is rejected, every request is honored eventually, the overload is just smoothed out over time. For a short burst against spare capacity, that is exactly right, and a queue is precisely the shock absorber you want. The trap is the word unbounded. If the queue has no limit and the overload is not brief, you have not smoothed anything — you have built a machine that converts sustained excess load into unbounded latency and then, reliably, into an out-of-memory crash. The system stays nominally "up," accepting requests, right up until it falls over all at once.

A store that survives overload is built on the opposite instinct: bound every queue, make the server push back when it is full, and answer an immediate, honest "busy" rather than quietly swallowing work it cannot finish in time. This post is about why that is the stable choice, and why a fast no is a kindness.

The unbounded queue is a crash with a countdown​

Start with the arithmetic, because it is the whole argument. A request's total latency is the time it spends being served plus the time it spends waiting behind everything already in line. When the arrival rate is below the service rate, the line stays short and waiting is negligible. The instant arrivals exceed service, the line grows — and it never catches up, because by definition more work arrives each second than leaves. Queue depth climbs without bound, and since every new request must wait behind that growing line, every request's latency climbs with it, toward infinity.

Two things fail together. Memory fails because the queue is holding an ever-larger backlog of pending work, and it climbs until the process is killed. And usefulness fails earlier and more quietly: long before the OOM, the queue has grown deep enough that requests sit in it past their deadline. The client that submitted a request five seconds ago has already timed out, returned an error to its own caller, and moved on — but the server does not know that, so it eventually dequeues that dead request and spends real capacity serving a result nobody is waiting for. The server is now busiest doing work that cannot possibly matter, which starves the work that still could. An unbounded queue does not prevent failure under overload. It delays it, hides it, and makes it total when it finally arrives.

Bound the queue, and say no on time​

The fix is a limit. A bounded admission queue has a fixed depth sized to absorb the bursts you expect against the headroom you have. While there is room, incoming work is admitted and the queue does its shock-absorber job. When it is full, the server does not grow the queue — it rejects the new request immediately, with an explicit "overloaded, try again" rather than an open-ended wait.

This feels harsher than queuing everything, and it is the opposite. A fast rejection is a usable answer. The client learns, within a round trip, that the server is saturated, and it can do something intelligent: back off, retry with jitter, route to another node, shed its own lower-priority work, or return a prompt error to its caller instead of hanging. Compare that to the alternative the unbounded queue offers — accept the request, then make the client wait until it times out. The timeout path is strictly worse for everyone: the client holds a connection and a thread for the entire timeout duration, which reduces its capacity, which makes its callers queue, and the overload propagates upstream and compounds. Overload that is not shed early does not stay put; it spreads. A bounded queue contains it at the first server that notices.

The principle has a name worth stating plainly: a NO that arrives on time is a signal; a response that arrives after its deadline is waste. Admission control is the server choosing to emit the useful signal.

Unbounded queue: arrivals > service → grows foreverloadqueue ▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮ … grows →serverlatency → ∞, then OOM · work dequeued after callers gave upBounded queue: absorb bursts to a fixed depth, reject beyondloadqueue ▮▮▮▮▮▮ (cap)serverqueue full → fast "busy"client backs off / reroutes / sheds — overload containedlatency stays bounded · the server never serves dead work

Backpressure: letting the transport carry the signal​

A bounded queue decides what to do at the moment of admission, but there is an even earlier place to push back: the connection itself. When a server is saturated and its worker pool is fully committed, it reads from its sockets more slowly, because there are no free workers to hand the next request to. That slowdown is not a bug to paper over — it is backpressure, and TCP propagates it for free. A reader that drains its socket slowly lets the receive buffer fill; the fill flows back through TCP flow control to the sender's send buffer; and the client's writes start to block or return "would block." The client has now been told, at the transport layer with no application message required, that the far end cannot keep up. The right client reaction is the same as to an explicit busy: slow down.

This is the same mechanism, incidentally, that Zaris's transport watches on the replication path. A send queue to a peer that stops draining is a bounded queue hitting its limit, and the stall is treated as a signal to act on — reset the wedged link, back off, reconcile — never as a reason to buffer replication traffic without bound. A queue that will not drain is information everywhere it appears in the system, and the consistent design choice is to read that information and respond, rather than to keep accepting into a reservoir that has no bottom.

Headroom is the real setting​

All of this comes down to one operational truth that is easy to forget when you are chasing a throughput number: a system run at 100% of its sustainable rate has no room to absorb a burst, and every real workload is bursty. The bounded queue is the headroom — it lets a short spike ride through without rejection — but it is finite on purpose, so that a spike which is not short turns into fast rejections rather than a slow death. Sizing it is the whole art: deep enough to absorb the bursts you actually see, shallow enough that it never holds more work than you could drain before those requests' deadlines pass. A queue deeper than that deadline is not headroom; it is just a bigger reservoir to drown in.

Wrap-up​

Overload is not an exceptional condition to be engineered away; it is a certainty to be planned for, and the plan is visible in how the system behaves at its limit. Accept everything into an unbounded queue and you have chosen unbounded latency followed by a crash, with the server spending its final healthy moments serving requests whose callers are long gone. Bound the queues, let the transport carry backpressure, and reject the overflow with a prompt, honest busy, and you have chosen a system that stays responsive, contains overload at the first node to feel it, and hands its clients a signal they can act on. The difference between a store that degrades and one that collapses is almost never raw speed. It is whether it knows how to say no, and whether it says it on time.