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
Software Engineering Fundamentals
Software Engineer
DoorDash
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Hard

0

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
concurrency
condition variables
backpressure
producer consumer
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. 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 Problems
Sample Answer
Requirements
  • put(item, timeout=None): blocks while full; returns False on timeout; raises Closed if closed.
  • get(timeout=None): blocks while empty; raises TimeoutError on timeout; raises Closed only 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...


Submit Your Answer
Markdown supported