Skip to main content

Classic design · Senior

Food delivery and fast local delivery (iFood/DoorDash/Gopuff)

Classic interview design. Key points: geospatial indexing.

16 min read · Content reviewed on October 23, 2026

Short answer

Classic interview design. Key points: geospatial indexing. Food delivery and fast local delivery look like a single problem, but they hide two questions. The first is about the catalog: which items can be delivered to that location right now. The second is about logistics: after the order, which courier takes it and when should they leave.

01 · CONTEXT AND REQUIREMENTS

Two questions in one: what can I deliver here, and who takes it

Food delivery and fast local delivery look like a single problem, but they hide two questions. The first is about the catalog: which items can be delivered to that location right now. The second is about logistics: after the order, which courier takes it and when should they leave. This case uses an interview-prep source, about a convenience company, for the first question, and an iFood publication for the second.

The convenience source describes fast delivery from 500+ micro-distribution centers. The core requirement is to query the availability of items deliverable within one hour, by location, summing the stock of nearby centers. The query must be fast, under one hundred milliseconds, and the order must be strongly consistent: two customers cannot buy the same physical product. The source itself assumes orders on the order of tens of millions per day.

The source leaves courier routing out of scope. That is why the second half of the case looks at the iFood publication, which describes how the order, the courier, and kitchen time enter the dispatch decision.

02 · AVAILABILITY

Which centers reach the customer in time

  1. The app sends the customer's location to the availability service, along with the items they are looking for.

    Architecture diagram: Local delivery: availability query
    CLCustomer app
    CPAvailability servicereceives the query
    CPNearby-centers service
    CPTravel-time service
    CHAvailability cache
    DBStock replicas
    DBLeader database
  2. The availability service asks the nearby-centers service which centers reach the customer; it filters candidates and queries the external travel-time service.

    Architecture diagram: Local delivery: availability query
    CLCustomer app
    CPAvailability service
    CPNearby-centers servicefilters candidates
    CPTravel-time serviceestimates the time
    CHAvailability cache
    DBStock replicas
    DBLeader database
  3. With the centers in hand, the service looks at the availability cache first.

    Architecture diagram: Local delivery: availability query
    CLCustomer app
    CPAvailability service
    CPNearby-centers service
    CPTravel-time service
    CHAvailability cachetries to answer
    DBStock replicas
    DBLeader database
  4. With no answer in the cache, the query falls to the stock replicas, which sum the stock of the centers; the result goes back to the cache.

    Architecture diagram: Local delivery: availability query
    CLCustomer app
    CPAvailability service
    CPNearby-centers service
    CPTravel-time service
    CHAvailability cachestores the result
    DBStock replicasreads the stock
    DBLeader database
  5. The leader database is reserved for order writes; availability reads go to the replicas.

    Architecture diagram: Local delivery: availability query
    CLCustomer app
    CPAvailability service
    CPNearby-centers service
    CPTravel-time service
    CHAvailability cache
    DBStock replicas
    DBLeader databasewrites only

Measuring only straight-line distance is misleading: a center can be close in distance and far in travel time, because of a river or a border, and the simple calculation also ignores traffic and road conditions. On the other hand, asking the external service for the travel time of every center generates too many queries, since most would never arrive in time.

AbordagemWhat it doesLimite
Simple distanceCompares straight-line distance against a limitIgnores traffic and road conditions
Travel time for all centersAsks the external service for the time of each centerToo many queries, because most would never arrive in time
Radius, then travel timeNarrows the candidates by a radius and only then calls the travel-time serviceDepends on an external service for the final estimate

03 · READ SCALE

Many queries, few purchases

The source starts from the volume of orders per day to estimate about 20 thousand availability queries per second. For this load, it points to cache aggressive with a short TTL. The trade-off is that the order service must expire the affected entries when it writes to the stock.

The second way out is to combine particionamento and read replicas. The source groups the centers by region, using the first digits of the ZIP code, so that queries land on few partitions. Availability reads can go to the replicas because they tolerate slight inconsistency; order transactions go to the leader.

04 · ORDER AND CONSISTENCY

Not selling the same item twice

  1. The app sends the order with several items to the order service.

    Architecture diagram: Local delivery: order in a single transaction
    CLCustomer app
    CPOrder servicereceives the order
    DBLeader database
    DBStock replicas
    CHAvailability cache
  2. The service opens a single transaction on the leader database: it checks the stock, records the order, and updates the stock, all together.

    Architecture diagram: Local delivery: order in a single transaction
    CLCustomer app
    CPOrder service
    DBLeader databasesingle transaction
    DBStock replicas
    CHAvailability cache
  3. If any item is no longer available, the whole order fails.

    Architecture diagram: Local delivery: order in a single transaction
    CLCustomer app
    CPOrder service
    DBLeader databasewhole order fails
    DBStock replicas
    CHAvailability cache
  4. After writing to the stock, the order service expires the cache entries that became stale.

    Architecture diagram: Local delivery: order in a single transaction
    CLCustomer app
    CPOrder service
    DBLeader database
    DBStock replicas
    CHAvailability cacheentries to expire
  5. Availability queries continue to be served by the read replicas.

    Architecture diagram: Local delivery: order in a single transaction
    CLCustomer app
    CPOrder service
    DBLeader database
    DBStock replicasserves the reads
    CHAvailability cache

To avoid selling the same stock to two users, some form of lock is needed. With two databases, one for orders and another for stock, the source recalls the failure modes: the service crashing between creating the order and decrementing the stock, and two orders with overlapping stock. As an alternative, it describes a single transaction in one database, which records the order and updates the stock.

CriterionTwo databases with a lockOne transaction in the same database
StrengthAllows using the best storage for each useIf two users request the same item at the same time, one of them is rejected
Weak pointA crash between creating the order and decrementing the stock is a failure mode to handleCouples the scale of stock and orders

05 · COURIER DISPATCH

Nearest is not enough

  1. The customer places the order and the order service passes the information to the restaurant.

    Architecture diagram: Food delivery: courier dispatch
    CLCustomer app
    CPOrder service
    CLRestaurant order managerreceives the order
    CPPrediction models
    CLCourier app
    QEvent stream
    CPDispatch optimizer
    NWLive monitoring
  2. The restaurant has about 8 minutes to confirm; without confirmation, the order is canceled automatically.

    Architecture diagram: Food delivery: courier dispatch
    CLCustomer app
    CPOrder service
    CLRestaurant order manageraccepts or expires
    CPPrediction models
    CLCourier app
    QEvent stream
    CPDispatch optimizer
    NWLive monitoring
  3. Prediction models report the kitchen time, which helps decide when to send the courier to the restaurant.

    Architecture diagram: Food delivery: courier dispatch
    CLCustomer app
    CPOrder service
    CLRestaurant order manager
    CPPrediction modelskitchen time
    CLCourier app
    QEvent stream
    CPDispatch optimizer
    NWLive monitoring
  4. The courier app sends a constant stream of data; dispatch needs to know the fleet, the positions, and who can pick up an order.

    Architecture diagram: Food delivery: courier dispatch
    CLCustomer app
    CPOrder service
    CLRestaurant order manager
    CPPrediction models
    CLCourier appposition and battery
    QEvent stream
    CPDispatch optimizersees the fleet
    NWLive monitoring
  5. The optimizer tests route hypotheses between orders and couriers, seeking to minimize delays; it batches orders only if none of them is delayed.

    Architecture diagram: Food delivery: courier dispatch
    CLCustomer app
    CPOrder service
    CLRestaurant order manager
    CPPrediction models
    CLCourier app
    QEvent stream
    CPDispatch optimizertests routes
    NWLive monitoring
  6. Monitoring tracks orders and delays live; a delayed order triggers an automatic incident.

    Architecture diagram: Food delivery: courier dispatch
    CLCustomer app
    CPOrder service
    CLRestaurant order manager
    CPPrediction models
    CLCourier app
    QEvent stream
    CPDispatch optimizer
    NWLive monitoringtracks delays

The decision is made minute by minute, at a scale far larger than that of a single courier. The goal is to find the best courier for each order, so that they arrive at the restaurant on time and then at the customer. Orders arise all the time, spread across the city.

CriterionWhat the source describes
Proximity to demandCouriers closer to areas of intense demand are prioritized to shorten the trip to pickup
Battery and GPSVery low battery can take the courier off the list, and a good practice is to keep at least a minimum charge and a calibrated GPS
VehicleBulky purchases favor a car, and long routes with items that fit in the bag favor a motorbike
AgrupamentoOrders are batched only if none of them is delayed relative to what was promised

06 · SYNTHESIS

Different guarantees for different paths

Availability, order, and dispatch call for different guarantees, and the design improves when each path gets its own. The availability read can use cache and replicas. The order requires strong consistency and, in the sources, goes to a single transaction. Dispatch works with information that changes all the time and with promised-deadline rules; in the didactic design, orders and positions reach it through an event stream.

Frequently asked questions

What is Food delivery and fast local delivery (iFood/DoorDash/Gopuff)?

Classic interview design. Key points: geospatial indexing.

What does the Food delivery and fast local delivery (iFood/DoorDash/Gopuff) design cover?

It is organized in these sections: Two questions in one: what can I deliver here, and who takes it, Which centers reach the customer in time, Many queries, few purchases, Not selling the same item twice, Nearest is not enough, and Different guarantees for different paths.

How long is Food delivery and fast local delivery (iFood/DoorDash/Gopuff) and what level is it?

It takes about 16 minutes to read and is rated Senior level.

Now design it yourself

Run this case as an interview in the System Design school: you make the decisions, the tutor challenges them and you see how your design scores.