Skip to content

Design DoorDash

A system design interview walkthrough for DoorDash, a food delivery marketplace, covering the order state machine, courier dispatch timing, tracking and surges.

Advanced24 minUpdated 2 December 2026

Before this: Design Uber, Message Queues

"Design DoorDash" sounds like "Design Uber with food", and candidates who say so lose ground quickly. A ride has two parties and the driver is the whole product. A delivery has three: a customer who wants food, a restaurant that takes minutes to cook it, and a courier who must be at the door of the restaurant at the right moment, not early and not late.

That third timing constraint is what the interviewer is testing. The nearest-driver search is already covered in Design Uber, so we link to it and spend our time on what is new: an order that moves through states owned by different people, a dispatch decision that depends on a cooking time you have to guess, and a dinner rush that compresses a day's orders into a few hours.

Clarify the requirements

Functional requirements:

  1. Customers browse restaurants and menus near them and place an order.
  2. A restaurant accepts the order, marks it preparing and marks it ready.
  3. A courier is assigned, picks up the order and delivers it.
  4. The customer sees the order's status and the courier's location, with an estimated arrival time.
  5. Payment is authorized at checkout and captured on delivery.

Out of scope, said aloud: restaurant onboarding, menu management, ratings, promotions, courier payouts and tipping, and the details of the payment flow (see Design a Payment System).

Non-functional requirements: these shape the design.

  • An order is never lost or duplicated. A double-tapped Place Order button or a retry must create one order and one charge.
  • State transitions are strictly ordered. An order cannot be delivered before it was picked up, and a canceled order cannot be picked up. Several actors change the same order, so races are real.
  • Dispatch is time-critical but can be slightly wrong. A courier arriving five minutes early wastes money, and one arriving late leaves cold food, but nothing is corrupted either way.
  • Tracking is read-heavy and tolerates a few seconds of lag.

Estimate the scale

Assume 10 million daily active customers and 5 million orders a day, so 0.5 orders per active user.

Order rate: 5M ÷ 86,400 ≈ 58 orders per second on average. Orders cluster at meals: suppose 60% of them arrive in a three-hour dinner window, then 5M × 0.6 ÷ (3 × 3,600 s) ≈ 280 orders per second at peak, about 5× the average.

Order events: each order has about 8 state changes (placed, accepted, preparing, ready, assigned, picked up, delivered, plus a payment event), so 5M × 8 = 40M events a day ≈ 460 per second on average.

Browsing reads: assume each active user makes 25 browse calls and 5 tracking polls a day: 10M × 30 = 300M ÷ 86,400 ≈ 3,500 reads per second, with a peak near 10,000.

Courier location: suppose 500,000 couriers are active at the dinner peak, each sending a position every 5 seconds: 500,000 ÷ 5 = 100,000 location updates per second. This one number dwarfs everything else and decides where location data lives.

Storage: 40M events × 500 bytes = 20 GB a day, about 22 TB over three years. Location pings are not kept long-term in the order path.

"Orders are only 280 a second at peak, a modest transactional load. The courier location stream is 100,000 writes a second, so it must not touch the order database. Browsing is a cacheable read. The two sensitive spots are the order's state machine and the dispatch timing."

Try different assumptions in the capacity estimator.

API and data model

POST /v1/orders                    { restaurantId, items[], addressId }   (Idempotency-Key header)
GET  /v1/orders/{id}               -> { status, eta, courier? }
POST /v1/orders/{id}/transitions   { to: "accepted" | "ready" | ..., expectedVersion }
GET  /v1/orders/{id}/stream        -> server-sent status and courier position events
PUT  /v1/couriers/me/location      { lat, lng, ts }
orders     (id PK, customer_id, restaurant_id, status, version, items, total, created_at)
order_events (order_id PK, seq SK, from_status, to_status, actor, at)
courier_location (courier_id -> lat, lng, ts, order_id?)   -- in memory, TTL 30 s

The non-obvious choices are version on the order and the Idempotency-Key. The version makes every transition a compare-and-set, so two actors acting at once cannot both win, and the key turns a retried POST into the same order instead of a second one. The idempotency lesson covers the mechanism.

High-level design

The slice worth running is order intake: a gateway, an order service that owns the order's state, the order store, and an event stream that hands each placed order to dispatch.

Orders pass an API gateway to an order service that writes the order store and publishes a dispatch event that dispatch workers consume.clientsgatewayorder apiorder storedispatch eventsdispatch workers
Orders pass an API gateway to an order service that writes the order store and publishes a dispatch event that dispatch workers consume.
  • Clients reach the order API through a gateway.
  • The order service writes the order to its database, then publishes an event to a stream that dispatch workers consume.
Describe this diagram

Components

  • clients (Client)
  • gateway (API gateway)
  • order api (Service)
  • order store (PostgreSQL)
  • dispatch events (Kafka)
  • dispatch workers (Service)

Connections

  • clients sends to gateway
  • gateway sends to order api
  • order api sends to order store
  • order api sends to dispatch events
  • dispatch events sends to dispatch workers

Run it, then try raising the load to dinner-rush levels and watch the order store before the stream.

The write path: the order service validates the cart, claims the idempotency key, writes the order in placed state and an outbox row in one transaction, and returns. A relay publishes the outbox row to the stream, so an order and its event never disagree. Dispatch workers read the stream, and restaurants are notified through their tablet's connection.

The read path: the customer app subscribes to a status stream or polls GET /v1/orders/{id}. Courier position comes from the in-memory location store, not the order database. Restaurant and menu browsing is served from a cache, because menus change a few times a day.

The interesting problem: when to dispatch a courier

In Design Uber, the best driver is the nearest one and the rider is already waiting. Here the food does not exist yet. The right moment to dispatch depends on how long the restaurant will take.

Approach A: assign the nearest courier at checkout

Good: simple, and it reuses the nearest-neighbor search from Uber. Customers see "courier assigned" immediately.

Bad: a restaurant that takes 25 minutes to cook leaves the courier standing at the counter for 20 of them. That is wasted courier time and money, and it removes the courier from the pool for other orders. For a fast-food order the same rule works well, which is why a fixed rule is wrong.

Approach B: dispatch just in time

Predict the restaurant's ready time from its recent preparation times, the order's size and the current queue, and predict the courier's travel time to the restaurant. Dispatch when now + travel ≈ ready − small buffer.

Good: couriers spend their time moving, not waiting, and food leaves the kitchen warm.

Bad: it depends on two predictions. If the ready time is underestimated, the food waits. If the courier is late, the food is cold. You need feedback from the restaurant (an "order is ready" tap) to correct the estimate as time passes.

Approach C: batch assignments over a short window

Collect the orders that need a courier and the couriers who are free, for a short window such as 10 to 30 seconds, then solve an assignment problem: choose the pairing that minimizes total expected wait and travel across all of them. The same step can stack two orders from nearby restaurants onto one courier.

Good: a globally better answer than assigning each order greedily, and it makes stacking possible.

Bad: a few seconds of added latency, and a heavier computation than a nearest search.

The recommended answer combines B and C: each order gets a dispatch time from the ready-time prediction, and orders that are due are assigned together in small windows. Say why: the cost you are minimizing is courier idle time and food waiting time, and neither is visible to a one-order-at-a-time rule.

Conceptual diagramOrder placedPredict ready timeDispatch due: now + travel = readyBatch window of due ordersAssign couriers, possibly stackingCourier claims order atomically
Diagram, as text
  • Order placed leads to Predict ready time
  • Predict ready time leads to Dispatch due: now + travel = ready
  • Dispatch due: now + travel = ready leads to Batch window of due orders
  • Batch window of due orders leads to Assign couriers, possibly stacking
  • Assign couriers, possibly stacking leads to Courier claims order atomically

The final step reuses the answer from Uber: the courier is claimed with an atomic conditional update, so two orders can never take the same courier. Say that in one sentence and move on. If the courier declines or times out, the order returns to the next window with its priority raised.

The second decision: the order state machine and tracking

An order has several writers: the customer (cancel), the restaurant (accept, ready), the courier (picked up, delivered), the dispatcher (assigned) and a timer (auto-cancel). Without discipline, they race.

Model it as an explicit state machine. Allowed transitions are a table: placed → accepted → preparing → ready → picked_up → delivered, with cancellation allowed from placed, accepted and preparing but not afterward. A transition request carries the order's expectedVersion, and the service applies it with one conditional update:

UPDATE orders SET status = 'ready', version = version + 1
WHERE id = ? AND status = 'preparing' AND version = ?;

If zero rows change, the order moved on, so the caller reloads and decides again. Every transition appends a row to order_events, so support can see exactly what happened.

Tracking: push or poll? Polling every five seconds from 10M users is simple, but wasteful and it adds read load at the worst moment. Push status changes over a server-sent stream or WebSocket for orders in progress, and read the courier position from the in-memory store, throttled to one update every few seconds. Fall back to polling when the stream drops. Use the client's last event number so a reconnect does not miss or repeat a state.

Money follows the state. Authorize the card at checkout, capture on delivered, and void the authorization on cancellation. That is a small saga: the order and the payment are different systems, so each step needs a compensating action.

Bottlenecks and failures

Dinner surge. Demand rises 5× in minutes while the number of couriers does not. The system must degrade by queueing, not by dropping orders: show longer estimates, pause new orders to overloaded restaurants and raise courier incentives. Scale the order service ahead of known meal peaks.

The location firehose. 100,000 updates a second belongs in an in-memory store with a short TTL, partitioned by geographic cell. It must never share a database with orders. Losing a few pings is harmless, because the next one arrives in five seconds.

Restaurant tablet offline. If no acceptance arrives within a timeout, retry through a second channel such as an automated call, then cancel and refund. Never leave an order in placed without a timer.

Stuck orders. A worker that crashes after a state change but before publishing the event leaves an order dispatch never sees. The outbox fixes this by making the event part of the same transaction. A sweeper that finds orders that sat in one state too long catches anything else.

Duplicate and abusive orders. The idempotency key stops accidental duplicates. Rate-limit order creation per user, and watch for promo-code abuse and chargebacks.

What if dispatch is down? Orders still arrive and wait in the stream. Dispatch catches up when it returns, and the ready-time prediction should not assume a courier is available when many orders have piled up.

Trade-offs to name aloud

  • Just-in-time dispatch over assign-at-checkout: less courier idle time, in exchange for dependence on a prediction.
  • Batching windows: a few seconds of delay in exchange for better global assignments and stacking.
  • An outbox over publishing directly: an extra relay, in exchange for never losing an order's event.
  • Push for in-progress orders, polling as fallback: more connections to manage, in exchange for lower latency and less read load.

What interviewers listen for

  • A working answer: an order service with a database, a state machine, a stream to dispatch, courier locations in a fast store and a reference to nearby-courier search.
  • A strong answer: sees that location updates are the largest write stream and keeps them off the order database, uses versioned transitions to prevent races, and explains the idempotent order creation.
  • A standout answer: argues for dispatching by predicted ready time instead of at checkout, batches assignments and stacks orders, ties payment authorization and capture to the order's states and describes how the prediction is monitored.

Check your understanding

Common mistakes

Calling it Uber with menus. The timing against a cooking process, and the order's several owners, are the new problems. Link to the driver-matching answer and move on.

Putting location pings in the order store. It is the biggest write stream by a factor of hundreds. Keep it in memory and expire it.

No explicit state machine. Without a table of allowed transitions and versioned updates, a canceled order gets picked up and nobody can explain how.

Publishing events outside the transaction. An order written without its event is invisible to dispatch. Use an outbox, or the order may sit forever.

Assigning couriers greedily at checkout. It looks fine in a small test and wastes courier time at scale.

Ignoring the restaurant as an unreliable actor. Tablets go offline and staff forget to press accept. Every wait needs a timeout and a fallback.

Practice

During a storm, 40% of couriers go offline while orders keep arriving at the dinner peak of about 280 per second. What does the system do?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

You cannot create couriers, so decide what to slow down, what to refuse and what to tell customers.

Show a strong answer

Protect the order path. Orders are cheap to accept and expensive to lose, so keep accepting them into the stream, but do not promise a delivery time you cannot meet.

Raise the estimates honestly. Dispatch knows the ratio of waiting orders to free couriers, so feed it into the ETA the customer sees at checkout. Show a longer time, or temporarily pause new orders from far-away or slow restaurants.

Prioritize in the window. In each batch, favor orders that have waited longest, and stop stacking only where it would delay a first order. Offer higher courier incentives in the affected zones to bring supply back.

Cancel with care. Orders waiting beyond a limit are canceled and the authorization voided, never captured, with a clear message.

The pattern worth keeping: when supply drops, shed load at the edge with honest estimates and priorities, and keep the durable order path healthy.

Restaurants complain that couriers arrive too early, and food orders show 'ready' ten minutes before the food is. How do you fix the dispatch timing?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

Find which of the two predictions, ready time or travel time, is off, then correct it from data.

Show a strong answer

Find the error source. Log, per order, the predicted ready time, the time the restaurant tapped Ready, the predicted travel time and the courier's actual arrival. The differences by restaurant show whether cooking time or travel is wrong.

Fix the ready time. If restaurants tap Ready early to look fast, the label is unreliable. Use the courier's pickup time as a second signal, and weight recent orders by restaurant and hour. Add a buffer for restaurants that are consistently late.

Add a feedback loop. Let the courier's arrival check a restaurant's real status (food on the shelf or not) and adjust the order's estimate in flight, so later dispatch decisions use it.

The pattern worth keeping: a prediction in a control loop needs measured error and a feedback signal you trust, not a one-time tuned number.

Key takeaways

  • Three parties, not two: the food's cooking time makes dispatch timing the core problem.
  • Courier locations are the biggest write stream: keep them in memory with a TTL, off the order database.
  • An explicit state machine with versioned, conditional transitions keeps several writers from corrupting an order.
  • Dispatch just in time and in small batches, and reuse the atomic courier claim from the Uber design.
  • Use an outbox so that an order and its event can never disagree, and an idempotency key so retries cannot duplicate it.
  • Under surge, degrade honestly: queue and raise estimates instead of dropping orders.

Further reading

  • Martin Kleppmann, "Designing Data-Intensive Applications" (O'Reilly, 2017): chapters on transactions, derived data and stream processing.
  • Pat Helland, "Life beyond Distributed Transactions: an Apostate's Opinion", CIDR (2007): why state changes across services need idempotent messages and compensation.
  • H. W. Kuhn, "The Hungarian Method for the Assignment Problem", Naval Research Logistics Quarterly (1955): the classic algorithm for optimal pairings.

Check yourself

3 questions in this lesson. Answer each once to complete it.

Practice this

Lessons in this track