Design a food delivery service like DoorDash
hard 60 minA customer orders, a kitchen cooks, a courier carries, and all three watch the same order while the food cools.
Video lesson · Chapter 1 of 5
Dinner is accepted before a courier is chosen
Theory
Read or listen first. About 2 min.
What it is
A food delivery service connects three sides. Customers order, restaurants cook, couriers carry. The service takes the order and the money, finds a courier, and tells everyone what is happening.
It is a shop and a moving map at once. The shop part is orders and payments, where each step must happen once. The map part is thousands of couriers, whose newest position replaces the one before.
Why it exists
Food has a short life. Ten minutes too early and the courier waits; ten minutes too late and the meal is cold. So the question is not only who is near, but who arrives when the pot is ready.
For a designer it joins three hard things: a process that crosses services and companies, a stream of small fast updates, and a matching problem that repeats every few seconds.
A short history
1955
Harold Kuhn publishes the Hungarian method for the assignment problem, a way to match workers and jobs at the lowest total cost.
1994
Pizza Hut takes an early online food order.
February 2008
Gustavo Niemeyer launches geohash.org: short strings that name areas of the map.
December 2011
RFC 6455 standardises WebSocket, a two-way connection that apps use for live updates.
January 2013
Stanford students launch PaloAltoDelivery.com, which becomes DoorDash.
Words to know
- Courier
- The person who carries the order. Some companies use another name.
- Ping
- One position report from a courier's phone.
- Dispatch
- Choosing which courier is offered which order, and when.
- Offer
- A short, exclusive chance to accept one order, here 30 seconds.
- ETA
- Estimated time of arrival. A range is more honest than one minute.
- Batching
- Two meanings: collecting orders for a few seconds before matching, and carrying two orders in one trip (stacking).
- Market
- One city area that runs on its own: its restaurants, couriers and orders.
- Saga
- A process of local steps, each with an undo step.
Solve it like an interview
New to it? Start with Approach. Revising? Go straight to the mock.
- 1ApproachWhat this question tests, where it gets hard, and how to spend the time.
- 2ScopeAsk what changes the design, then commit to a short list.
- 3NumbersWork out a number when the answer changes what you build.
- 4API and dataThe contract first, then the data that serves it.
- 5DesignStart with the smallest system that works. Change it only when something breaks.
- 6Deep divesCompare the options before you open them, then say which you would pick.
- 7Explain your choicesAnswer first. Then compare your reasoning.
- 8By levelThe same question is judged differently for mid, senior and staff.
- 9MockAnswer against the clock, then score yourself.
How it works
Step through the idea, or press Play.
Order. Store, hold the money, ask the kitchen
Understand it
The slate must be right. The sky changes all the time.
Scope
What are we building?
Customers find restaurants that deliver to them, order and pay. Restaurants accept and cook. Couriers are offered orders, pick up and deliver. Everyone sees the same state and an estimate.
Order
Exact, paid once, never lost.
Dispatch
The right courier at the right minute, again and again.
Track
52,000 pings a second at peak, and 209,000 people watching.
Predict
Cooking, driving and parking, as a range.
Similar applications
| Product | The twist |
|---|---|
| Uber Eats | Shares couriers and maps with ride hailing |
| Grubhub | Grew from restaurant ordering |
| Postmates | Many kinds of shops |
| Instacart | Groceries: somebody picks items and replaces missing ones |
| Deliveroo | Strong in European cities |
| Swiggy, Zomato | India; Zomato began with restaurant discovery |
| Gopuff | Own small stores, so stock is known |
How it differs from its neighbours
| Compared with | Same | Different |
|---|---|---|
| Ride hailing | Positions, matching, offers | A kitchen's timing in between; nobody waits at the kerb |
| A web shop | Basket, payment, state machine | Minutes instead of days; three parties live |
| Restaurant search | Places near you | Only those that deliver to your door now |
The finished system
Where the design ends up
This is the last version. Design begins with one service and one database, and names the break that forces each box.
The whole system
Where to read what
| Question | Interview tab | Concept page that owns the idea |
|---|---|---|
| What must it do? | Scope | Scoping |
| How big is it? | Numbers | Numbers that decide |
| What is the interface? | API and data | Idempotency, real-time APIs |
| How does it grow? | Design | Saga, log-based queues |
| What is hard? | Deep dives | Stream processing, pub-sub |
| Can I do it aloud? | Mock | 45 minutes |
Summary
The whole topic in one minute.
An order is a small state machine in a transactional store: stored before money is touched, charged with one key, and moved forward only from the expected state. A courier is claimed for it by one conditional write.
Positions are the opposite: the newest one lives in memory, older ones stream to a short history, and watching customers get pushed updates. Dispatch collects due orders every few seconds, asks who is near, estimates minutes, matches, and offers.
- Store the order before you touch the money.
- A courier and an order are joined by one conditional write.
- Aim for arrival when the food is ready, not for the nearest person now.
- The newest position of all couriers is 35 MB. Keep it in memory; stream the rest.
- Cooking and the courier's trip to the kitchen overlap, so take the larger, not the sum.
- A city is a natural boundary: run each market on its own.