System Design Academy

Saving…

Lesson 2 of 7 in Module 50 of 45 lessons complete

Restaurant Kitchen Order Router — Part A: Design

Module 5, lesson 2Case study15 min

Definitions

Station

In plain English
A station is one area of a kitchen that prepares one kind of item, such as grill, fryer, salad or drinks.
Think of it like
It is like one desk in an office that handles one type of form.

Ticket

In plain English
A ticket is the unit of work a station receives: one item from one order.
Think of it like
It is like a single task card on a board.

The brief

In the kitchen-router domain, a busy restaurant receives orders from tablets and two delivery apps. Route each item and report whole-order readiness.

What it must do

  • Accept orders from dine-in tablets and delivery apps.
  • Route each item by category and process each station’s normal tickets in arrival order.
  • Promote orders waiting over 15 minutes; explicit rush orders also use the rush lane.
  • Mark an order ready after all items finish; notify the front screen and delivery channel.

How well it must do it

  • Accept concurrent submissions without corrupting order counts.
  • Register new stations and routing rules without editing the router loop.
  • Give each station its own worker; bounded queues apply backpressure to submitters.

Out of scope

  • Payments and menu management.
  • Inventory and real kitchen hardware.

Design walkthrough

Entities and relationships

NounResponsibility
Order and ItemOwn the customer request and its item values.
TicketCarry one item to a worker.
StationCook queued tickets independently.
RouterValidate and send items through Submit.
OrderTrackerTrack, start and complete orders safely.
NotifierTell a screen or delivery app that an order is ready.

Order owns its items: composition. Stations hold tickets temporarily: aggregation. Router uses stations but does not own their lifecycle.

Class diagram

Order contains Items; Router uses RoutingRule and Station; Station holds Tickets; OrderTracker uses Notifier.

Separate routing, cooking and readiness.

Order contains Items; Router uses RoutingRule and Station; Station holds Tickets; OrderTracker uses Notifier.

Core flow: place an order

Channel submits an order; Router registers its count before sending tickets, and completed tickets lead to a ready notification.

Track before workers can finish.

Channel submits an order; Router registers its count before sending tickets, and completed tickets lead to a ready notification.

Resolve every category before registering the order. An unknown category must not leave half an order cooking.

Order lifecycle

An order moves from Received to Cooking, then Ready and finally PickedUp.

Only completed orders become ready.

An order moves from Received to Cooking, then Ready and finally PickedUp.

An enum and checked transitions are enough here. Separate state types would add little behaviour.

Type skeleton

order.go — Values describe the order and ticket.
Go
package kitchen

import "time"

type Status string

const (
	Received Status = "received"
	Cooking  Status = "cooking"
	Ready    Status = "ready"
	PickedUp Status = "picked-up"
)

type Item struct{ Name, Category string }
type Order struct {
	ID, Channel string
	Items       []Item
	PlacedAt    time.Time
	Rush        bool
}
type Ticket struct {
	OrderID string
	Item    Item
}

Keep values separate from worker state. Routing can then change without changing the customer request.

routing.go — A map supplies the routing strategy.
Go
package kitchen

type RoutingRule interface{ StationFor(Item) (string, bool) }
type ByCategory map[string]string

func (b ByCategory) StationFor(i Item) (string, bool) {
	station, ok := b[i.Category]
	return station, ok
}

Each worker has two lanes. The tracker owns readiness; subscribers only receive its result.

notify.go — Interfaces and fields show the concurrency boundaries.
Go
package kitchen

import "sync"

type Notifier interface{ OrderReady(id, channel string) }
type Station struct{ Rush, Normal chan Ticket }
type OrderTracker struct {
	mu          sync.Mutex
	remaining   map[string]int
	subscribers []Notifier
}
type Router struct {
	Rule     RoutingRule
	Stations map[string]*Station
	Tracker  *OrderTracker
}

Design decisions

How do items reach the right station?

Our choice

Use a RoutingRule strategy backed by a category map.

Why not the alternatives

  • A switch inside RouterEach new category would require changing the core loop.

How do stations stay independent?

Our choice

Give each station a goroutine and its own queue.

Why not the alternatives

  • One shared workerA slow grill would delay drinks too.

How does the front screen learn readiness?

Our choice

Count completed items and call Notifier subscribers outside the lock.

Why not the alternatives

  • Poll every stationThe screen would need to understand station internals.

How do delayed orders jump ahead?

Our choice

Check rush in a non-blocking select before waiting on both lanes.

Why not the alternatives

  • Re-sort a shared sliceAll station workers would contend over one collection.

Trade-offs

Pros

  • Stations cook independently.
  • Routing and notification types plug in.
  • The order lifecycle is explicit.

Cons

  • Workers require coordinated shutdown.
  • Two lanes give approximate priority, not strict priority.

Use when

  • Work fans out to specialised workers.
  • Several channels feed the same kitchen.

Avoid when

  • One cook handles every item.
  • A single queue meets the requirement.

Quick check

Why give each station its own goroutine and channel?
Adding a "dessert" station should change which part of the design?

Takeaways

  • Fan items out to independent station workers.
  • Use Strategy for routing, Observer for readiness, and explicit states for the lifecycle.
  • Design so new stations plug in.

Try the quick check above whenever you feel ready.

Previous: The Machine-Coding Framework