Glossary / Backpressure
Backpressure
Backpressure is feedback from a slower consumer or downstream stage that tells a producer to slow down, pause, or stop generating data. It prevents unbounded buffering and memory growth in streams, queues, network pipelines, and asynchronous worker systems. Without backpressure, a fast producer can overwhelm a slow consumer even if each component is individually correct.
Producer-consumer control
A bounded queue can expose capacity or a “ready” Promise; the producer waits before enqueueing more. Web Streams use internal queues, queuing strategies, high-water marks, and desired size to communicate demand. Node streams use write() returning false and a later drain event as a key signal. Async iteration can also be demand-driven when the producer advances only on next().
Backpressure is end-to-end only when every stage propagates it. A transform that eagerly buffers all input defeats downstream flow control. Consider chunk size, high-water mark, cancellation, error propagation, and whether the producer can actually pause. For message queues, a bounded consumer concurrency and acknowledgment policy play a similar role.
Backpressure is distinct from rate limiting: it responds to current capacity, while a rate limiter enforces a policy over time. Both may be needed. Monitor queue length, buffered bytes, latency, drop rate, and consumer throughput.
Interview questions
- What problem does backpressure solve? It prevents producers from overwhelming slower consumers and growing buffers without bound.
- How does a Node Writable signal pressure?
write()can return false; wait fordrainbefore writing more. - What is a high-water mark? A queue threshold used to signal desired buffering/capacity, not necessarily a hard total-memory limit.
- How can a pipeline lose backpressure? An intermediate stage eagerly buffers instead of propagating demand upstream.