# Food delivery - three parties and a promise

> How three parties who can each say no move one order through a shared state machine to a promised ETA. The ETA is shown before the restaurant has accepted and…

Source: https://tierslate.com/templates/food-delivery

Marketplaces & booking · System design · core · 8 step walkthrough · 5 tables

How three parties who can each say no move one order through a shared state machine to a promised ETA.

**Own this board: 400 credits.** The first act plays on the page. Owned once with credits, never a subscription.

## What this board gets wrong on purpose

The tension: The ETA is shown before the restaurant has accepted and before any courier exists, so it is a promise made on behalf of two parties who have not agreed to it - built on a prep-time estimate the restaurant has every incentive to understate and no obligation to meet. Once it is displayed it is a commitment the business is refunded against, so it is stored and never recomputed, which means the customer is shown a number the system already knows is wrong for the fifteen minutes before anybody tells them. The courier side has the matching hole: dispatch optimises each offer greedily, one order at a time, so on a Friday at 19:30 the couriers nearest the busiest restaurants are consumed by whichever orders happened to be placed first, and the orders placed ninety seconds later - to the same restaurant - have no supply left within eight minutes. Nothing on this board is doing global assignment, and the reassignment loop sweetens the fee rather than fixing the allocation.

## Practise this as an interview

Take Food delivery - three parties and a promise as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.

## Start here

### Why this design

Food delivery is the classic three-sided marketplace question: a customer, a restaurant and a courier, none of whom work for you, all moving one order. Interviewers use it to see whether you can keep a shared state machine correct while three independent parties act on it at once, design dispatch for supply that is free to say no, and notice that the dominant load is GPS pings rather than orders. DoorDash, Uber Eats and Deliveroo spend most of their engineering on exactly these seams.

### What you will learn

- Why an order is a sequence of**compare-and-set transitions**, and how that settles a cancel racing an accept.
- Why dispatch is an**offer with a 30 s expiry**and a re-offer loop, not a work queue - and where greedy one-at-a-time assignment breaks at the Friday dinner peak.
- Why courier location,**50,000 writes/s**and 150x the order rate, is held in memory and never written to the transactional database.
- Why the ETA is computed once and**stored as a promise**, and what that costs when it is wrong.
- Why**authorise at placement, capture at handoff**is the payment shape for an order that can fail three ways.
- How sharding by**city**makes failover, deploys and blast radius one marketplace at a time.

### How to read this board

1. Press play once: the walkthrough follows one order from checkout to handoff.
2. **CUSTOMER**(top left): placing the order, the payment hold and the ETA promise.
3. **THE ORDER**(right): the one state machine all three parties write into.
4. **RESTAURANT**, then**COURIER**and**WHEN NOBODY ACCEPTS**: the two parties who can say no, and the re-offer loop.
5. **DATA MODEL**: the tables Generate SQL emits - transitions are append-only, offers are not assignments.
6. Then pages 1 to 6 in order: requirements, capacity, storage, availability, how it works, deployment.

## 1 · Requirements

Three parties, none of whom work for us, and an order that moves between them. Every requirement below is shaped by the fact that two of the three can say no.

### Ask these before designing

- **Who owns the courier relationship?**Employed riders can be assigned. Self-employed riders can only be offered, and the difference rewrites dispatch entirely.
- **Is the ETA a promise or an estimate?**If refunds are issued against it, it is a promise, and it must be stored rather than recomputed.
- **Can an order be cancelled after the restaurant has started cooking?**This is a commercial question - somebody pays for the food - and it decides where CANCELLED sits in the state machine.
- **Batching: can one courier carry two orders?**It roughly halves delivery cost and roughly doubles the complexity of both assignment and the ETA.
- **How fresh must courier location be?**4 seconds is a smooth map and 50,000 writes/s. 15 seconds is a jerky map and 13,000 writes/s. This single number is the largest line in the infrastructure bill.
- **What happens when no courier accepts?**Sweeten and re-offer, widen the radius, or cancel and refund. All three are real answers and they are product decisions.

### Functional

- Place an order, authorise payment, route it to a restaurant.
- Restaurant accepts or rejects, and reports a prep time.
- Offer the delivery to couriers and let them accept or decline; re-offer on timeout.
- Track the order through a legal sequence of states, driven by three different actors.
- Show live courier position and an ETA to the customer.
- Capture payment at handoff, refund on failure.

### Non-functional

- **A transition must be legal from the state the order is actually in.**Two parties will act on the same order in the same second; exactly one may win.
- **Order placement p99 under 1.2 s.**
- **Offer round trip under 30 s**- a courier staring at a phone for longer declines.
- **Ordering 99.95%**, tracking**99.99%**and degrading to text rather than a map.
- **Demand is two spikes a day**, not a curve: 40% of the day’s orders land between 19:00 and 20:30.
- Location writes are lossy by design. A dropped ping is a slightly jerkier map, never a wrong order.

### Explicitly out of scope

Menu management, pricing and promotions, courier payouts and tax, restaurant onboarding, fraud, customer support tooling.

## The rest of this board

This page publishes the question. The answer - 5 more written pages, an 8-step narrated walkthrough and a 5-table schema - is the board itself, and it opens in Tierslate.

- 5 written pages
- 8 walkthrough steps
- 5 tables (38 columns)

5 pages behind this one:

- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan

## Related system design templates

- [Checkout system design](https://tierslate.com/templates/amazon-checkout) - Why stock is held before the card is charged, and what must unwind when the charge fails.
- [Auction bidding system design](https://tierslate.com/templates/auction-bidding) - Why bids are ordered by a sequence under one lock rather than a clock, and how soft close moves the end.
- [Hotel booking system design](https://tierslate.com/templates/hotel-booking) - Why a stay is sold night by night or not at all, and why selling the last room twice is sometimes deliberate.
- [Seat sales system design](https://tierslate.com/templates/ticketmaster-seats) - Why fifty thousand buyers for one hundred seats is a contention problem that sharding cannot solve.
- [Coupon codes system design](https://tierslate.com/templates/coupon-codes) - Why a single-use code is a race between every checkout holding it, and how a conditional write settles it.
- [Rental search system design](https://tierslate.com/templates/rental-search) - How a stay search filters by place, dates and price at once, and why the availability calendar is the bottleneck.
- [Job board system design](https://tierslate.com/templates/job-board) - How listings are indexed for search and applications are routed, and why expired jobs must disappear fast.

All 100 system design templates: https://tierslate.com/templates (Markdown: https://tierslate.com/templates.md)
