UML Diagrams

UML Sequence Diagrams

Show how objects interact over time through message exchanges. Essential for explaining system behavior in interviews.

12 min readEssential for Interviews

1Basic Elements

Sequence diagrams show interactions between objects over time. Time flows from top to bottom. Objects are shown as boxes with dashed lifelines.
Participant/Lifeline

Box at top, dashed line extending down representing object's existence.

Activation Bar

Thin rectangle on lifeline showing when object is active/processing.

Synchronous Message

Solid arrow with filled head. Caller waits for response.

Return Message

Dashed arrow back. Shows response to a call.

Sequence Diagram Notation

ClientServerDatabase1: request()2: query()dataresponseSolid arrow = sync callDashed arrow = return

2Message Types

TypeArrowDescription
Synchronous────▶Solid line, filled arrowhead. Caller blocks.
Asynchronous────>Solid line, open arrowhead. Caller continues.
Return- - -▶Dashed line. Response to a call.
Self-callArrow loops back to same lifeline.
Create- - -▶ ☐Dashed line to new object box.

3Combined Fragments

Fragments add control flow (loops, conditions) to sequence diagrams:

alt

Alternative - like if/else. Shows mutually exclusive paths.

opt

Optional - executes only if condition is true.

loop

Loop - repeats the enclosed interactions.

par

Parallel - shows concurrent execution.

Fragment Example: Login with Alt

UserAuthServiceDBlogin(user, pass)verify()alt[valid credentials]user datatoken[invalid]nullerror

4Interview Tips

Drawing Sequence Diagrams in Interviews
  • 1. Identify key actors/objects - Start with User, main services, database
  • 2. Focus on happy path first - Show main success scenario
  • 3. Add error handling if asked - Use alt fragments
  • 4. Keep it simple - Don't overcomplicate with every detail
  • 5. Number your messages - Makes it easy to discuss

5Interview Follow-up Questions

Interview Follow-up Questions

Common follow-up questions interviewers ask

6Key Takeaways

1Sequence diagrams show object interactions over time.
2Lifelines (dashed vertical) represent object existence.
3Activation bars show when an object is processing.
4Solid arrow = call, Dashed arrow = return.
5Use fragments for conditionals (alt), loops (loop), parallel (par).
6In interviews: show happy path first, add error handling if asked.