Backpressure is the mechanism by which a consumer signals to a producer how many items it is ready to receive. Without it, a fast producer and a slow consumer produce one of two outcomes: unbounded buffer growth that eventually exhausts heap, or silent data loss. Neither is acceptable in a production system. The Reactive Streams specification—version 1.0.4, published May 26, 2022, created by Netflix, Lightbend, Pivotal, and LinkedIn among others—defines backpressure through the `Subscription.request(n)` method. A `Subscriber` calls `request(n)` to demand exactly n items from the `Publisher`. The `Publisher` must emit no more than n items before receiving another demand signal. This transforms the default push model into a cooperative push/pull hybrid where the consumer drives the pace. Node.js expresses backpressure differently but equivalently: `stream.write()` returns `false` when the internal buffer reaches the `highWaterMark`, and the `drain` event signals that the buffer has cleared and writing can resume. The Web Streams API—`ReadableStream`, `WritableStream`, `TransformStream`—builds backpressure in structurally via `ByteLengthQueuingStrategy` and `CountQueuingStrategy`, making it a browser-native primitive. Apache Pekko Streams 1.6.0 (compatible with JDK 8 through 21, supporting 200+ operators) implements dynamic push/pull switching: when the downstream is fast, upstream pushes freely; when it slows, the protocol switches to pull mode with explicit demand. Akka Streams offers `OverflowStrategy.dropNew` and `OverflowStrategy.backpressure` as explicit choices for overflow handling. A well-documented case study from Akka HTTP showed that buffering entire FTP responses caused heap stress; switching to entity streaming allowed backpressure to regulate the download rate end-to-end without any memory growth. RxJava 2 provides `onBackpressureBuffer`, `onBackpressureDrop`, and `onBackpressureLatest` as explicit overflow strategies for situations where the source cannot be slowed—say, a UI event stream. Uber's uForwarder, a push-based Kafka consumer proxy that processes trillions of messages per day across 1,000+ consumer services, treats bounded demand as a core architectural invariant rather than an afterthought.
Comments on "Backpressure"
Create a free account or sign in to join the discussion.
Sign in to join the conversation