Sequence basics

What a sequence diagram shows, the parts it's made of, when to draw one and how to start one.

A sequence diagram shows one interaction between people and systems. It shows who takes part and the messages they send each other, in order, with time running down the page.

Use one for a sign-in, a payment, an API call or a webhook: anything where the order of messages matters more than who owns each step. Each element below comes with the sequence code that draws it.

A checkout payment sequence diagram in the editor: its sequence code on the left, and on the right the diagram with Shopper, Shop, Payments and Bank as lifelines, numbered messages, and an alt box for the 3-D Secure challenge.

Participants and lifelines

A participant is a person or a system that sends or receives messages. Each one is a column, with its head at the top and a dashed lifeline running down.

The head's shape says what kind of participant it is:

KindDrawn asUse it for
ParticipantA boxA system, service or role
ActorA stick figureA person
DatabaseA cylinderA data store
QueueA cylinder on its sideA queue or topic
CollectionsStacked boxesSeveral of the same thing, such as workers
BoundaryA UML circleWhere the system meets the outside, such as a screen or an API
ControlA UML circleLogic that coordinates the others
EntityA UML circleData the system keeps, such as an order

A box round neighbouring participants labels them as a group, such as a third party.

Sequence code
actor Shopper
participant Shop
database Orders DB

Shopper->Shop: Place order
Shop->Orders DB: Save order

Participants appear left to right in the order the code first names them. Put the one who starts the interaction first.

Messages: call, reply and async

A message is an arrow from one lifeline to another, labelled with what is sent. There are three kinds:

  • A call (->) is a solid line with a filled head. The sender waits for an answer.
  • A reply (-->) is a dashed line back to the caller. It answers an earlier call.
  • An async message (->>) is a solid line with an open head. Nobody waits, as with an event or a queue.
Sequence code
participant Client
participant API
participant Queue

Client->API: Create order
API-->Client: 201 Created
API->>Queue: Order created

A participant can send a message to itself, such as a step it does on its own.

A message's ends can say more:

  • A head at both ends means the message goes both ways.
  • A cross at the end means it fails.
  • A filled circle at the end means it's lost on the way. At the start, it means the message comes from someone the diagram doesn't show.
  • A message can come from outside the diagram, or go out of it.
  • A message can create its receiver. The receiver's head is then drawn level with the message.
  • A lifeline can end in a cross.
Sequence code
[->Shop: Refund requested
Shop<->Payments: Check order
Payments->x Bank: Refund card
Shop->Worker **: Archive order
destroy Worker

Activation bars

An activation bar is a narrow box on a lifeline. It shows that the participant is busy, usually handling a request while it waits on others.

Add ++ to the message that starts the bar and -- to the one that ends it.

Sequence code
participant Client
participant API
database DB

Client->API ++: GET /orders/42
API->DB: Load order 42
DB-->API: Order
API-->Client --: 200 OK

Add bars for the main service handling a request, not on every message.

Fragments

A fragment is a frame around some messages, with a tab naming its kind and a condition. Use one when messages only happen in some cases, or happen more than once.

KindWhat it means
altAlternatives: one branch is taken. Each branch after the first starts with else.
optOptional: happens only if the condition holds.
loopRepeats while the condition holds. Say the limit, such as "up to 3 times".
parParallel: the branches run at the same time. Each branch after the first starts with and.
breakLeaves the enclosing block early, such as after the last failed retry.
criticalRuns without interruption. Each other outcome starts with option.
groupA labelled box, with no meaning of its own.
Sequence code
participant Shop
participant Payments

Shop->Payments: Charge card
alt card accepted
  Payments-->Shop: Payment confirmed
else card declined
  Payments-->Shop: Declined
end

Only alt, par and critical have more than one branch. Write each condition as a short state, such as "cache hit" or "card declined".

UML has seven more operators, for diagrams that say exactly which orders of messages are allowed. Each has one branch and an optional label.

KindWhat it means
seqWeak sequencing: messages on different lifelines may happen in any order.
strictStrict sequencing: the messages happen exactly in the order drawn.
negInvalid: these messages must never happen.
ignoreThe messages named in its label may happen here and don't matter.
considerOnly the messages named in its label matter here.
assertAssertion: this is the only valid continuation.
regionCritical region: nothing else interleaves with these messages.

The app draws the tab in the frame's top-left corner, in the gap left of the first lifeline inside. The tab ends at that lifeline, or at the activation bar on it. The first condition starts just right of the lifeline and its bars.

The frame leaves at least as much room right of its last lifeline as left of its first. The app draws it over the lifelines and bars it crosses, so its edges stay whole.

Notes, refs, dividers, delays and numbering

  • A note holds a fact such as a timeout or a security rule. It sits over one or more participants, or to the left or right of one.
  • A ref is a frame over some participants. It stands for an interaction drawn in another diagram.
  • A divider splits a long interaction into phases, with a label across the whole diagram.
  • A delay shows that time passes. The lifelines turn dotted for a row, with an optional label such as "2 days later".
  • Numbering puts 1, 2, 3 in front of the messages, so you can refer to them. It can start at any number and count in steps, such as 10, 20, 30.
Sequence code
autonumber
participant App
participant Auth server

== Sign in ==
App->Auth server: Authorization request
Auth server-->App: Authorization code
note over App, Auth server: State checked on every request

When to use a sequence diagram

Draw a BPMN process when the question is "what work happens, who does it, and what comes next". Draw a sequence diagram when the question is "what do these systems say to each other, in what order, and what happens when one fails".

A processA sequence diagram
FollowsThe work, through decisions and hand-offs, often over daysThe messages in one interaction, often over seconds
Columns or lanesOne lane per roleOne column per person or system, with every request and answer between them
Good forPeople agreeing how work runsDevelopers agreeing how a feature or an integration behaves

The two work well together. A service task in a process, such as "Charge card", can have a sequence diagram of its own that shows the calls behind it.

Keep each sequence diagram to one scenario, with about 3 to 8 participants and up to 30 messages. Draw a second diagram for a detailed part, or for a second scenario such as sign-up next to sign-in.

Make a sequence diagram

There are five ways to start one:

  • In the Diagrams panel, select New diagram (the + button) and choose Sequence diagram.
  • Press ⌘ K (Ctrl K on Windows and Linux) and run New sequence diagram.
  • Select Templates in the rail. Under Sequence diagram are Sign in with Google and Checkout payment, and View all adds API with cache and Webhook delivery. Selecting one creates a new diagram from it.
  • In New diagram, choose Import Mermaid, PlantUML or sequence code file…. See Import a file.
  • Paste Mermaid, PlantUML or sequencediagram.org code into the Sequence code pane. See Code from other tools.

A new diagram is called "Untitled sequence". On its empty canvas, Describe it opens the assistant, Add participant adds the first column, and Use a template shows the sequence templates. You can also type the diagram in the Sequence code pane beside the canvas.

Next

Edit on the canvas, learn sequence code, or let the assistant draft a diagram for you.

On this page