Sequence-diagram grammar is interview-popular but underused in real codebases — most teams have no idea how to make these diagrams genuinely readable to reviewers. Here’s the full set.
Fragment cheat sheet (repeated for emphasis)
1 2 3 4 5 6 7
alt / else / end — branch opt / end — optional block loop / end — loop par / else / end — parallel critical / option / end — critical + failure path break / end — early exit note / end note — annotation
Two or three of these for “order payment flow”:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
@startuml title Payment flow
User -> Gateway: initiate pay Gateway -> Risk: evaluate alt risk OK Gateway -> Bank: charge critical failure rollback Gateway -> Bank: refund option refund failed Gateway -> Support: human in end option end critical Gateway --> User: 200 else risk rejected Gateway --> User: 403 end
@startuml actor User participant "Order Service" as Os participant "Payment Service" as Ps participant "Inventory Service" as Is database "Order DB" as Odb
== Submit order == User -> Os: POST /orders Os -> Is: lock stock Is --> Os: ok Os -> Odb: insert Odb --> Os: order_id
== Pay == Os -> Ps: pay(order_id) group payment logic alt success Ps -> Odb: update status=paid else fail Ps -> Odb: update status=failed Os -> Is: unlock end end
== Notify == Os --> User: 200 + order_id @enduml
group / end folds a span in the rendered output — handy for hiding detail.
ref and step
ref — point to another diagram
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
@startuml title Main login flow participant FE participant API participant Auth
== Signup == User -> FE: open signup FE -> API: POST /signup API -> Auth: create user Auth --> API: ok API --> FE: 200
note right of User: already documented @enduml
ref over A, B : label references an existing description:
1 2 3 4 5 6 7 8 9 10 11
@startuml
participant FE participant API
FE -> API: POST /login note right of FE: ref'd over ref over FE : login page loaded FE -> API: submit form
@enduml
step (visible delay)
step 500ms tells PlantUML to render the next arrow after a delay:
1 2 3 4 5 6 7 8 9
@startuml
Client -> Server: request step 500ms Server --> Client: 200 step 1000ms Client -> Server: next request
@enduml
Useful for animated sequence screenshots, but for static blog exports the delay doesn’t show.