State machine

Forge

An explicit model of the states a task can occupy and the transitions allowed between them.

What is a state machine?

A state machine is an explicit model of the states a task may occupy together with the transitions permitted between them. A task occupies exactly one state at a time and moves only along a defined transition. Anything the model does not permit cannot happen by accident.

Why implicit state is where a workflow loses track of itself

A workflow whose state is implied by a scatter of flags will eventually hold a task that is both approved and awaiting approval. Nobody engineered that state, which is exactly the point, since nothing ever declared which states were legitimate. The explicit version costs more at design time and pays for itself the first time a task resumes after a restart, because the machine knows where the task had reached. It also gives operations a vocabulary for the backlog that matches what the engineers see.

  • An explicit model makes an impossible combination of states unreachable.
  • A resumed task can establish exactly where it had reached.
  • Permitted transitions are the natural place to attach an approval.
  • Operations and engineering describe the same task in the same words.

How a state machine works

  • The states a task may occupy are enumerated, including its terminal states.
  • Each permitted transition is declared with the condition that allows it.
  • The current state is persisted durably at every transition.
  • Transitions are recorded with a timestamp and the actor that caused them.
  • An attempted transition outside the model is rejected and raised as an exception.
  • Tasks lingering in one state beyond a threshold are reported for attention.

How a state machine is evaluated

A state machine is assessed on whether the live population matches the model. Examine the following against the task store:

  • tasks found in a state the model does not define
  • rejected transitions per thousand executions
  • distribution of tasks across states over time
  • tasks exceeding the expected dwell time in any state
  • proportion of transitions with a recorded actor

Limitations, risks and common failure modes

  • States are added over time until no diagram matches the implementation.
  • A terminal state is reachable while compensating work remains outstanding.
  • Transition records are retained for less time than the tasks themselves.
  • Two components write the state directly, so the model is bypassed.
  • Dwell time thresholds are never set, so a stalled task stays invisible.

All 315 terms