← Questions

Design a food delivery system (object-oriented)

0
AmazonOO design

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), Menu and MenuItem (price, availability), Cart, Order (items with the prices at order time, totals, status, history), Courier (location, status), Payment, a DispatchService that assigns couriers, and NotificationService.
  • 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 RefundPolicy that 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 Order class much.

Where it's asked

What it tests

object-oriented design

Your canvas
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing