Keep consequential workflow state in a durable system that independent workers can inspect. In-memory variables and automation execution history alone may not establish the current owner, intent revision, or external effect state after a restart.
A state database represents business progress
A workflow-state database records the logical operation and permitted transitions independently from individual execution attempts. Useful fields include operation identity, current stage, intent revision, ownership, relevant versions, and authoritative result references.
For a proposed design, use atomic transitions or supported concurrency controls to claim work and reject stale updates. Workers record attempts under the same logical operation. A restart should reconstruct pending and uncertain work from durable evidence rather than replay everything.
The database is not automatically the authority for every external fact. A booking or payment service may remain authoritative for its own result. Store the relationship and reconciliation state rather than pretending local intent proves remote completion.
Walk through a fictional two-worker race
Two workers receive the same request operation. Both read “ready.” Only one should successfully claim the permitted transition to execution under the database’s concurrency mechanism. The other observes the current state and does not create a second effect.
If the winning worker crashes after the remote write commits, recovery must reconcile the remote outcome. A local “running” row alone does not establish whether it is safe to repeat the write.
| State boundary | Required invariant |
|---|---|
| Work accepted | Durable operation is discoverable |
| Worker claims task | One current valid owner under policy |
| Intent changes | Stale action cannot commit unchecked |
| Remote outcome uncertain | Explicit reconciliation state |
| Work completes | Authoritative result linked |
Test transaction conflicts, lease expiry where used, and process restarts. A simple sequential test does not establish concurrency safety.
Keep the model small enough to operate
Too many states make recovery confusing, while one success flag hides critical differences. Define states by actions staff or workers may safely take. Document terminal states and which events cannot revive them.
A durable state service adds schema migrations, storage, access control, and monitoring. It is justified when loss, duplication, or conflicting execution has material consequences. For a simple low-impact task, a smaller ledger may satisfy the same essential boundary.
This architecture is proposed. The voice integration case study describes relevant backend work. Pair it with restart recovery tests.
Workflow state FAQ
Does a database guarantee exactly-once external actions?
No. External effects still need supported identity, concurrency, and reconciliation mechanisms.
Should every message be stored as workflow state?
No. Persist the business facts and evidence references required for safe progress and recovery.
What should operations be able to see?
The current stage, known effect status, owner, permitted next action, and reason work is unresolved.