Backpressure

On this page 7

Backpressure is a flow-control mechanism that propagates a signal from a slower downstream consumer to a faster upstream producer, so the producer slows down, buffers or sheds load instead of overwhelming the system. In streaming data, it keeps pipelines stable when the rate of incoming events temporarily exceeds the rate at which they can be processed.

Without backpressure, a fast source facing a slow sink has only bad options: unbounded memory growth, crashes or silent data loss. With it, the whole pipeline settles at the throughput of its slowest stage, and overload becomes visible and manageable instead of catastrophic.

How backpressure works

Backpressure works by bounding the buffers between stages and making a full buffer slow down the stage that fills it. When an operator cannot accept more data, its input queue fills, the upstream operator blocks or stops requesting more, and the effect travels backward until it reaches the source.

Systems implement this signal in two main ways. In push-based systems with credits, a receiver grants the sender a number of credits, one per buffer it can accept, and the sender transmits only while credits remain. In pull-based systems, consumers request data when they are ready, so a slow consumer naturally reads less. The Reactive Streams specification formalizes this demand signaling for asynchronous libraries, and TCP flow control applies a similar idea at the network level through its receive window.

MechanismHow the signal travelsTypical setting
Credit-based flow controlReceiver grants send creditsDistributed stream processors
Pull-based consumptionConsumer fetches when readyLog-based brokers such as Kafka
Demand signalingSubscriber requests n itemsReactive Streams libraries
Blocking bounded queuesProducer waits on a full queueIn-process thread pipelines
TCP receive windowWindow size shrinks toward zeroNetwork connections
Backpressure mechanisms in common streaming patterns

Backpressure with message brokers and event streams

A durable message broker changes the backpressure picture. With Kafka, consumers pull records at their own pace, so a slow consumer does not block producers. Instead, the gap appears as consumer lag, the difference between the latest offset written and the latest offset processed.

This decoupling absorbs bursts gracefully, but it only moves the problem. If lag keeps growing, data eventually exceeds the retention period and is deleted before it is read, and event-time results such as windowed aggregates become increasingly late. Lag must therefore be monitored as the backpressure signal of broker-based architectures.

LocationVisible symptomMain metric
Producer clientSend calls block or time outBuffer usage, send latency
Message brokerGrowing backlog of unread dataConsumer lag in records or time
Stream processorOperators marked as backpressuredBusy time, input buffer usage
Sink databaseSlow or rejected writesWrite latency, throttling errors
Where backpressure shows up in a streaming architecture

Strategies for handling overload

Backpressure is one of several strategies for handling a producer that is faster than its consumer. Which one fits depends on whether data may be lost, delayed or summarized.

StrategyWhat happens to excess dataWhen it fits
BackpressureProducer slows downEvery event matters, sources can wait
BufferingStored temporarilyShort bursts with bounded size
Dropping or samplingDiscarded deliberatelyMetrics, telemetry, sensor readings
Load sheddingLow-priority work rejectedUser-facing services under peak load
AutoscalingCapacity is addedSustained growth, elastic infrastructure
ConflationOnly the latest value keptMarket prices, live positions
Overload strategies compared

Real systems combine strategies. A pipeline may buffer short bursts, apply backpressure for sustained overload and trigger autoscaling when lag stays above a threshold for several minutes.

Diagnosing and tuning backpressure

Diagnosing backpressure means finding the slowest stage, because the backpressured operators are victims and the bottleneck is the first operator downstream of them that is not backpressured. Stream processors such as Apache Flink report backpressure and busy time per operator, which makes this search straightforward.

  • Check the sink first: slow database writes and external API calls are the most common bottlenecks.
  • Look for data skew, where one key or partition receives a disproportionate share of events.
  • Inspect garbage collection pauses and state backend performance in stateful operators.
  • Increase parallelism or partitions only after confirming the bottleneck can scale out.
  • Use asynchronous input and output with bounded concurrency for external lookups.

Buffer sizes are a trade-off. Larger buffers raise throughput and absorb jitter but increase latency and checkpoint duration, while very small buffers react quickly yet waste capacity on coordination.

Common mistakes with backpressure

The classic mistake is an unbounded queue between stages. It hides overload until memory runs out, turning a slowdown into an outage, which is why bounded buffers are a design requirement rather than an optimization.

Other frequent errors include treating backpressure alarms as problems in the backpressured operator rather than its downstream bottleneck, adding retries without limits that multiply load on an already slow sink, and ignoring consumer lag in time units, which matters more to users than lag in record counts.

A further pitfall is a source that cannot be slowed at all, such as sensors, clickstreams or webhooks from external partners. Backpressure stops at that boundary, so the design must place a durable buffer such as a broker at the edge of the system, or define in advance which data may be sampled or dropped. Testing pipelines with synthetic load at two to three times normal peak reveals where pressure accumulates before a real incident does.

Explained without jargon

Think of a factory line where one worker packs boxes more slowly than the others fill them. If nobody tells the earlier workers to slow down, boxes pile up until they fall off the belt.

Backpressure is the message passed back along the line asking everyone upstream to wait because the next station is full. Everyone then works at the pace of the slowest worker. Nothing is lost, and the pile never grows out of control, although the whole line moves only as fast as its slowest step.

A typical use case

A logistics company streams GPS positions from 40,000 delivery vans, each sending one update every 5 seconds, which averages about 8,000 events per second. A stream processor reads the events from Kafka, enriches them with route data and writes them to a time-series database that powers a live map.

During the evening peak, the database slows down because of a heavy reporting query. The processor’s sink operator fills its buffers, upstream operators show high backpressure, and consumer lag grows from seconds to about six minutes. No events are lost because Kafka retains them for seven days. Engineers move reporting to a read replica and add asynchronous batched writes, after which the processor drains the backlog in about 15 minutes. The incident becomes a delay rather than data loss, exactly the behavior backpressure is designed to produce.