Design a Food Delivery Order Tracking System
Track each food-delivery order through validated, retry-safe status transitions, show the courier's live position, push status notifications, and deliver new orders to restaurants.
Problem statement
For this exercise, assume a food-delivery platform begins tracking an order after checkout has accepted it. Restaurants and couriers report progress while customers and support agents read the current state and timeline.
Use the lifecycle PLACED, RESTAURANT_ACCEPTED, PREPARING, READY_FOR_PICKUP, PICKED_UP, EN_ROUTE, DELIVERED, and CANCELLED, with only documented legal transitions. Each status command carries an order ID, stable command ID, actor identity and role, expected order version, proposed status, and observed time.
A retry must not create another transition, conflicting reuse of a command ID must fail, and concurrent or out-of-order updates must not move an order backward.
Assume 10 million orders per day, 1 million simultaneously active orders, bursts of 50,000 status commands per second, and 500,000 concurrent tracking subscribers.
Healthy status commands should complete within 300 milliseconds at p95, and 99 percent of committed transitions should reach connected clients within five seconds. Keep active timelines queryable for 30 days and archive immutable transition history for one year.
Acknowledged transitions must survive a single-zone failure.
For this exercise, also assume three more capabilities. Courier location: from PICKED_UP until DELIVERED or CANCELLED, the assigned courier's app sends its position about every four seconds; the order's customer sees it on a map within about five seconds, and a position older than 30 seconds is shown as stale.
Positions are not lifecycle transitions: they never go through the order transaction, command receipt or outbox, and are kept for only 24 hours.
Customer notifications: the customer gets a push notification when the order becomes RESTAURANT_ACCEPTED, PICKED_UP, DELIVERED or CANCELLED, even when the app is closed; a push may be late or duplicated and never replaces the authoritative read.
Restaurant order intake: when an order becomes PLACED, the restaurant's device receives its details (items, quantities and special instructions) and accepts it through the existing RESTAURANT_ACCEPTED command; an order still PLACED five minutes after it was placed is flagged to operations.
Exclude restaurant discovery, menu ranking, pricing, payment processing, courier dispatch and assignment, ETA prediction, courier route optimization, location history replay, SMS or email notifications, and proof-of-delivery media.
What to build
- Authorized restaurant, courier, and operations actors can append legal, retry-safe order-status transitions.
- Customers and support agents can read the authoritative current state and an ordered status timeline.
- Connected clients receive committed status changes with resumable delivery and explicit freshness.
- Operators can replay durable transition history, rebuild projections, and detect stuck or divergent orders.
- While an order is PICKED_UP or EN_ROUTE, its customer can see the assigned courier's latest position, with stale positions clearly marked.
- The customer receives a push notification for each notifying status change, even when the app is closed.
- The restaurant's device receives each new order's details when it is placed, and orders not accepted in time are flagged.
At scale
- For this exercise, assume 10 million orders per day, 1 million simultaneously active orders, bursts of 50,000 status commands per second, and 500,000 concurrent tracking subscribers.
- For this exercise, target 300 milliseconds p95 for healthy status commands and deliver 99 percent of committed transitions to connected clients within five seconds.
- For this exercise, retain active timelines for 30 days, archive immutable transition history for one year, and preserve acknowledged transitions through a single-zone failure.
- For this exercise, clients and producers may retry, reconnect, and send delayed observations, but one order's committed lifecycle must remain monotonic and auditable.
- For this exercise, assume about 300,000 couriers are on active deliveries at peak, sending about 75,000 position updates per second, separate from the 50,000-per-second status-command burst; each position goes only to that order's customer.