Sequence diagrams: critical regions
简介 / Introduction
Some steps in a sequence are “must succeed, otherwise the whole flow fails” — locking stock, debiting a balance, writing an audit log. That block is modelled as a critical region: every message inside it must run, and a failure jumps to the alternative branch. Unlike alt (pick one) or loop (repeat), the semantics here are “fail fast”.
Both engines provide critical, but the companion branch keyword differs: PlantUML uses opt, Mermaid uses option. The label syntax differs too. This article compares both with the same “place an order and lock stock” scenario.
PlantUML version
1 | @startuml |
In PlantUML the failure branch of a critical block is spelled opt (not option). Labels usually go inside square brackets: critical [lock stock] (plain critical lock stock also parses, but brackets are the idiomatic PlantUML fragment style). A critical needs at least one opt to draw the full region structure; without it no failure branch is drawn.
Mermaid version
1 | sequenceDiagram |
In Mermaid the failure branch of a critical block is spelled option. The label goes right after the keyword with no square brackets — Mermaid renders critical [lock stock] literally as [lock stock], because brackets are not syntax there. Mermaid also does not accept else or break inside a critical block; either one raises a Parse error.
对比 / Side-by-side
| Feature | PlantUML | Mermaid |
|---|---|---|
| Critical keyword | critical |
critical |
| Failure branch keyword | opt |
option |
| Label syntax | brackets critical [text] |
plain critical text |
| Square brackets in a label | rendered correctly | rendered literally as [text] |
option keyword |
❌ syntax error | ✅ correct |
opt keyword |
✅ correct | ❌ treated as ordinary text |
else inside the block |
✅ supported | ❌ parse error |
break inside the block |
✅ supported | ❌ parse error |
Nested par inside the block |
✅ supported | ✅ supported |
小结 / Wrap-up
critical carries the same “must succeed or fail” meaning in both engines, but three details differ: PlantUML’s failure branch is opt while Mermaid’s is option; PlantUML labels are bracketed while Mermaid’s are not; and Mermaid rejects else or break inside a critical region. Writing those three rules into a team convention means maintaining the same sequence diagrams across both engines only requires swapping the keyword instead of debugging render failures.
- Title: Sequence diagrams: critical regions
- Author: puml.online
- Created at : 2026-11-09 09:00:00
- Updated at : 2026-11-26 01:07:01
- Link: https://puml.online/blog/sequence-diagram-critical-region-en/
- License: This work is licensed under CC BY-NC-SA 4.0.