State vs activity: which one for your workflow

State vs activity: which one for your workflow

puml.online

简介 / 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
2
3
4
5
6
7
8
9
10
@startuml
title Order State Machine
[*] --> PendingPayment
PendingPayment --> Paid : Payment succeeds
PendingPayment --> Cancelled : timeout or user cancels
Paid --> Shipped : Merchant ships
Shipped --> Completed : delivery confirmed
Cancelled --> [*]
Completed --> [*]
@enduml

Activity diagram: order fulfilment flow

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
@startuml
title Order Fulfilment Activity
start
:Submit order;
if (Stock available?) then (Yes)
:Create order;
:Await payment;
if (Payment successful?) then (Yes)
:Merchant ships;
:Await delivery;
:Order complete;
else (No)
:Close order on timeout;
endif
else (No)
:Report out of stock;
:Flow ends;
endif
stop
@enduml

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
2
3
4
5
6
7
8
stateDiagram-v2
[*] --> PendingPayment
PendingPayment --> Paid : Payment succeeds
PendingPayment --> Cancelled : timeout or user cancels
Paid --> Shipped : Merchant ships
Shipped --> Completed : delivery confirmed
Cancelled --> [*]
Completed --> [*]

Activity diagram: order fulfilment flow

1
2
3
4
5
6
7
8
9
10
11
flowchart TD
A([Submit order]) --> B{Stock available?}
B -- Yes --> C[Create order]
C --> D[Await payment]
D --> E{Payment successful?}
E -- Yes --> F[Merchant ships]
F --> G[Await delivery]
G --> H([Order complete])
E -- No --> I[Close order on timeout]
B -- No --> J[Report out of stock]
J --> K([Flow ends])

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.