Sequence Diagram and Activity Diagram are both essential interaction-modeling tools, but they focus on different things. Sequence diagrams emphasize who said what to whom and when; activity diagrams emphasize branching, loops, and parallelism in a process. Picking the right diagram type makes the chart self-explanatory; picking wrong adds confusion.
PlantUML 版
Sequence Diagram
1 2 3 4 5 6 7 8 9 10 11 12 13 14
@startuml title User Login Sequence actor User participant "Frontend" as FE participant "Backend" as BE database "Database" as DB
User -> FE : Enter credentials FE -> BE : POST /login BE -> DB : Query user DB --> BE : User record BE --> FE : JWT Token FE --> User : Login success @enduml
Activity Diagram
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
@startuml title Order Processing Activity start :Receive order; :Check inventory; if (Inventory sufficient?) then (yes) :Deduct stock; :Generate invoice; else (no) :Notify user out of stock; stop endif :Send order email; stop @enduml
PlantUML uses -> / --> for message arrows in sequences and if / fork / kill / start / stop for activity flow control. The two diagram types share no keywords.
Mermaid 版
Sequence Diagram
1 2 3 4 5 6 7 8 9 10 11 12 13
sequenceDiagram title User Login Sequence actor User participant Frontend participant Backend database Database
User->>Frontend: Enter credentials Frontend->>Backend: POST /login Backend->>Database: Query user Database-->>Backend: User record Backend-->>Frontend: JWT Token Frontend-->>User: Login success
Activity Diagram
1 2 3 4 5 6 7 8 9 10 11 12 13
activity title Order Processing Activity :Receive order; :Check inventory; if (Inventory sufficient?) then (yes) :Deduct stock; :Generate invoice; else (no) :Notify user out of stock; stop endif :Send order email; stop
Mermaid also separates the two diagram types entirely: sequenceDiagram uses ->> arrows, while activity uses if/else, parallel, and stop. The title keyword is optional in both.
对比 / Side-by-side
Dimension
Sequence Diagram
Activity Diagram
Core focus
Temporal order of messages between participants
Branching and parallelism of a process
PlantUML keywords
->, -->
if, fork, kill, start, stop
Mermaid keywords
->>, -->>
if/else, parallel, stop
Best for
API calls, protocol interactions, object collaboration
Business workflows, algorithm steps, decision branches
Loop notation
loop (both engines)
while / repeat
小结 / Wrap-up
Use a sequence diagram when you want to show who calls whom and when (message exchange over time). Use an activity diagram when you want to model process logic (branches, loops, parallelism). In real projects the two complement each other: the activity diagram shows the overall business flow, while the sequence diagram explains the interface calls at key nodes. Choose based on the core semantics you need to convey, not on which chart looks more complex.