Build a Bounded Blocking Queue for a Log Shipping Pipeline
Last updated: November 29, 2026
Quick Overview
Implement a thread-safe bounded queue where producers block when it is full and consumers block when it is empty, with timeouts and a close operation for clean shutdown.
0
0
0 solved
Implement a thread-safe bounded queue where producers block when it is full and consumers block when it is empty, with timeouts and a close operation for clean shutdown.
Google services commonly buffer work between threads, such as a log agent that batches records before shipping them. Interviewers use this to check condition variable fluency, spurious wakeup handling, and whether you think about shutdown, not just the happy path.
What the Interviewer Expects
- Uses one lock with two condition variables correctly
- Waits in a loop or with wait_for to handle spurious wakeups
- Supports timeouts on put and take
- Implements close that wakes all blocked threads
- Explains why notify rather than notify_all is safe for put and take
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you make put_many atomic for a batch?
- How would you implement this lock-free?
- What changes if consumers must see items in priority order?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
put(item, timeout)blocks while full; returns False on timeout; raises if closed.take(timeout)blocks while empty; raises TimeoutError on timeout; returns None once closed and drained, which ...
High-Level Design
A deque guarded by one mutex. Two conditions share that mutex: not_full for producers and not_empty for consumers. Each mutation signals the opposite side. wait_for re-checks the predicate after...