Sequence Diagrams

📌 What is a Sequence Diagram?

A Sequence Diagram is a type of interaction diagram in UML (Unified Modeling Language) that models the flow of messages/events between system components (objects, actors) over time. It is used to show how different parts of a system interact with each other in a specific sequence to accomplish a process or functionality.

Purpose:

  • Visualize the order of interactions in a process.

  • Show how objects and components collaborate over time.

  • Model use case scenarios and system behaviors in detail.


🎯 Key Elements of Sequence Diagrams

Element

Description

Notation

Lifeline

Represents an object, class, actor, or system component

Vertical dashed line

Actor

External user or system interacting with the system

Stick figure

Message

Communication between lifelines (method calls, signals)

Solid arrow (→)

Return Message

Response to a message

Dashed arrow (--> )

Activation/Execution Bar

Time period when an object performs an operation

Thin rectangle on lifeline

Creation Message

Creates a new object

Arrow with "new" label

Destruction Message

Destroys an object

Cross mark (X) on lifeline

Alt / Opt / Loop Fragments

Conditional and looping behaviors

Boxed frames with label


When to Use Sequence Diagrams

  • To model scenarios of a use case or business process.

  • To visualize the flow of interactions between system components.

  • To specify system behavior and logic.

  • To analyze and design the dynamic aspects of a system.

  • To document communication patterns in software engineering.


🧭 How to Create a Sequence Diagram (Step-by-Step)

  1. Identify the scenario/use case to be modeled.

  2. List all actors and objects involved in the process.

  3. Determine the order of interactions (messages) exchanged.

  4. Draw lifelines for each participant.

  5. Add messages and return messages between lifelines.

  6. Use activation bars to show periods of activity.

  7. Add conditional/loop fragments if needed.

  8. Review and validate with stakeholders.


📊 Example of a Sequence Diagram

Scenario: User Login Process

Participants:

  • User (Actor)

  • Login Page (UI)

  • Authentication Service

  • Database


Step-by-Step Flow:

  1. User enters credentials on Login Page.

  2. Login Page sends credentials to Authentication Service.

  3. Authentication Service queries Database for user data.

  4. Database returns user data.

  5. Authentication Service verifies credentials.

  6. Authentication Service sends login success/failure to Login Page.

  7. Login Page displays result to User.


Diagram Representation (Text format)

pgsqlCopyEditUser       Login Page       Auth Service       Database
 |              |                  |                  |
 |-- Login -->  |                  |                  |
 |              |-- Auth Request ->|                  |
 |              |                  |-- Query User -->|
 |              |                  |<-- User Data ---|
 |              |<-- Auth Result --|                  |
 |<-- Result ---|                  |                  |

💡 Explanation of Flow:

  • Horizontal axis: Participants (User, Login Page, Services).

  • Vertical axis: Time flow from top (start) to bottom (end).

  • Solid arrows: Messages/requests.

  • Dashed arrows: Return messages.

  • Activation bars: Indicate active period of execution (optional in text).


🚀 Benefits of Sequence Diagrams

Benefit

Explanation

Clarifies communication flow

Shows how components exchange messages.

Captures system behavior

Visualizes object interactions for scenarios.

Reveals process logic

Makes implicit flows explicit for review.

Improves collaboration

Helps business and technical teams align understanding.

Useful for design and testing

Guides development and validation of processes.


🔑 Best Practices for Sequence Diagrams

  • Focus on a single scenario to keep diagrams simple.

  • Name messages clearly (use descriptive method names).

  • Use activation bars to highlight when objects are active.

  • Organize lifelines logically from left to right.

  • Use fragments (alt, opt, loop) for conditional/looped flows.

  • Keep diagrams clean and uncluttered for readability.


🎯 Summary of Sequence Diagrams

Aspect

Details

Purpose

Visualize message flow over time between objects

Key Elements

Lifelines, Messages, Activations, Fragments, Actors

Use Cases

Modeling scenarios, system interactions, communication flows

Main Benefits

Clarifies communication, documents system behavior, improves understanding


📚 Common Fragments and Notations

Fragment

Purpose

Notation

alt (Alternative)

Represents conditional flow (if/else)

Box labeled alt with conditions

opt (Optional)

Represents optional flow (if condition met)

Box labeled opt

loop

Repeating interaction flow

Box labeled loop with condition

par

Parallel flows

Box labeled par


🚀 Example of a Loop Fragment (Login Retries)

pgsqlCopyEditloop [Attempts < 3]
   User -> Login Page: Enter credentials
   Login Page -> Auth Service: Authenticate
   Auth Service -> Login Page: Auth result
end loop

Last updated