Skip to content
Preptima
hardDesignCodingMidSeniorStaff

Design a producer-consumer pipeline with a bounded buffer. What do you do when the buffer is full?

A producer-consumer bounded buffer applies backpressure to the producer instead of letting an unbounded queue absorb overload until the process dies. Deciding what a full buffer does - block, drop, or reject - is the decision that determines how the system fails.

6 min readUpdated 2026-08-15

Answer

Short answer

In a producer-consumer bounded buffer, the queue capacity is the backpressure mechanism. When the buffer is full, the producer must either block, drop work, or reject the item immediately; choosing among those policies is part of the design, not an implementation detail. A correct implementation uses a library bounded queue or waits on conditions in a while loop, and it defines shutdown and poison-item handling explicitly.

Was this answer helpful?

Likely follow-ups

  • Why must a wait on a condition variable be inside a while loop rather than an if?
  • Your consumers are stuck and the buffer is full. How would you tell that apart from a slow producer?
  • How do you shut this down cleanly without losing items already accepted?
  • One item throws every time it is processed. What happens to the pipeline?

Related questions