Design a Food Delivery App (Low-Level Design)
Low-level design of a food delivery app (Swiggy/Zomato style): Customer, Restaurant, Menu, Order and DeliveryPartner, with an order-lifecycle State machine, Strategy partner-matching and pricing, and Observer status updates.
🟠Low-Level Design · Case Study · Senior
"Design a food-delivery app" (Swiggy / Zomato / DoorDash, the LLD flavour) is a rich end-to-end domain: customers, restaurants, menus, orders, and delivery partners, tied together by an order lifecycle that's a textbook state machine. It brings together several patterns you've seen across this series. Let's design the object model.
Step 1 — Requirements
- Functional: browse restaurants & menus; place an order (cart of items); restaurant accepts & prepares; assign a nearby delivery partner; track order status; pay; rate.
- Non-functional: a clean order lifecycle, extensible pricing/discounts, decoupled notifications, and a pluggable partner-matching strategy.
Step 2 — The classes
- Customer, Restaurant (has a Menu of MenuItems), DeliveryPartner (with a location & availability).
- Cart → Order — line items, amounts, addresses, and a status.
- OrderState (interface) → Placed, Accepted, Preparing, OutForDelivery, Delivered, Cancelled.
- DeliveryAssignmentService — matches an order to a partner.
- OrderService / Payment — orchestration + a pluggable pricing strategy.
Step 3 — The order lifecycle = State pattern
🟠An order's allowed actions depend entirely on its stage — a perfect State pattern. Each state knows its valid transitions, so illegal jumps (deliver before accept) can't happen. It's the same backbone as the vending machine and ATM.
interface OrderState { OrderState next(Order o); OrderState cancel(Order o); }
class PlacedState implements OrderState {
public OrderState next(Order o){ return new AcceptedState(); } // restaurant accepts
public OrderState cancel(Order o){ return new CancelledState(); } // allowed while placed
}
class OutForDeliveryState implements OrderState {
public OrderState next(Order o){ return new DeliveredState(); }
public OrderState cancel(Order o){ throw new IllegalStateException("too late to cancel"); }
}
Step 4 — Matching a delivery partner = Strategy
🔴 Assigning a partner is a pluggable policy — a Strategy: nearest-available, lowest-load, or highest-rated. Under the hood it's a geospatial "who's close?" query (the same geo-matching idea as ride-hailing). Keeping it behind an interface means you can A/B different matching algorithms without touching the order flow.
Step 5 — The senior nuances
🔴 Where to add depth:
- Notifications = Observer: on every state change, notify customer, restaurant, and partner — reuse a notification service.
- Pricing = Strategy: base + taxes + delivery fee + surge + coupons, each a composable rule.
- Payment atomicity & idempotency: charge exactly once; on failure, don't confirm the order (echoes the payment system concerns).
- Cancellation & refunds: allowed only in certain states — the State machine enforces it cleanly.
The interview-ready walkthrough
"A Customer builds a Cart into an Order of MenuItems from a Restaurant. The order's lifecycle is a State machine — Placed → Accepted → Preparing → OutForDelivery → Delivered — so each state permits only valid actions and cancellation is state-gated. A DeliveryAssignmentService matches a partner via a pluggable Strategy (nearest / least-loaded) backed by a geo lookup. State changes fan out via Observer to notify everyone, pricing is a composable Strategy, and payment is idempotent so an order is only confirmed once charged." That ties State + Strategy + Observer into one coherent, real-world design."
What to read next
- State · Strategy · Observer — the patterns tying this together
- Design Uber — the geospatial matching at scale
- LLD Interview: How to Approach — the framework behind every case study
- ← The complete System Design guide (hub)