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.