THN Interview Prep

Design Restaurant Ordering (LLD)

1. Requirements

  • Functional

    • Menu with categories, items, modifiers, and optional combos.
    • Orders aggregate line items; kitchen receives tickets by station (grill, cold).
    • Table or counter service flows; bill splitting optional extension.
  • Non-Functional

    • Order state machine consistent when POS and kitchen display both update.
    • Extensible pricing for happy hour and coupons without dirty flags everywhere.
  • Assumptions / Out of Scope

    • Delivery marketplace routing omitted; dine-in and takeaway only.

2. Core Entities

EntityResponsibilityKey Attributes
MenuCatalog rootcategories
CategoryMenu sectionname, items
MenuItemSellable dishname, basePrice, station
ModifierAdd-onname, priceDelta
OrderCustomer ticketlines, status, table
OrderLineQuantity lineitem, modifiers, note
KitchenTicketFulfillment viewstation, lines subset
PricingPolicyAdjust totalsrules

3. Class Diagram

Loading diagram…

4. State / Sequence Diagram (where relevant)

Loading diagram…

5. Design Patterns Applied

6. Implementation

Go

package restaurant

type MenuItem struct {
    Identifier string
    Name       string
    BasePrice  int
    Station    string
}

type OrderLine struct {
    Item       MenuItem
    Quantity   int
    Modifiers  []string
}

type Order struct {
    Identifier string
    Lines      []OrderLine
    Status     string
}

type OrderService struct {
    Menu *Menu
}

func (service *OrderService) SubmitOrder(order Order) error { /* validate + emit tickets */ }

JavaScript

class Order {
  constructor({ identifier, tableId }) {
    this.identifier = identifier;
    this.tableId = tableId;
    this.lines = [];
    this.status = 'draft';
  }
  addLine({ menuItem, quantity, modifiers }) { /* ... */ }
}

class KitchenBoard {
  constructor({ stations }) {
    this.stations = stations;
  }
  receiveTickets(order) { /* partition lines by station */ }
}

7. Concurrency / Thread Safety

  • Collisions: Kitchen marks ready while cashier applies void line.
  • Granularity: Optimistic locking on Order version; event log for kitchen screen replay.
  • Go: Mutex per order id during payment capture.

8. Extensibility & Followups

  • Inventory decrement hooks when order submitted per ingredient BOM.
  • Reservation system linking table turn rotation.
  • Edge cases: 86 item mid-order, allergy overrides, split checks across parties.

Last updated on

Spotted something unclear or wrong on this page?

On this page