Skip to content

feat(blog): state machine vs workflow, with worked examples - #121

Merged
vandetho merged 1 commit into
mainfrom
blog/state-machine-vs-workflow-examples
Jul 26, 2026
Merged

feat(blog): state machine vs workflow, with worked examples#121
vandetho merged 1 commit into
mainfrom
blog/state-machine-vs-workflow-examples

Conversation

@vandetho

Copy link
Copy Markdown
Owner

Adds a deep-dive companion to the existing short state-machine-vs-workflow guide (2026-04-05), which stayed at the "one state vs many states" level.

New post: state-machine-vs-workflow-worked-examples"State Machine vs Workflow: The Same Domain, Modeled Both Ways".

What's in it

Four worked examples, each with YAML plus the PHP entity and call sites:

  1. Order lifecycle as a state_machine — string column, can() / apply()
  2. The same order with parallel fulfillment as a workflow — AND-split on pay, AND-join on ship, JSON marking column
  3. Article review — the canonical Petri net, guards on individual approvals
  4. One ticket, three concurrent lifecycles — why that's three state machines, not one net

Plus the two traps, both checked against Symfony source rather than written from memory:

  • from: [a, b] is an OR under state_machine and an AND-join under workflow, because FrameworkBundle expands state-machine transitions into one Transition per from×to pair while workflows keep a single multi-input transition
  • to: [x, y] under state_machine fails at container compile with the confusing "A transition from a place/state must have an unique name" message — a consequence of that same expansion

Closes with a decision table, a 4-step state-machine → workflow migration checklist, and a simulator exercise.

Also

The older short post now links to this one at the end, so the two don't compete on search.

Notes

  • tsc --noEmit clean; lint-staged (eslint + prettier) ran on commit
  • The blog reads from the blogPost table with the static array only as fallback, so this needs pnpm prisma:seed against the target DB before it appears on the live site

🤖 Generated with Claude Code

Deep-dive companion to the existing short state-machine-vs-workflow
guide, with four worked examples (order lifecycle, parallel
fulfillment, article review, three concurrent lifecycles) and the two
type-specific traps: `from: [a, b]` compiles to an OR under
state_machine but an AND-join under workflow, and `to: [x, y]` fails
StateMachineValidator at container compile time.

Cross-links the older short post to the new one so the two do not
compete on search.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@vandetho
vandetho merged commit b655b01 into main Jul 26, 2026
3 checks passed
@vandetho
vandetho deleted the blog/state-machine-vs-workflow-examples branch July 26, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant