Notesfoundations🌱 seedling

Backpressure

Also: Back Pressure · Flow Control

Backpressure is a consumer signalling its producer to slow down when it can't keep up, so work waits upstream instead of piling up in an unbounded buffer. It loses nothing, but only works if the producer can afford to wait.

Why it exists

A fast producer and a slower consumer joined by an unbounded queue turn overload into ever-growing latency and memory use, silently, until something falls over. After an hour-long outage, a system that queued everything needs double its capacity for another hour just to catch up, and much of that backlog is stale by then.

How it works

  • Bounded buffers: when the queue is full, the producer blocks or is told "not now".
  • Credit / demand signalling: the consumer grants permission for n more items. TCP's receive window and Reactive Streams' request(n) work this way.
  • Pull instead of push: a consumer that fetches at its own pace (like a Kafka consumer in a Consumer Group) gets backpressure for free; lag grows in the log instead of in memory.
  • Pressure propagates upstream hop by hop until it reaches something that can wait, or something that must reject.

Trade-offs

Gains Costs
no work lost producers slow down; end-to-end latency grows
bounded memory everywhere a slow consumer can stall the whole pipeline
natural fit for pipelines and batch useless where the caller is a human who won't wait

In practice

  • Streaming pipelines (Kafka, Flink) rely on it: consumer lag is the visible measure of pressure.
  • At the edge, pressure must turn into rejection: Load Shedding or Rate Limiting with 429/503.

Pitfalls

  • "Elastic" unbounded queues that hide overload until the backlog is unrecoverable. Bound them, give items a TTL, and alarm on the age of the oldest item.
  • Applying backpressure to interactive traffic: users time out and retry, making it worse.

Recall

These cards are also in your review deck, scheduled with spaced repetition.