SproutStackSproutStack home

Backpressure & Flow Control

6 min readBeginner-friendlyFree to read

Before this, it helps to know: Queues & Pub/Sub.

Read a little, play a little. No scary maths, and no rush.

Share:

The mismatch that breaks systems

A producer emits events at 10,000/sec; a downstream consumer can process 2,000/sec. Something has to absorb that 8,000/sec gap. With no plan, it's an in-memory queue that grows until the process runs out of memory and crashes — the worst possible place for a slowdown to surface, because by the time it's visible, it's an outage.

Backpressure: push the slowdown somewhere survivable

Backpressure is any mechanism that signals "slow down" back toward the producer instead of silently absorbing unlimited work. Concretely: a bounded queue that blocks or rejects once full (TCP does this at the socket level — a full receive buffer stalls the sender), a rate limiter that returns 429 instead of queuing indefinitely, or a pull-based protocol where the consumer explicitly requests the next batch (Kafka consumers do this — nothing is pushed faster than a consumer's own offset commits allow).

Push vs pull changes who's in control

Push systems are simple until the consumer can't keep up — then every unbounded push model needs backpressure bolted on after the fact. Pull systems build the limit in from the start: the consumer only gets what it asks for, so it can never be overwhelmed by more than its own request size. This is why many high-throughput systems (Kafka, reactive streams) default to pull or request-based flow, rather than push-and-hope.

Deciding what to do when you're full

Once a buffer is bounded, something must happen when it's full: block the producer (correct but can cascade the slowdown upstream), drop new or oldest items (fine for metrics/telemetry, unacceptable for financial events), or reject with a signal the caller can retry later (an explicit 429/503 beats a silent timeout). There's no universally right choice — the right one depends on whether losing an item is worse than slowing down the whole pipeline.

at capacityslow downProducer10,000 events/sBounded bufferfixed sizeConsumer2,000 events/sWhen it is fullblock, drop or reject
The buffer has a fixed size. When it fills, a deliberate policy decides what happens, and the producer is told to slow down instead of the process running out of memory.

A worked example: a log pipeline under a spike

Application servers ship logs to a central pipeline that normally handles the load comfortably. A bad deploy makes one service log five times more than usual. The pipeline uses a bounded buffer and a clear policy: when the buffer fills, drop debug-level logs first, always keep errors, and count every drop. The counter feeds an alert, so the team learns within minutes that logs are being shed, and why. Without the bound, the pipeline's memory would have grown until it crashed, losing everything, errors included.

Backpressure across the network

Between services, the "slow down" signal is usually an HTTP status: 429 (too many requests from you) or 503 (I am overloaded), ideally with a Retry-After header saying when to come back. Well-behaved clients wait as told. When a server is overloaded, load shedding goes one step further: deliberately reject the least important work first, such as background syncs or analytics calls, so that critical requests like checkout keep succeeding.

How missing backpressure shows up

Memory that climbs steadily under load and never comes back down, latency that keeps rising while throughput stays flat, and queues whose oldest item keeps getting older. Each of these means work is arriving faster than it leaves, and something is absorbing the difference without limit.

Remember this

  • Someone must absorb a producer/consumer speed mismatch — backpressure decides who, deliberately.
  • Pull-based consumption builds the limit in; push-based systems need backpressure added after the fact.
  • When a bounded buffer fills, block/drop/reject is a product decision, not just an engineering one.

Check your understanding

5 questions · first-try answers earn the most XP

1. Without any backpressure, a producer emitting 10,000 events/sec into a consumer that handles 2,000/sec will cause…
2. Which mechanism is the textbook example of backpressure applied at a socket level?
3. Why do many high-throughput systems (like Kafka and reactive streams) prefer pull-based consumption over push?
4. Once a bounded queue is full, choosing to drop new items is acceptable for which kind of data?
5. When a bounded buffer is full, is it acceptable to block the producer rather than drop items?

My notes

Saved in this browser. Highlight a line above and save it, or write it in your own words.

Nothing saved yet. Your highlights will live here.

References

Finished reading?

Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.

Practice this in an incident

Try a design drill

Related chapters

Spotted a mistake or want a topic covered? Report an issue

📬 An occasional email when new lessons land

New lessons and showdowns, no more than a few times a month. No spam, unsubscribe anytime. We store your email only to send the newsletter.