Full answer
Requirements
Functional:
- Customers browse restaurants near them, see menus and delivery time, place and pay for an order.
- Restaurants accept the order and mark it ready.
- A delivery partner is assigned, picks up and delivers; the customer tracks the order live.
Non-functional:
- Browsing is fast and can be slightly stale (a menu price a minute old is fine).
- Orders and payments are never lost or duplicated.
- Dispatch decisions within about 30 seconds of the restaurant accepting.
Capacity estimates
Assumptions: 10M orders per day, peak factor 3 at meal times, 300,000 delivery partners online at peak sending a location every 5 seconds, 20 browse requests per order.
- Orders: 10M / 86,400 = about 116 per second on average, about 350 per second at peak.
- Browse and search: 20 x 350 = about 7,000 requests per second at peak, mostly cacheable.
- Partner locations: 300,000 / 5 = 60,000 updates per second.
The order rate is modest; the location stream and the browse traffic need the scaling work.
API
GET /v1/restaurants?lat=..&lng=..&q=biryani&cursor=.. -> list with ETA and rating
GET /v1/restaurants/{id}/menu
POST /v1/orders (Idempotency-Key header) {"restaurant_id", "items": [...], "address_id", "payment_method"}
GET /v1/orders/{id} -> status, partner location, ETA
POST /v1/partner/orders/{id}/pickup | /deliver
Data model
restaurantsandmenusin a relational store, copied into a search index (geo field, cuisine, open hours) for discovery.orders: order_id, customer_id, restaurant_id, items, amount, status, partner_id, timestamps. Partitioned by order_id; secondary indexes by customer and restaurant.order_events: append-only history of each status change, used for support and analytics.- Partner locations: in-memory geo index, as in ride-hailing.
High-level design
flowchart LR
C[Customer app] --> API[API gateway]
API --> S[Search service]
S --> IDX[(Search index with geo)]
API --> O[Order service]
O --> DB[(Orders DB)]
O --> PAY[Payment service]
O -- "order events" --> BUS[(Event bus)]
BUS --> DIS[Dispatch service]
BUS --> N[Notifications]
P[Partner app] --> LOC[Location service] --> GEO[(Partner geo index)]
DIS --> GEO
BUS --> REST[Restaurant tablet app]Order state machine
CREATED -> PAID -> ACCEPTED_BY_RESTAURANT -> PARTNER_ASSIGNED -> PICKED_UP -> DELIVERED, with CANCELLED and REFUNDED branches. Each transition is a conditional update ("set ACCEPTED only if status is PAID") and emits an event. The idempotency key on order creation stops a double tap from creating two orders.
Dispatch
The dispatcher predicts when food will be ready (from the restaurant's history and current load) and the travel time of candidate partners. It assigns a partner whose arrival matches the ready time, so partners do not wait at the counter and food does not go cold. Every few seconds it solves a small batch assignment per zone (orders and partners in that zone), which gives better results than greedy one-by-one matching and allows batching two orders from the same restaurant.
Bottlenecks and trade-offs
- Meal-time peaks. Autoscale stateless services ahead of known peaks; the search cache absorbs most browse traffic.
- Restaurant tablets may be offline. If an order is not accepted within a few minutes, call the restaurant or cancel and refund automatically.
- Batch dispatch versus instant dispatch. Batching every few seconds gives better assignments at the cost of a small delay.
- Search freshness. Restaurant open or closed status must update quickly (seconds), while ratings can refresh hourly; use separate update paths.
- Payment and order consistency uses the outbox pattern: the order row and an outgoing event are written in one local transaction, so no payment succeeds without an order record.
By level
Fresher: Describe the customer, restaurant and partner flows and the main tables. A fresher should explain the order status steps and why the menu can be cached.
Mid: Do the peak math, design the state machine with conditional updates and idempotency, and describe event-driven dispatch. Mention search for discovery with geo filters.
Senior: Discuss batch assignment, ready-time prediction, offline restaurants, freshness of different data, and the outbox for payment consistency. Expect capacity planning for meal peaks.
Key points
- Three subsystems: discovery, ordering, dispatch
- Orders are a durable state machine with conditional transitions
- Idempotency key on order creation
- Dispatch targets food-ready time, not earliest arrival
- Plan for meal-time peaks about 3 times the average
Common mistakes
- Treating the order rate as the scaling problem while ignoring browse and location traffic
- Assigning the nearest partner immediately so they wait at the restaurant
- Updating order status without conditional checks
- Coupling payment success and order creation without an outbox or saga
Follow-ups
- How would you batch two orders from the same restaurant?
- How do you estimate food preparation time?
- What happens if the restaurant never accepts?
Tips
- Draw the order state machine
- Explain why dispatch waits for the ready time
- Show the event bus between services
Evaluation rubric
- Clear split into discovery, ordering and dispatch
- Correct capacity math with peaks
- Order state machine with idempotency
- Thoughtful dispatch design and trade-offs