← Lessons

quiz vs the machine

Gold1420

System Design

The Order Management System

Modeling an order as a state machine from placed to delivered or canceled.

5 min read · core · beat Gold to climb

Orders are state machines

An order management system tracks the lifecycle of every order. The clean way to model this is a state machine: an order moves through well defined states, and only certain transitions are legal.

Typical states

  • Placed: order created and payment authorized.
  • Confirmed: inventory committed and payment captured.
  • Fulfilling: warehouse is picking and packing.
  • Shipped: handed to the carrier.
  • Delivered or Canceled: terminal states.

Illegal transitions, such as shipping a canceled order, must be rejected.

Why this matters

  • Auditability: every transition is an event you can log, replay, and reconcile.
  • Coordination: downstream services such as shipping and accounting react to state change events.
  • Recovery: if a process crashes, the stored state tells you exactly where to resume.

Each transition should be idempotent so a retried event does not advance the order twice.

Key idea

Model orders as a state machine with legal transitions and idempotent events so the lifecycle stays auditable and recoverable.

Check yourself

Answer to earn rating on the learn ladder.

1. Why model an order as a state machine?

2. Why should each order transition be idempotent?