Orders, refunds, subscriptions, tenants, support tickets, deployments β most business entities move through a lifecycle. And a whole category of production bugs comes from that lifecycle being implicit:
A cancelled order gets shipped because the cancel and the ship request arrived 50 ms apart.
A refund is issued twice because two retries both saw status = 'PAID' .
An account stuck in PROVISIONING for a week because a step failed and nothing defined what happens next.
In each case, the states existed only as a string column, and any code path could set any value. The fix is to make the state machine explicit, and to enforce it where concurrency actually happens: in the database.
Step 1: name the states and transitions
Write them down in one place. For an order:
Every arrow is an allowed transition; anything else is a bug.β¦