3.1.1 What Is a Sequence Diagram?
A sequence diagram models how system components interact over time.
Unlike flowcharts (which model process flow), sequence diagrams emphasize:
Participants (actors/components)
Request/response patterns
Sequence diagrams are ideal for:
Event-driven architecture
Debugging communication paths
In Mermaid, every sequence diagram starts with:
3.1.2 Participants
Participants represent:
Basic participant declaration:
Example:
If you omit explicit declarations, Mermaid auto-generates participants based on message lines.
Example:
Mermaid automatically creates User and Server.
3.1.3 Naming Participants Clearly
Use meaningful identifiers:
Poor:
Better:
Clear naming improves:
3.1.4 Basic Message Syntax
The core message syntax:
Example:
This defines:
3.1.5 Arrow Types in Sequence Diagrams
Mermaid supports different arrow styles.
Solid arrow (synchronous message)
Dotted arrow (response/return)
Solid line (no arrow head emphasis)
Asynchronous/return style
Example: Request–Response Pattern
Solid arrows = requests
Dotted arrows = responses
This is standard API modeling practice.
3.1.6 Ordering Matters
Sequence diagrams are time-ordered from top to bottom.
This:
Means:
Reordering lines changes system behavior representation.
3.1.7 Real-World Example — Login Flow
Observe:
3.1.8 Implicit vs Explicit Participants
Implicit version:
Explicit version:
Best practice:
Declare participants explicitly in production diagrams.
3.1.9 External Actors
Mermaid supports actor keyword:
Actors visually appear differently from system participants.
Use actors for:
3.1.10 Multi-Service Microservice Example
This models a distributed system clearly.
3.1.11 Best Practices for Participants
Avoid single-letter identifiers
Use consistent naming conventions
Declare participants at top
Order participants logically (left to right)
Example ordering strategy:
3.1.12 Hands-On Exercise
Build a Password Reset Flow:
Requirements:
Constraints:
Use at least 4 participants
Include request and response arrows
Keep chronological ordering correct
3.1.13 Common Beginner Mistakes
Forgetting sequenceDiagram keyword
Placing responses before requests
Overcrowding with too many participants
Mixing flowchart syntax inside sequence diagrams
Incorrect:
Correct:
3.1.14 Key Takeaways
Sequence diagrams focus on:
Participants define actors in the system.
Messages define interaction.
Chronology defines behavior.
Mastering these primitives allows you to model:
Microservice choreography
In the next topic, we will explore Activation and Deactivation, which models execution lifelines and processing duration.