Skip to content

Hierarchical Checkout

A multi-step checkout flow covering cart, shipping, and payment. The payment step is complex enough to warrant its own sub-states — making this a natural fit for a nested submachine. The flattened variant shows what the same flow looks like when every state is promoted to the top level.

In the nested variant, the Payment state contains a submachine (CardEntry → Processing → Confirmed / Failed). The outer machine delegates control to the submachine while payment is in progress and resumes once it reaches a terminal state. This keeps the top-level machine focused on the checkout stages and isolates payment complexity.

In the flattened variant, all payment sub-states are peers at the top level alongside Cart, Shipping, and OrderComplete. Every state is explicit and directly traversable, at the cost of a larger flat list of states and repeated transitions.

Submachines shine when a phase of your flow is complex enough to warrant local state management — and when you want to reuse or test that phase in isolation.