Online Food Delivery
Food Ordering and Delivery Platform
Design the object model of a food delivery platform: a customer orders from a restaurant, the restaurant accepts and cooks, a dispatcher hands the order to one free driver, and every party sees the order move through a fixed set of states.
Overview
Three parties take part in one order. The customer picks items from a restaurant menu and pays. The restaurant accepts or rejects the order, cooks it and marks it ready. A driver collects it and delivers it. The platform in the middle owns the order, decides which driver gets it, enforces which status changes are legal, and tells everyone when something changes.
This is a design exercise, not a description of how any real company runs. Interviewers pick it because it has a clean state machine (the order), a pluggable decision (which driver), a rule table (what a cancellation refunds), and a race (two orders must not get the same driver). A strong answer names the entities in the first minutes, draws the order states before writing code, puts the driver choice behind a strategy interface, and shows where the lock lives.
Keep money in whole cents and keep the order's status changes in one method, so a bad transition is impossible rather than merely unlikely.
Scoping the problem
The design starts with six questions. Each one matters because its answer adds or removes part of the design, and each has a usual answer.
- Delivery only, or also pickup and scheduled orders? Each adds states and skips others. Build delivery now, and say how pickup would drop the driver states.
- When is a driver assigned: when the restaurant accepts, or when the food is ready? Early assignment wastes driver time; late assignment lets the food go cold. Assign on accept, with a range limit, and discuss the trade-off.
- Who can cancel, and when? The refund rule depends on how far the kitchen has gone. The customer can cancel, up to the moment the food is ready.
- One restaurant per order? Multi-restaurant orders need several pickups per trip. Keep to one restaurant.
- Is payment in scope? Payment is its own state machine. Record the total, and treat charging as a call to another service.
- How many drivers at once? This decides whether a list scan is fine or you need a spatial index. Plan for hundreds per city in the interview, and say what changes at 100,000.
Functional requirements
- Place an order from one open restaurant: every item must exist and be available, quantities positive, total in cents
- The restaurant accepts or rejects a placed order; an accepted order is offered to one free driver in range
- Move an order through Placed, Accepted, Preparing, Ready, PickedUp and Delivered, refusing any other move
- The customer can cancel until the food is ready; the refund follows a rule table keyed by status
- An accepted order with no driver waits and is retried whenever a driver is released
- Anyone can subscribe to an order and is told about every status change
Non-functional requirements
- A driver is never assigned to two live orders: the choice runs under one lock
- The dispatch policy is swappable without touching the dispatcher or the orders
- Money is integer cents; no floats in prices, totals or refunds
- Validation happens before an order is stored, so a failed request leaves no state behind
- Every status change is recorded in the order history and pushed to subscribers from one place
Interview questions
- Should the driver be assigned when the restaurant accepts or when the food is ready?
- How do cancellation rules stay easy to change?
- Nearest-driver search scans every driver. What do you do with 100,000 drivers?
- How do the customer, restaurant and driver see status changes in real time?
- How would you persist this, and what happens when the driver app retries a request?
Sign up free to read the full topic
More Low-Level Design topics
Start free on Cariara · Coding problems · System design studio