State diagrams: choice and fork pseudostates

State diagrams: choice and fork pseudostates

puml.online

Introduction

State machines describe how an object transitions through a set of discrete states during its lifecycle. Two important pseudostates power most real-world models:

  • choice — conditional branching, like if/else, selecting the next state based on guard conditions.
  • fork — parallel branching, splitting a single flow into multiple concurrent paths.

This post uses the same scenario (order processing) to demonstrate both PlantUML and Mermaid, then compares them head-to-head.

PlantUML

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
@startuml
hide empty description

state "New order" as New
state "Paid" as Paid
state "Shipped" as Shipped
state "Delivered" as Received
state "Cancelled" as Cancelled
state "Refunding" as Refunding

[*] --> New
New --> Paid : paymentOk
New --> Cancelled : paymentFail
Paid --> Shipped : ship
Paid --> Refunding : refundRequest

state fork_state <<fork>>
Paid --> fork_state
fork_state --> Shipped
fork_state --> Refunding

state join_state <<join>>
Shipped --> join_state
Refunding --> join_state
join_state --> Received

Received --> [*]
Cancelled --> [*]
@enduml

PlantUML uses <<fork>> and <<join>> stereotypes to mark fork and join pseudostates on the diagram; multiple arrows then branch out from the fork.

Mermaid

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
stateDiagram-v2
[*] --> New
New --> Paid : paymentOk
New --> Cancelled : paymentFail
Paid --> Shipped : ship
Paid --> Refunding : refundRequest

Paid --> Fork : ship
Fork --> Shipped
Fork --> Refunding

Shipped --> Received
Refunding --> Received
Received --> [*]
Cancelled --> [*]

Mermaid uses Fork and Join as special state nodes to achieve the same effect, with guards written inline on the transition lines.

Side by side

Feature PlantUML Mermaid
Choice pseudostate state X <<choice>> guards inline on transitions (cond)
Fork syntax <<fork>> + <<join>> Fork / Join nodes
Parallel arrows multiple --> from fork multiple paths from Fork node
Style class/activity-diagram like concise YAML-like syntax

Wrap-up

choice and fork are the two core pseudostates in state machine modeling. PlantUML implements them via <<choice>>, <<fork>>, and <<join>> stereotypes — semantically precise but more verbose. Mermaid uses built-in Fork/Join nodes — much shorter but lacks an explicit choice pseudostate (guards are inline only). Pick based on whether you need semantic precision or syntactic brevity.

  • Title: State diagrams: choice and fork pseudostates
  • Author: puml.online
  • Created at : 2026-09-06 09:00:00
  • Updated at : 2026-12-06 10:29:22
  • Link: https://puml.online/en/blog/state-diagram-choice-fork/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
State diagrams: choice and fork pseudostates