Sequence Diagram

Show object interactions over time

Overview

Sequence diagrams show how objects interact over time. They display the order of method calls between objects and are excellent for visualizing complex workflows and scenarios.

Sequence diagrams are very useful in LLD interviews to explain how your classes work together.

Key Concepts

Objects shown as boxes at top with lifelines (dashed vertical lines)

Messages shown as arrows between lifelines

Activation bars show when object is active

Return messages shown as dashed arrows

Time flows from top to bottom

Code Example

java
1/*
2Sequence Diagram: User Login Flow
3
4  User          LoginController      AuthService       UserRepository      Database
5    │                 │                   │                   │                │
6    │   login(email,  │                   │                   │                │
7    │   password)     │                   │                   │                │
8    │────────────────>│                   │                   │                │
9    │                 │  authenticate()   │                   │                │
10    │                 │──────────────────>│                   │                │
11    │                 │                   │  findByEmail()    │                │
12    │                 │                   │──────────────────>│                │
13    │                 │                   │                   │    SELECT      │
14    │                 │                   │                   │───────────────>│
15    │                 │                   │                   │    user        │
16    │                 │                   │                   │<───────────────│
17    │                 │                   │       User        │                │
18    │                 │                   │<──────────────────│                │
19    │                 │                   │                   │                │
20    │                 │                   │ verifyPassword()  │                │
21    │                 │                   │──────┐            │                │
22    │                 │                   │      │            │                │
23    │                 │                   │<─────┘            │                │
24    │                 │                   │                   │                │
25    │                 │   AuthResult      │                   │                │
26    │                 │   (token, user)   │                   │                │
27    │                 │<──────────────────│                   │                │
28    │                 │                   │                   │                │
29    │  LoginResponse  │                   │                   │                │
30    │  (success/fail) │                   │                   │                │
31    │<────────────────│                   │                   │                │
32    │                 │                   │                   │                │
33
34Notation:
35─────────────> Synchronous message
36<─ ─ ─ ─ ─ ─ ─ Return message (dashed)
37──────┐        Self-call
3839<─────┘
40*/

Shows the sequence of method calls during a login process, from user request through authentication to database query.

Best Practices

  • 1.

    Include only key objects for the scenario

  • 2.

    Show one scenario per diagram

  • 3.

    Keep it readable - don't show every detail

  • 4.

    Use activation bars to show object activity

  • 5.

    Include return values when relevant

💡 Interview Tips

  • Draw sequence diagrams to explain your design

  • Show main success scenario first

  • Helps validate that your classes work together

  • Practice with common flows: login, checkout, search

  • Can reveal missing methods or classes

AI Tutor

Ask about the topic

Sign in Required

Please sign in to use the AI tutor

Sign In
Sequence Diagram - UML | LLD | Revise Algo