Bounded Blocking Queue for Order Events With Clean Shutdown
Last updated: November 29, 2026
Quick Overview
Implement a bounded blocking queue between the checkout service and dispatch workers: put blocks when full, get blocks when empty, both accept timeouts, and close() wakes all waiters so shutdown never hangs while remaining items still drain.
DoorDash
November 29, 20260
0
0 solved
Implement a bounded blocking queue between the checkout service and dispatch workers: put blocks when full, get blocks when empty, both accept timeouts, and close() wakes all waiters so shutdown never hangs while remaining items still drain.
Backpressure between services comes up across DoorDash's order pipeline, and building the primitive yourself shows real understanding of condition variables. Interviewers look for while-loops around wait (spurious wakeups), two conditions sharing one lock, correct timeouts, and a shutdown story.
What the Interviewer Expects
- Use one lock with two condition variables
- Wait inside while loops, never if
- Compute remaining time against a monotonic deadline
- Make close() notify_all on both conditions
- Let consumers drain remaining items after close
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 non-blocking and return a 503 to callers when full?
- How would you add priorities so DashPass orders jump the queue?
- What metrics would you emit to detect a stuck consumer?
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=None): blocks while full; returns False on timeout; raisesClosedif closed.get(timeout=None): blocks while empty; raisesTimeoutErroron timeout; raisesClosedonly w...
High-Level Design
State is a deque protected by one lock. not_full and not_empty are conditions on that lock, so a producer waiting for space and a consumer waiting for data never miss each other's signal. Each wai...