System design interview: design a food delivery app

A food delivery app connects three parties: a customer who orders, a restaurant that cooks and a courier who carries the food. The design is mostly about the order's life as a state machine and about dispatch: choosing a courier who reaches the restaurant just as the food is ready, then showing the customer an honest arrival time while the courier moves.

By Published 8 min read

1. Clarify the requirements

This is a generic delivery marketplace of the kind run by DoorDash, Uber Eats or Deliveroo; nothing here describes their real systems. Confirm which of the three apps the interviewer wants you to focus on, because each has different hard parts.

  • Functional: browse nearby restaurants and menus; place and pay for an order; the restaurant accepts and marks it ready; a courier is assigned, picks up and delivers; the customer tracks progress on a map; ratings afterwards.
  • Non-functional: placing an order is reliable and never double charges; dispatch decisions take seconds, not minutes; tracking updates feel live (every few seconds); menus load fast; the system copes with the dinner peak.
  • Out of scope unless asked: grocery picking, restaurant onboarding, promotions engine, courier pay calculation, fraud scoring.

2. Estimate the scale

Back-of-envelope estimate for a large delivery marketplace (assumed figures)
QuantityAssumptionResult
Orders10 million a dayabout 116 a second on average; about 580 at a dinner peak of 5x
Couriers online at peak500,000each sends a location every 5 seconds: 100,000 updates a second
Restaurants1 million, about 100 menu items each100 million items; at 1 KB each about 100 GB of menu data
Tracking viewersone per active order, polling or subscribeda few hundred thousand open tracking screens at peak
Back-of-envelope estimate for a large delivery marketplace (assumed figures). Scroll sideways on a small screen.

Orders are a modest write rate for a database. The location stream is the real throughput problem, roughly 170 times the order rate at peak, and it is data you only need for a few minutes. That difference drives the split between the order store and an in-memory location service.

3. Define the API

GET  /v1/restaurants?lat=..&lng=..&open=true        -> 200 [{ id, name, etaMinutes, deliveryFee }]
GET  /v1/restaurants/{id}/menu                       -> 200 { sections, items, version }
POST /v1/orders  { restaurantId, items[], address, paymentMethodId, idempotencyKey } -> 201 { orderId, status }
POST /v1/orders/{id}/accept       (restaurant)  { prepMinutes }
POST /v1/orders/{id}/ready        (restaurant)
POST /v1/couriers/me/location     (courier)     { lat, lng, heading, ts }   every few seconds
POST /v1/offers/{id}/respond      (courier)     { accept: true }
WS   /v1/orders/{id}/track        (customer)    -> status changes, courier position, ETA
Customer, restaurant and courier apps each get a small surface. Pushes ride a persistent connection.

4. Sketch the data model

Durable order data versus short-lived location data
DataStoreNotes
Order and order itemsRelational database, sharded by order ID or by cityStatus, timestamps for each transition, totals, payment reference
Order eventsAppend-only logEvery transition with who made it; feeds analytics, ETA training and support tools
MenusDocument store plus a cache and CDN for imagesVersioned per restaurant; the order stores the item prices it was placed with
Courier stateIn-memory store (for example Redis) with a geo gridPosition, availability, current orders; expires if no update arrives for a while
OffersIn-memory with a short TTLWhich courier was offered which order, and until when
Durable order data versus short-lived location data. Scroll sideways on a small screen.

5. The order as a state machine

PLACED -> ACCEPTED -> PREPARING -> READY -> PICKED_UP -> DELIVERED
PLACED -> REJECTED            (restaurant declines or times out)
PLACED | ACCEPTED -> CANCELLED (customer, within the allowed window)
courier assignment runs alongside: UNASSIGNED -> OFFERED -> ASSIGNED (-> UNASSIGNED if declined or late)
Allowed transitions. Anything else is rejected, which protects against late or duplicate messages.
  • One owner. The order service is the only writer of order status. It applies a transition with a conditional update ("set READY where status is PREPARING"), so a repeated tap or a late message cannot move the order backwards.
  • Everything else listens. Each change is published as an event; dispatch, notifications, the tracking feed and payments subscribe. Publish through an outbox table so a committed change is never lost between the database and the queue.
  • Timeouts are transitions too. A restaurant that does not accept within a few minutes moves the order to REJECTED, which triggers a refund of the authorization and a message to the customer.

6. Dispatch: the right courier at the right time

The naive answer is "assign the nearest free courier as soon as the order is placed". That courier then waits at the restaurant for twenty minutes while food is cooked. A better dispatcher plans backwards from the time the food will be ready.

  1. Predict readinessUse the restaurant's stated prep time, corrected by its history at this hour, to estimate when the food will be ready.
  2. Find candidatesQuery the geo grid for available couriers within a radius of the restaurant, plus couriers finishing a nearby drop-off soon.
  3. ScoreFor each candidate, estimate travel time to the restaurant and compare it to readiness. Prefer small waits on both sides; consider adding the order to a courier already heading to that restaurant (batching).
  4. Decide in roundsRun matching every few seconds per city zone over all pending orders together, rather than greedily one order at a time, so one order does not grab the courier another order needed more.
  5. OfferSend the offer with a short expiry. If declined or ignored, return the order to the pool for the next round.
import math
from collections import defaultdict

CELL = 0.01  # degrees, about 1.1 km of latitude

def cell(lat, lng):
    return (math.floor(lat / CELL), math.floor(lng / CELL))

def km(a, b):  # haversine distance
    la1, lo1, la2, lo2 = map(math.radians, (*a, *b))
    h = math.sin((la2 - la1) / 2) ** 2 + math.cos(la1) * math.cos(la2) * math.sin((lo2 - lo1) / 2) ** 2
    return 2 * 6371 * math.asin(math.sqrt(h))

class CourierGrid:
    def __init__(self):
        self.cells = defaultdict(dict)   # cell -> {courier_id: (lat, lng)}
        self.where = {}                  # courier_id -> cell

    def update(self, cid, lat, lng):
        new = cell(lat, lng)
        old = self.where.get(cid)
        if old is not None and old != new:
            del self.cells[old][cid]
        self.cells[new][cid] = (lat, lng)
        self.where[cid] = new

    def nearby(self, lat, lng, radius_km):
        ci, cj = cell(lat, lng)
        di = math.ceil(radius_km / 111.0 / CELL)            # rows to scan
        # columns shrink toward the poles; use the widest latitude in range
        worst = min(abs(lat) + di * CELL, 89.0)
        dj = math.ceil(radius_km / (111.0 * math.cos(math.radians(worst))) / CELL)
        out = []
        for i in range(ci - di, ci + di + 1):
            for j in range(cj - dj, cj + dj + 1):
                for cid, pos in self.cells.get((i, j), {}).items():
                    d = km((lat, lng), pos)
                    if d <= radius_km:
                        out.append((d, cid))
        return [cid for d, cid in sorted(out)]
In-memory courier grid: move couriers between cells and find those within a radius. Checked against a brute-force search.

The detail interviewers like: longitude cells get narrower away from the equator, so a fixed three-by-three scan silently misses couriers at high latitudes. The code widens the column scan using the cosine of the latitude. In production you might use Redis geo commands or a hierarchical cell system such as H3 instead; the idea is the same. The Uber walk-through goes deeper on matching riders and drivers with this kind of index.

7. The architecture

  1. Apps
    • Customer app
    • Restaurant tablet
    • Courier app
  2. Edge
    • API gateway
    • WebSocket servers
  3. Core
    • Order service
    • Menu service
    • Dispatch
    • Location service
    • ETA service
  4. Data
    • Orders DB with outbox
    • Menu store and cache
    • In-memory geo store
  5. Async
    • Event log
    • Payments
    • Notifications
    • Analytics and ETA training
Order, dispatch and tracking paths for a food delivery app. Customer, restaurant and courier apps connect through an API gateway and a pool of WebSocket servers. The order service owns order state in a sharded relational database and publishes every transition through an outbox to an event log. The dispatch service reads pending orders and courier positions from an in-memory geo store, runs matching rounds per zone and sends offers. Courier location updates go to a location service that writes the geo store and forwards positions to tracking subscribers. Payment, notification and ETA services consume the event log.

Customer notifications ("your courier is nearby") are fanned out by a separate service with retries and user preferences, the same shape as the notification system walk-through.

8. What breaks, and what you do about it

Failure modes worth naming
FailureEffectMitigation
Restaurant tablet offlineOrders sit in PLACED, customers waitDetect missed heartbeats, pause the restaurant in search, fall back to a phone call or auto-reject after a timeout
Courier phone loses signalMap freezes, dispatch sees a stale positionMark positions stale after a short time; the courier app queues status taps and sends them on reconnect
Dinner peak with too few couriersLong waits and cold foodWiden radius, batch more orders per courier, show longer ETAs honestly, raise courier incentives in that zone
Duplicate order submitTwo orders and two chargesIdempotency key on order creation; the second request returns the first order
Geo store node lostDispatch blind in some zones for secondsPositions repopulate within one update interval; run replicas and accept the short gap
Failure modes worth naming. Scroll sideways on a small screen.

9. Trade-offs to discuss

  • Greedy or batched matching. Greedy is simple and fast; matching rounds over many orders give better overall wait times at the cost of a few seconds of delay.
  • Early or late assignment. Assigning early gives the customer a named courier sooner; assigning closer to readiness wastes less courier time.
  • Polling or push for tracking. Polling every few seconds is simple and cache-friendly; a WebSocket push is smoother but needs connection management at scale.
  • Shard by city or by order ID. City shards keep dispatch local and make regional outages contained; a huge city can still outgrow one shard.
  • ETA accuracy versus optimism. A short promised time wins the order but loses trust when missed. Show a range and update it as states change.

10. How to talk through it in the interview

Fictional example

Reframing dispatch as a timing problem
Interviewer
How do you choose a courier for an order?
Candidate
I would not just take the closest free courier. The food will not be ready for maybe fifteen minutes, so I estimate readiness from the restaurant's history and look for couriers who can arrive close to that time, including ones finishing a drop-off nearby.
Interviewer
Couriers are scarce tonight. What changes?
Candidate
I would batch: give a courier two orders from the same restaurant or two on the same route, widen the search radius, and push longer ETAs to new customers so we are honest about the wait.
  • Draw the three apps first; it shows you see the marketplace, not a shopping cart.
  • Write the state machine early. Most follow-ups (cancellations, timeouts, duplicates) are answered by it.
  • Keep location data out of the order database and say why in one sentence using your estimate.

Practicing this design with Natively

Dispatch is where candidates tend to ramble, so rehearse that part aloud more than once. Set up a mock call, have the other person play a skeptical interviewer, and let Natively run alongside on your computer: it transcribes both of you, and a press of the answer shortcut gives you suggested points for the question in front of you, such as batching or readiness prediction. Ask it for a diagram of the state machine if you want something to check your board against. The transcript you keep afterwards shows how long the dispatch answer actually took.

Questions people ask

How would you design DoorDash or Uber Eats in a system design interview?

Start with the three apps (customer, restaurant, courier) and an order state machine owned by one service. Keep courier locations in an in-memory geo index, run dispatch in short rounds that match couriers to orders by expected food readiness, and push status and position updates to the customer's tracking screen.

How does a food delivery app assign a courier to an order?

A good design estimates when the food will be ready, finds available couriers near the restaurant in a geo grid, and scores them by how closely their arrival matches readiness. Matching runs every few seconds over all pending orders in a zone, and it can batch two orders onto one courier when routes line up.

Where should courier locations be stored?

In memory, in a geo index such as a grid of cells or Redis geo commands, with each position expiring if updates stop. Locations arrive every few seconds from every online courier and are only useful for minutes, so writing them to the order database would waste capacity.

When should a delivery app charge the customer's card?

Authorize the estimated total when the order is placed, then capture the final amount at delivery once substitutions, refunds and tips are known. If the restaurant rejects the order or it is cancelled in time, release the authorization instead of issuing a refund.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP