Thread-Safe Order Claiming That Never Double-Assigns a Delivery
Last updated: November 29, 2026
Quick Overview
Several dispatch workers may concurrently offer the same order to different Dashers. Implement claim(order_id, dasher_id) and complete(order_id) so each order is claimed by exactly one Dasher and no Dasher exceeds a maximum number of active orders.
DoorDash
November 29, 20260
0
0 solved
Several dispatch workers may concurrently offer the same order to different Dashers. Implement claim(order_id, dasher_id) and complete(order_id) so each order is claimed by exactly one Dasher and no Dasher exceeds a maximum number of active orders.
Double assignment, where two Dashers arrive for one order, is a classic DoorDash concurrency failure. Interviewers use this to probe check-then-act races, lock granularity, consistent lock ordering to avoid deadlock, and how the in-memory answer maps to a database conditional write.
What the Interviewer Expects
- Identify the check-then-act race in a naive dictionary version
- Use lock striping so unrelated orders do not contend
- Acquire locks in a fixed global order
- Keep the critical section small
- Explain the distributed version with a conditional update or compare-and-set
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 implement this across many dispatch hosts with a database?
- What happens if a Dasher's app crashes after claiming?
- How would you test for races deterministically?
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
claimreturns True for exactly one caller per order, and only if the Dasher has fewer thanmax_activeorders.completereleases the order and decrements the Dasher's count; a second call ret...
High-Level Design
A naive if order not in owner: owner[order] = dasher lets two threads both pass the check. Wrap the check and the write in a lock. A single global lock is correct but serializes all dispatch, so str...