CMD Guide
HomeOO & Low-Level DesignOOD Foundations

Sequence diagram

A sequence diagram pins a single scenario to two axes so message order becomes unambiguous: each participant gets a vertical lifeline, and time flows strictly downward, so a message drawn lower on the page provably happens after one drawn higher — the diagram is the call order, read top to bottom.

Read the notation off the wire:

Worked trace: a $200 ATM withdrawal

Scenario: a customer with a $150 balance asks for $200. We trace the exact messages an LLD interview answer would draw, with concrete values, so the alt branch and the return arrows are forced to mean something. Participants: Customer (actor), :ATM, :Account, bank:BankService.

#From → ToMessage (with values)KindReturns
1Customer → :ATMwithdraw(amount=200)sync
2:ATM → :AccountgetBalance("acct-77")sync150
3alt [requested 200 > balance 150] — guard is TRUE, so this branch runs
4:ATM → Customershow("Insufficient funds")return
5[else] — guard FALSE; skipped this run
6:ATM → bank:BankServicedebit("acct-77", 200) (not sent)syncok
7:ATM → Customerdispense(200) (not sent)async

The trace makes the value-dependence explicit: because getBalance returned 150, the guard 200 > 150 selected the top arm of the alt and steps 6–7 never execute on this run. Swap the input to amount=100 and the diagram is identical except the lower arm runs instead — that is the whole point of drawing the alt rather than two separate diagrams.

diagram
diagram

Pitfalls

When to reach for it — and when not

UML gives you several interaction/behavior views; the skill is picking the one that makes the thing you're worried about visible.

One-liner: choose a sequence diagram when the bug or design question is "in what order do these objects talk"; prefer an activity diagram when it's "what's the branching logic inside one flow", and a communication diagram when it's "which objects are even connected".

Takeaways


Sources: OMG UML 2.5.1 Specification (interaction diagrams, lifelines, combined fragments and guards); Martin Fowler, UML Distilled (3rd ed., ch. on Sequence Diagrams — sync vs async messaging and when to prefer activity/communication diagrams); Grady Booch et al., The Unified Modeling Language User Guide. Re-authored and deepened for this guide: added the mechanism statement, a step-by-step $200/$150 ATM withdrawal trace, a hand-authored SVG replacing the prior unlabeled figure, a pitfalls section, and a selection/trade-offs comparison against activity, communication, and state diagrams.

When NOT to draw a sequence diagram

Interviewer follow-ups & drills

  1. Why sequence over communication diagram? Time ordering and call stack depth are clearer for request/response.
  2. Failure teaching: missing return/timeout messages hide real production hangs — always show the failure path once.
  3. Drill: login with SSO — Client→App→IdP→App→Client; mark redirect vs back-channel.
🤖 Don't fully get this? Learn it with Claude

Stuck on Sequence diagram? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Sequence diagram** (OO & Low-Level Design) and want to truly understand it. Explain Sequence diagram from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Sequence diagram** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Sequence diagram** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Sequence diagram** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes