Problem statement
Design a thread-safe bounded blocking queue: a fixed-capacity FIFO that blocks a producer when it is full and a consumer when it is empty. It is the backbone of an in-process producer/consumer pipeline where several threads on each side share one queue.
Operating context. One process, multiple producer and consumer threads, capacity fixed at construction. put(item) blocks while the queue is at capacity; take() blocks while it is empty. Callers also want bounded variants, offer(item, timeout) and poll(timeout), that give up after a deadline. The design carries backpressure: a slow consumer naturally throttles fast producers by leaving them blocked on a full queue.
Out of scope. Distributed or durable queues, priority ordering, the work items themselves, cross-process IPC, and any persistence or replay of the queue contents.
What to produce. The class model (the queue, its internal storage, the condition variables), the public API with blocking and timed variants, and the state transitions of the buffer (empty, partial, full). Be explicit about how you avoid lost wakeups, how you signal the minimum necessary waiters instead of a thundering herd, and how the backing storage strategy is swappable behind the queue's interface.
Requirements
This assessment is a Premium feature.
The statement above is free to read. The functional and non-functional requirements, and the graded canvas that scores your design against them, come with Premium.
Topics
- System Design LLD
- Concurrency Condition-Variables
- Concurrency Blocking
- Patterns Producer-Consumer
- Oop Interface-Design