UML sequence diagrams
The behaviour diagram people actually draw. Participants across the top, time running down, and every message in the order it happens - including the branches, the loops, and the calls that fail.
15 min readUML 2.5.18 of 35
The short answer
- A sequence diagram answers what happens, in what order, between whom. Time runs downwards, and vertical distance carries no information about duration.
- A filled arrowhead means the caller blocks; an open one means it moved on. That single distinction is the most useful thing the notation tells you about a distributed system.
- Conditions and repetition are combined fragments - alt, opt, loop, par, ref - each a box with an operator in its top-left tag.
- Once the happy path is drawn, the failures become countable: ask of every message what happens if there is no reply, if the reply is a failure, and if it arrives twice.
01What it shows#
A sequence diagram answers one question precisely: what happens, in what order, between whom. It is the diagram you draw when two people disagree about which service calls which, or when a flow crosses four systems and nobody has the whole path in their head.
The layout does all the work. Participants sit across the top. Time runs downwards - not left to right, and not to scale. A message lower on the page happens after a message higher on the page, and that is the entire reading rule.
02Lifelines, activations, messages#
Three pieces of furniture, and everything else is a variation on them.
A lifeline is the head at the top plus the dashed vertical line running down from it. The head names the participant. It can be a class name, an object (: Checkout), an actor drawn as a stick figure, or a role with a stereotype like «boundary» or «control». Whichever you pick, be consistent down the whole diagram.
An activation bar - sometimes called an execution occurrence - is the thin rectangle laid over the lifeline. It marks the span during which that participant is doing something. Nested bars mean a participant called back into itself. Activations are optional in UML, and they are worth drawing: they make it obvious that Checkout is still waiting while the gateway works.
A message is the horizontal arrow. Its style says what kind of call it is, and that is the part worth memorising.
03The message kinds#
| Element | Notation | What it means |
|---|---|---|
| Synchronous | Solid line, filled arrowhead. The caller blocks until it gets a reply. An ordinary method or a blocking HTTP call. | |
| Asynchronous | Solid line, open arrowhead. The caller carries on immediately. Publishing to a queue or firing an event. | |
| Reply | Dashed line, open arrowhead. The return. Label it with what comes back, not with the word "return". | |
| Create | Dashed arrow landing on the head of a lifeline that starts partway down. Marked «create». | |
| Destroy | a cross at the lifeline's end | The participant ceases to exist; its lifeline stops at the cross. |
The filled-versus-open arrowhead distinction is the one that carries real weight. It is the difference between "the caller is now blocked" and "the caller moved on", and it is the single most useful thing a sequence diagram tells a reader about a distributed system.
04Branching: combined fragments#
Real flows have conditions and repetition. UML handles both with a combined fragment: a box drawn around a run of messages, with an operator in a tag at its top-left corner.
alt- alternatives. Split by a dashed line into compartments, each with a guard in square brackets. Exactly one runs. This is an if/else.opt- optional. One compartment with a guard; it runs or it does not. This is an if with no else.loop- repetition. The guard gives the condition or the bounds, as inloop [1..*]orloop [while more pages].par- parallel. Compartments run concurrently, in no guaranteed order.ref- a reference to an interaction defined on another diagram. This is how you keep one sequence diagram from growing to three pages.critical- a region that must not be interleaved with anything else.
05The frame, gates, and messages from nowhere#
Everything above sits inside a box that most diagrams draw and few readers notice: the interaction frame, a rectangle around the whole diagram with a tag in the top-left corner reading sdand the interaction's name. It looks like decoration and it is not - it is what gives the interaction a name, which is what makes ref possible. Without it you cannot cut a long flow into pieces, which means every flow has to fit on one page.
| Element | Notation | What it means |
|---|---|---|
| Frame | sd AuthorizePayment | The box around the diagram and the name of the interaction inside it. What a ref on another diagram points at. |
| Gate | an arrow ending on the frame | A message that crosses the frame boundary rather than starting or ending on a lifeline. It is the parameter list of the interaction: this is how a ref receives and returns anything. |
| Found message | a filled circle at the tail | Arrives from a sender the diagram does not model - a user click, a scheduler, a webhook. Honest, and far better than inventing a lifeline for the outside world. |
| Lost message | a filled circle at the head | Sent to a receiver the diagram does not model, or genuinely never arrives. Rare on a design diagram, useful on one describing a failure. |
| Duration constraint | { < 200ms } | A brace-delimited constraint spanning two points on a lifeline. The one way a sequence diagram can say anything about time, since vertical distance says nothing. |
| State invariant | { order = PLACED } | A condition written on a lifeline that must hold at that point. Useful directly above a message whose whole reason for existing is that condition. |
The fragment list in the previous section is the working set, not the whole set. Four more operators exist and three of them earn their place occasionally: break abandons the rest of the enclosing fragment when its guard holds, which is the natural shape of an early return on error; strict forces the order of its compartments where plain seq leaves them loose; neg marks an interaction that must not happen, which is a way of writing a negative test into a picture. assert, ignore and consider belong to formal specification work and are safe to skip until something forces them on you.
06Reading the failure paths out of it#
The most valuable thing a sequence diagram does is not documenting the happy path. It is that once the happy path is on a page, the failures become countable - and a flow crossing four systems has a lot more of them than anybody estimates from memory.
Walk down the diagram and ask three questions of every message, in order. The answers are your extension paths, and each one is either a fragment you should draw or a decision somebody needs to make.
- What if there is no reply? Every synchronous message is a place the caller can block forever. Somewhere there is a timeout value; if nobody in the room knows what it is, that is the finding. Draw it as an
altwith a[timeout]guard, and the number goes on the diagram where it can be argued with. - What if the reply is a failure? Distinct from no reply, and treated identically by an alarming amount of production code. A declined authorization and a dead acquirer need different handling, and the diagram is where that difference becomes visible.
- What if this is delivered twice?Ask it of every asynchronous message, because queues redeliver and clients retry. If the answer is "the customer is charged twice", you have found the idempotency requirement that was not in the ticket.
Then read the diagram once more, backwards, for the question the forward pass never catches: what has already happened that now has to be undone?A failure at the fourth message leaves the first three's effects in place. That is the compensation logic, and a sequence diagram is the cheapest place in the world to discover you need some.
07When to draw one#
Reach for it when
- A flow crosses several services and the call order is not obvious
- You need to settle an argument about who is responsible for calling whom
- Documenting a protocol, a handshake, or an integration for another team
- Working out where the failure modes are - a diagram makes missing error paths visible
Reach for something else when
- The interaction is two participants and three messages - just write the sentence
- You care about elapsed time or deadlines - use a timing diagram
- The structure, not the order, is the question - use a class or component diagram
- The flow is mostly branching logic - an activity diagram will be far more readable
A sequence diagram is also the most effective UML artefact for reviewing a design before it is built, because it forces the awkward questions into the open. What happens if the gateway times out? Who retries? Is that call blocking? You cannot draw the diagram without answering them.
08Common mistakes#
- Every arrow drawn solid-filled. If everything looks synchronous, the diagram has thrown away its most useful distinction. Use open heads for fire-and-forget.
- Reply arrows for everything. A reply to a synchronous call is often implied and can be omitted. Draw it when the returned value matters.
- Mixing abstraction levels. A lifeline for a whole payment platform next to a lifeline for a single helper class. Pick one altitude.
- No error path. The happy path alone is the least interesting half. An
altwith the timeout branch is what makes the diagram worth reviewing. - Twenty lifelines. Past roughly seven the diagram stops fitting on a screen and starts being scrolled rather than read. Split it and use
ref.
In one line each
- 01Participants across the top, time downwards; vertical distance is not duration.
- 02Filled arrowhead is synchronous and blocking, open arrowhead is asynchronous.
- 03Dashed arrows are replies; dashed into a lowered head is «create».
- 04Activation bars show who is busy, and are worth the effort.
- 05alt, opt, loop, par and ref cover branching; never nest more than two deep.
- 06Draw the failure path - it is the half that makes the diagram useful.
09Common questions#
What is a lifeline in a sequence diagram?
The dashed vertical line under each participant, representing that participant's existence over time. Time runs downwards, so a message drawn lower on the page happens later than one above it.
What is the difference between a synchronous and an asynchronous message?
A synchronous message has a filled solid arrowhead and means the sender waits for the call to return. An asynchronous message has an open line arrowhead and means the sender carries on immediately. The reply to a synchronous call is a dashed line with an open arrowhead.
What do alt, opt, loop and par mean?
They are combined fragments: labelled boxes wrapping part of the interaction. alt is a branch with guarded alternatives, opt is a single branch that may not run, loop repeats its contents, and par means its regions may interleave. The label sits in the pentagon at the top left of the box.
What is an activation bar?
The thin rectangle drawn on a lifeline while that participant is doing something, formally an execution specification. It starts when the participant receives a message and ends when it returns, which is what makes nested calls visible as stacked bars.
When should I use a sequence diagram instead of a communication diagram?
Use a sequence diagram when the order of messages is the point: a protocol, a failure path, a timeout. Use a communication diagram when the structure is the point, meaning who is connected to whom. The two carry the same information and differ only in layout.
In this series
- 01What is UML?
- 02UML symbols
- 03Choosing a diagram
- 04Class diagrams
- 05Class diagram examples
- 06How to draw a class diagram
- 07Class diagram symbols
- 08Sequence diagrams
- 09Sequence diagram examples
- 10How to draw a sequence diagram
- 11Use case diagrams
- 12Use case examples
- 13Activity diagrams
- 14Activity examples
- 15State machine diagrams
- 16State machine examples
- 17Component diagrams
- 18Component examples
- 19Drawing a component diagram
- 20Component symbols
- 21Deployment diagrams
- 22Deployment examples
- 23Object diagrams
- 24Package diagrams
- 25Composite structure diagrams
- 26Communication diagrams
- 27Sequence vs communication
- 28Timing diagrams
- 29Interaction overview diagrams
- 30Profile diagrams
- 31UML with AI
- 32E-commerce example
- 33Banking example
- 34Microservices example
- 35AWS example
Related reading
Foundations
Behaviour diagrams
Behaviour diagrams
Structure diagrams
Foundations
Behaviour diagrams