Design a food delivery system (object-oriented)
I was asked this
No reports yet. Sign in to say where you were asked it.
An object-oriented design interview question asked at Amazon. It tests object-oriented design.
Design the object model for a food delivery app: restaurants and their menus, customers placing orders, couriers delivering them, and the states an order moves through. Include assigning a courier and cancelling an order. This is an object-oriented design round, so focus on classes, responsibilities and the order lifecycle, not on scaling.
Requirements
- Functional: customers browse restaurants and menus; build a cart from one restaurant; place an order and pay; the restaurant accepts or rejects it and marks it ready; the system assigns an available courier near the restaurant; the courier picks it up and delivers it; customers and restaurants see the status at each step; an order can be cancelled under rules that depend on its state (free before the restaurant accepts, partial refund after, not after pickup).
- Menu items can be unavailable; prices are fixed at the time of ordering.
- Non-functional: one courier is never assigned to two orders at once unless batching is allowed; the order's state changes only through allowed transitions.
Clarifying questions
- Can a cart contain items from several restaurants?
- How is a courier chosen: nearest, longest idle, or by an external dispatcher?
- Can a courier carry several orders at once?
- Who can cancel (customer, restaurant, courier, support), and what refund applies in each state?
- Are ratings, tips and promotions in scope?
What a strong answer covers
- Core classes:
Customer,Restaurant(menu, opening hours, accepting orders),MenuandMenuItem(price, availability),Cart,Order(items with the prices at order time, totals, status, history),Courier(location, status),Payment, aDispatchServicethat assigns couriers, andNotificationService. - The order lifecycle as an explicit state machine: placed, accepted, preparing, ready, picked up, delivered, plus cancelled and rejected, with the allowed transitions and who may trigger each.
- Courier assignment behind a strategy interface (nearest available first), and marking the courier busy atomically when assigned.
- Cancellation and refunds as rules on the state machine, with a
RefundPolicythat can change. - Observers for status updates to the customer, restaurant and courier apps.
- Money in integer cents and order lines that copy the price at checkout.
Follow-ups
- Add batching: one courier picks up two orders from nearby restaurants.
- The assigned courier does not show up. How does the model reassign?
- Add promotions and coupons without touching the
Orderclass much.
Where it's asked
What it tests
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. New accounts get 5 credits: each one unlocks a question for good.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
