Backpressure: when the producer is 3× faster, how does the queue not overflow?
TL;DR
Backpressure lets the receiving side tell the sender to slow down. A buffer has a high watermark that triggers PAUSE and a low watermark that triggers RESUME. The queue never overflows and the whole system runs at the consumer’s speed.
How watermarks work (8-slot buffer)
| Point | What happens |
|---|---|
| Hits high watermark 6/8 | A PAUSE signal travels back to the producer. |
| Peaks at 7/8 | 2 in-flight messages still land — that’s why the threshold sits below capacity. |
| Drops to low watermark 2/8 | RESUME is signalled and the producer continues. |
A 3× faster producer doesn’t raise throughput: the system always runs at the consumer’s 1 msg/s.
How to put it to work
- Avoid unbounded queues in production code — they’re the fastest route to an OOM.
- Pick a strategy when full: block the producer (backpressure), drop/sample messages, or return 429 to clients.
- Built into many tools: Node.js streams (
highWaterMark, thedrainevent), Reactive Streams/RxJS, TCP flow control, Kafka consumer lag. - Fix the root cause: if the producer is always faster, scale consumers — backpressure only keeps the system from falling over.