← Lessons

quiz vs the machine

Platinum1760

Concurrency

Backpressure In Reactive Streams

Let slow consumers signal demand so fast producers do not overwhelm them.

6 min read · advanced · beat Platinum to climb

Backpressure In Reactive Streams

When a fast producer feeds a slow consumer, unbounded buffering eventually exhausts memory. Backpressure is the mechanism by which a consumer tells a producer how much it can handle, turning a push firehose into a controlled flow.

The Reactive Streams specification formalizes this with a small protocol. A subscriber calls request n to grant demand, and the publisher may emit at most n items before waiting for more demand. Items beyond the granted demand must not be sent. This is demand driven or pull push hybrid flow: the producer pushes, but only up to what was pulled.

When a source cannot be slowed, such as sensor readings or stock ticks, the system applies an overflow strategy:

  • Buffer Hold items up to a bound, then fail or drop.
  • Drop Discard the newest or oldest items beyond capacity.
  • Latest Keep only the most recent value.

Backpressure propagates across stages. A slow database sink signals its operator, which lowers its own demand upstream, and the signal flows all the way back to the source. This end to end coordination keeps every buffer bounded and prevents the silent memory growth that plagues naive push pipelines. Frameworks like Reactor, RxJava, and Akka Streams implement these semantics.

Key idea

Backpressure makes consumers signal demand so producers emit only what can be handled, keeping buffers bounded end to end.

Check yourself

Answer to earn rating on the learn ladder.

1. In Reactive Streams, how does a subscriber control flow?

2. What is an overflow strategy used for?