Food Delivery (DoorDash / Uber Eats)
Requirements: browse restaurants near the customer with menus and ETAs; place and pay for orders; restaurants accept and prepare; dispatch assigns couriers; live courier tracking; order status updates.
browse: client -> search svc (geo index of restaurants + filters) -> menu cache/CDN -> ETA estimates
order: client -> order svc (state machine: placed -> accepted -> preparing -> picked up -> delivered)
-> payment (authorize; capture on delivery) -> restaurant tablet notification
dispatch: every few seconds per region: open orders × available couriers -> optimizer -> offers to couriers
couriers: location every ~5 s -> location svc (in-memory geo index by region) -> tracking via WebSocket/SSE
Deep dives
- Dispatch is an assignment problem: batch orders and couriers per region every few seconds and solve for minimum total delivery time (min-cost matching / heuristics), considering food prep time (don't make couriers wait), order batching (two orders, one courier) and fairness.
- ETA combines prep time prediction, courier travel time and traffic (an ML model per stage).
- Order state machine with idempotent transitions; restaurants and couriers confirm steps; timeouts trigger reassignment.
- Peak hours: surge pricing / delivery fees by region to balance supply and demand; precompute restaurant availability.
- Location pipeline, geo index and real-time tracking mirror the Ride Sharing design.