Sequence diagrams: async messages and callbacks

Sequence diagrams: async messages and callbacks

puml.online

简介 / Introduction

Sequence diagrams visualize time-ordered interactions between objects. Synchronous (sync) messages block until a response arrives, while asynchronous (async) messages fire and forget — common in HTTP calls, event-driven systems, and microservice architectures. This article uses the same business scenario to compare PlantUML and Mermaid side by side.

PlantUML 版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@startuml
skinparam backgroundColor #FEFEFE
skinparam handwritten false

participant "Client" as Client
participant "Service A" as SvcA
participant "Service B" as SvcB

Client -> SvcA : Request (sync)
activate SvcA
SvcA -> SvcB : Fire event (async)
activate SvcB
SvcB --> SvcA : Callback
deactivate SvcB
SvcA --> Client : Response (sync)
deactivate SvcA

note over Client, SvcB
Async messages do not block the sender.
Callbacks use dashed return arrows.
end note
@enduml

PlantUML uses -> for sync messages, --> (dashed) for returns, and activate/deactivate to manage lifelines. Async messages are plain -> arrows with no special keyword. Callbacks are explicitly modelled with dashed return arrows.

Mermaid 版

1
2
3
4
5
6
7
8
9
sequenceDiagram
participant Client
participant SvcA
participant SvcB

Client->>+SvcA: Request (sync)
SvcA->>+SvcB: Fire event (async)
SvcB-->>-SvcA: Callback
SvcA-->>-Client: Response (sync)

Mermaid’s syntax is more compact: ->>+ enters an activation, -->>- leaves and returns in one step. A plain -> arrow without +/- is async — it neither pushes nor pops the activation stack. Callbacks use a dashed return arrow -->>.

对比 / Side-by-side

Feature PlantUML Mermaid
Sync message -> ->>+ (enters activation)
Async message -> (no marker) ->
Return message --> -->>-
Activation/Deactivation activate / deactivate trailing + / - on arrow
Callback --> (dashed return) -->> (dashed return)
Note/Comment note over %% line comment

小结 / Wrap-up

Both engines express async and callback semantics clearly. PlantUML is more verbose but more expressive, suitable for complex interactions; Mermaid is terse and ideal for embedded documentation and quick prototypes. Choose based on interaction complexity and team tooling preferences.

  • Title: Sequence diagrams: async messages and callbacks
  • Author: puml.online
  • Created at : 2026-08-28 09:00:00
  • Updated at : 2026-08-28 01:01:15
  • Link: https://puml.online/blog/sequence-diagram-async-messages-en/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
Sequence diagrams: async messages and callbacks