Post

UML Communication Diagram vs Sequence Diagram: When to Use Which

A practical comparison of UML Communication Diagrams and Sequence Diagrams with real-world use cases.

UML Communication Diagram vs Sequence Diagram: When to Use Which

Introduction

While writing test documentation, I kept switching between Communication and Sequence diagrams without a clear reason. One reviewer asked: “Why did you use a sequence diagram here but a communication diagram there?” I didn’t have a good answer. After researching the UML spec and experimenting with both, I finally understood when to use each.


Same Scenario, Different Diagrams

Let’s visualize the same interaction both ways to see the difference:

Scenario: Tester calls Update API, then calls Undo API

Communication Diagram

Focus: Who talks to whom (structure)

flowchart LR
    T([Tester])
    U[Update API]
    D[Undo API]
    
    T -->|"1: POST /update"| U
    U -.->|"1.1: 200"| T
    T -->|"2: POST /undo"| D
    D -.->|"2.1: 200"| T

Sequence Diagram

Focus: What happens when (time)

sequenceDiagram
    participant T as Tester
    participant U as Update API
    participant D as Undo API
    
    T->>+U: POST /update
    U-->>-T: 200
    T->>+D: POST /undo
    D-->>-T: 200

Notice the difference? Communication shows the network of relationships. Sequence shows the timeline with activation bars.


When to Use Each

flowchart TD
    Q1{What question are you answering?}
    
    Q1 -->|"Which components interact?"| COMM
    Q1 -->|"What happens step by step?"| SEQ
    
    COMM[Communication Diagram]
    SEQ[Sequence Diagram]
    
    COMM --> C1["Architecture overview"]
    COMM --> C2["Test scenario summary"]
    COMM --> C3["Compact documentation"]
    
    SEQ --> S1["Detailed flow analysis"]
    SEQ --> S2["Debugging/tracing"]
    SEQ --> S3["Async/parallel operations"]

Decision Table

QuestionAnswerUse
“Which components are involved?”Need to show connectionsCommunication
“What happens first, second, third?”Need to show orderSequence
“How does the whole system look?”Architecture viewCommunication
“Why did step 3 fail?”Debug/traceSequence
“Space is limited”Need compact diagramCommunication
“Many back-and-forth messages”Complex interactionSequence

Detailed Comparison

AspectCommunication DiagramSequence Diagram
LayoutFree-form networkVertical timeline
Message OrderExplicit numbers (1, 1.1, 2)Implicit (top→bottom)
ActivationNot shownBars show active objects
Loops/AltHard to showNative support (loop, alt)
SpaceCompact, fits overviewGrows vertically
MermaidWorkaround (flowchart)Native support
Best For“Big picture”“Step-by-step”

Real-World Use Cases

1. Test Scenario Overview (Communication)

When documenting test coverage, show all APIs involved:

flowchart LR
    T([Tester])
    L[Listing API]
    S[Search API]
    U[Update API]
    X[Undo API]
    
    T --> L
    T --> S
    T --> U
    T --> X

2. Single Test Flow (Sequence)

When documenting one specific test, show the exact steps:

sequenceDiagram
    participant T as Tester
    participant A as API
    participant DB as Database
    
    T->>+A: GET /listing
    A->>+DB: SELECT
    DB-->>-A: rows
    A-->>-T: 200 (original data)
    
    T->>+A: POST /update (modify row)
    A->>+DB: UPDATE
    DB-->>-A: affected=1
    A-->>-T: 200
    
    T->>+A: GET /listing
    A->>+DB: SELECT
    DB-->>-A: rows
    A-->>-T: 200 (modified data)

Mermaid Tips

Communication Diagram Workaround

Mermaid doesn’t support Communication Diagrams natively. Use flowchart LR:

1
2
3
4
5
6
7
8
```mermaid
flowchart LR
    A[Object A]
    B[Object B]
    
    A -->|"1: request"| B
    B -.->|"1.1: response"| A
​```

Conventions:

  • --> for request (solid arrow)
  • -.-> for response (dashed arrow)
  • "1: message" for numbered labels

Sequence Diagram Native

1
2
3
4
5
```mermaid
sequenceDiagram
    A->>+B: request
    B-->>-A: response
​```

Conventions:

  • ->> for sync call
  • -->> for response
  • +/- for activation bars

Summary

SituationUse
Overview documentationCommunication
Test scenario listCommunication
Detailed test flowSequence
Debugging failed testSequence
Architecture diagramCommunication
API interaction traceSequence

Rule of thumb: Start with Communication for the overview, add Sequence for important details.

This post is licensed under CC BY 4.0 by the author.