← Lessons

quiz vs the machine

Gold1380

Concurrency

The Bounded Queue For Backpressure

How a fixed size queue forces fast producers to slow down.

5 min read · core · beat Gold to climb

The Bounded Queue For Backpressure

When a producer creates work faster than a consumer can finish it, an unbounded queue between them quietly fills until memory runs out and the system crashes. The fix is a bounded queue with a fixed maximum size.

The bound creates backpressure. When the queue is full, a producer trying to add an item blocks or is rejected. That pause travels upstream: the producer cannot race ahead, so it naturally matches the consumer's pace. The queue becomes a signal, not just storage.

  • Hard ceiling Memory use is capped at the queue size, so a slow consumer cannot crash the process.
  • Pace matching A blocked producer slows down, aligning input rate with processing rate.
  • Reject or wait The full queue can either block the producer or reject the item so callers can shed load.

Backpressure makes overload visible and controllable instead of silent and fatal. Without it, latency grows without limit as items pile up; with it, the system degrades gracefully by slowing intake or refusing excess work.

Key idea

A bounded queue caps memory and creates backpressure, forcing a fast producer to slow to the consumer's pace instead of overflowing.

Check yourself

Answer to earn rating on the learn ladder.

1. What danger does an unbounded queue create under overload?

2. How does a bounded queue create backpressure?