ld.← ALL FIELD NOTESTHE RELATED CASE STUDY ↗
FIELD NOTES / 24STATE MACHINES   ·   ENGINEERING PRACTICE

Make invalid state transitions impossible.

A state machine becomes practical when a bad state transition would otherwise succeed silently.

A small set of rules

Our submission lifecycle has three states: Draft, Open, and Merged. Draft can move to Open; Open can return to Draft or move to Merged. A Draft cannot skip review and become Merged directly.

Without an explicit guard, a faulty client or concurrent request might attempt a transition the workflow does not allow. A successful write could leave the submission in a state the product never intended.

A REVIEWABLE LIFECYCLE
DRAFTPrepare changes
OPENReview or return to draft
MERGEDApply the approved submission

Enforce the boundary

We check whether the current and requested states form a valid transition before applying a change. Invalid transitions return a 409 with a clear explanation, rather than quietly changing the record.

Keeping the rules in one place makes the lifecycle easier to reason about across callers. Correctness under concurrent updates also depends on how the state change is guarded at the storage boundary.

Continue the conversation

KEEP READING / 23Why every graph change goes through review.

Another note from the notebook.