State vs activity: which one for your workflow
简介 / Introduction
State diagrams and activity diagrams both come from UML behavioural modelling, yet they answer different questions. A state diagram answers “which state is this object in, and how does it get to another state”. An activity diagram answers “what steps does the whole process go through, and where are the branches and loops”.
The classic confusion is an order system: should “pending payment → paid → shipped → completed” be a state machine or an activity flow? Both are valid, but they serve different purposes. A state diagram attaches to an object and encodes constraints and validation; an activity diagram describes end-to-end steps for business stakeholders.
PlantUML version
State diagram: order lifecycle
1 | @startuml |
Activity diagram: order fulfilment flow
1 | @startuml |
In PlantUML, a state diagram declares its start state with [*] --> and labels each transition with its trigger after a colon (: label). An activity diagram uses if/else/endif for branches and : action; for action nodes.
Mermaid version
State diagram: order lifecycle
1 | stateDiagram-v2 |
Activity diagram: order fulfilment flow
1 | flowchart TD |
Mermaid’s stateDiagram-v2 has the same semantics as PlantUML, with [*] again standing for the start/end pseudostate. For activity-style flowcharts Mermaid recommends flowchart: square brackets are action nodes, { } are decision nodes, ([ ]) are start/end nodes, and edge labels such as -- Yes -- mark branch conditions.
Side-by-side
| Dimension | State diagram | Activity diagram |
|---|---|---|
| Modelled subject | The states of a single entity | The steps of a cross-role process |
| Core elements | States, transitions, trigger events | Action nodes, decisions, branches/parallels |
| PlantUML keywords | [*], -->, : trigger event |
start/stop, : action;, if/endif |
| Mermaid keywords | stateDiagram-v2, [*], --> |
flowchart TD, { }, ([ ]) |
| The question it answers | “What state is it in now?” | “What happens next?” |
Wrap-up
A simple rule: if every node in your diagram is a state of a thing, use a state diagram; if every node is an action, use an activity diagram. A state diagram is an object-level model of state constraints, while an activity diagram is a process-level model of behaviour. In practice the two complement each other — the activity diagram gives the overall flow, and state diagrams add precise transition rules for key objects (orders, tickets, accounts) so the flow chart does not only draw the happy path and quietly drop the exception branches.
- Title: State vs activity: which one for your workflow
- Author: puml.online
- Created at : 2026-11-04 09:00:00
- Updated at : 2026-11-26 01:07:01
- Link: https://puml.online/blog/state-vs-activity-for-workflow-en/
- License: This work is licensed under CC BY-NC-SA 4.0.