Skip to content
Preptima
mediumDesignCodingMidSeniorStaff

An order moves through a set of states with rules about which transitions are allowed. How would you design that so it does not become a nest of if statements?

5 min readUpdated 2026-08-15Target archetype: Big Tech, Enterprise Captive, Product Startup

Answer

Short answer

Write the legal transitions down as a table first, then give the entity one entry point that consults it and no state setter at all. The design question is where the transition rules live and how side effects stay outside the decision that changed the state.

Was this answer helpful?

Likely follow-ups

  • Two events for the same order arrive at the same moment. What stops the second applying to a state that has already moved?
  • Where do the side effects live, and what happens when one fails after the new state was saved?
  • How would you add a new state without editing every existing state class?
  • The business says any state may go to Cancelled except Shipped. Where exactly does that rule live?

Related questions