Sequence diagram: notation, examples and how to draw one

The notation, a filled-in example you can copy, and the Mermaid code that draws it.

A sequence diagram is a UML diagram that shows how people and systems exchange messages in one scenario, in the order they happen. Each participant gets a lifeline running down the page, and each message is an arrow from one lifeline to another, so you read it from top to bottom. To draw one, pick a single scenario, line the participants up left to right, then add the messages, replies and branches in time order.

Annotated sequence diagram of a coffee order between a customer and a coffee app, with eight numbered parts from participant to asynchronous message. Each part is described in the text version below.

Figure 1Parts of a sequence diagram. The five parts on a small coffee order, with the four message types numbered separately, so eight notes in all. Time runs down the page, and the line style and label tell you whether the sender waits.

What is a sequence diagram?Copied!Link to this section

A sequence diagram is an interaction diagram from UML, the Unified Modeling Language: it shows one scenario as messages passed between participants, ordered by time. Wikipedia sums it up as a diagram that “shows process interactions arranged in time sequence” (Wikipedia). Sequence diagrams are sometimes called event diagrams or event scenarios.

UML groups its 14 diagram types into structure diagrams and behavior diagrams, and the sequence diagram sits in the interaction subset of behavior diagrams with the communication, timing and interaction overview diagrams (Wikipedia, UML). The current standard is UML 2.5.1, published by the Object Management Group in December 2017 (OMG). For the other 13 types, see our overview of UML diagrams.

Visual Paradigm’s guide puts it plainly, time in a sequence diagram is about ordering, not duration (Visual Paradigm). Two arrows far apart may be a millisecond apart.

When should you use a sequence diagram?Copied!Link to this section

Use a sequence diagram when the question is who talks to whom, and in what order: designing an API call, explaining an integration with a payment provider, or finding the race in async code. A sequence diagram is the wrong tool when the question is what happens next in a process with many decisions. That’s a flowchart’s job.

Good fits:

  • Designing an endpoint before writing it, so the team agrees on which service calls which.
  • Explaining an integration to someone new: what you send a third party and what comes back.
  • Debugging async behavior, where code shows what can happen and the diagram shows what happens in order.
  • Reviewing failure paths. If the diagram has no declined card, timeout or retry, the design probably doesn’t either.

What are the parts of a sequence diagram?Copied!Link to this section

A sequence diagram has five parts: participants, lifelines, messages, activation bars and combined fragments. Participants sit along the top, each with a lifeline dropping down the page. Messages are arrows between lifelines, activation bars show who is busy, and combined fragments are frames that add branches and loops. Messages come in four common types:

Message type

How it’s drawn

What it means

Synchronous

Solid line, filled arrowhead

The sender waits for the answer, like a function call

Asynchronous

Solid line, open arrowhead

The sender carries on without waiting, like an event on a queue

Reply

Dashed line, open or filled arrowhead

A result going back to whoever asked

Self message

An arrow that loops back to its own lifeline

A participant calling itself

UML has a few rarer messages too: a create message that starts a new participant’s lifeline partway down, a destroy message that ends a lifeline with an X, and found and lost messages that come from, or go to, somewhere outside the diagram.

What do the arrows mean in a sequence diagram?Copied!Link to this section

The arrowhead and line style tell you whether the sender waits. In Wikipedia’s words, “Solid arrow heads represent synchronous calls, open arrow heads represent asynchronous messages, and dashed lines represent reply messages” (Wikipedia). A synchronous caller “must wait until the message is done”; an asynchronous one “can continue processing and need not wait for a response”.

The dashed line is what makes a reply: UML 2.5.1 says a reply “has a dashed line with either an open or filled arrow head” (UML specification, p. 577 (page 619 of the PDF)), and the figures here use the filled one. Some guides draw asynchronous messages as dashed lines too. In UML that reads as a reply, so a dashed arrow with no request before it looks like an answer to nothing.

The figures in this guide are live boards whose sequence diagrams have one arrowhead, filled, so they mark each asynchronous message in its label instead, as (async). When you draw your own, the open arrowhead or the label both work, as long as the whole diagram uses one.

What is an activation bar in a sequence diagram?Copied!Link to this section

An activation bar is the thin rectangle on a lifeline that shows a participant is busy handling a message. It starts when the message arrives and ends when the participant sends its reply or finishes. UML’s formal name for it is an execution specification (Wikipedia). Activation bars are optional, but they make it obvious who is holding things up.

What are combined fragments in a sequence diagram?Copied!Link to this section

A combined fragment is a frame around a group of messages, with an operator in its top left corner that says how they run. Conditions, called guards, go in square brackets, such as [card approved]. IBM’s guide compares alt to if-then-else logic and opt to a simple if-then statement (IBM Developer). The four you’ll use most:

  • alt: alternatives. Only the section whose guard is true runs, like if and else.
  • opt: optional. The messages run only if the guard is true, like an if with no else.
  • loop: the messages repeat while the guard is true, or a set number of times.
  • par: the sections run in parallel, in any interleaving.

UML has more operators, such as break for an exit from the scenario, critical for a section that can’t be interrupted, and ref for a reference to another sequence diagram.

Sequence diagram example: ordering a coffee aheadCopied!Link to this section

Here’s a filled-in sequence diagram for a coffee shop app. A customer orders a flat white for pickup, the orders API charges the card, and on success it sends the order to the barista’s tablet. It covers two outcomes in one alt fragment: the card is approved, or it’s declined.

Sequence diagram of a coffee order between a customer, a coffee app, an orders API, a payment provider and a barista tablet, with an approved and a declined branch and the asynchronous New order #142 message as the takeaway. The messages are listed in the text version below.

Figure 2Sequence diagram example: ordering a coffee ahead. New order #142 (async) is the message to notice: it's asynchronous, so the orders API confirms the order without waiting for the barista. The board is the Mermaid code further down, so you can copy either one.

How do you read a sequence diagram?Copied!Link to this section

Read a sequence diagram from top to bottom, one arrow at a time, and say each one out loud as a sentence: “the coffee app sends POST /orders to the orders API, and waits”. When you reach a frame, read its guard first, then only the section that applies. Inside an alt frame only one section runs, so an activation bar that ends at a reply is drawn through both sections and stops at the reply in the last one.

In the example, the first three messages always happen. Then the alt frame splits: on an approved card, the orders API sends the order to the barista and confirms it to the app; on a declined card, it returns 402 and the app asks for another card. New order #142 is the message worth a second look. The orders API doesn’t wait for the barista to accept the order, so the customer sees “Ready in 5 min” straight away. If the tablet is offline, nobody is told. That’s the kind of gap a sequence diagram makes visible before it ships.

How do you draw a sequence diagram?Copied!Link to this section

To create a sequence diagram, pick one scenario, put its participants in a row in the order they first act, then add the messages top to bottom with a reply under each synchronous call. Add frames for branches last, and check the diagram against the code or the people who own each participant.

Choose the scenarioCopied!Link to this section

  1. Write the scenario in one sentence, such as “a customer orders a coffee ahead and pays by card”.
  2. Name its trigger: the person or system whose first message starts it.
  3. Decide which failure paths belong in this diagram and which get their own.

Lay out the participantsCopied!Link to this section

  1. Put the trigger on the left, drawn as an actor if it’s a person.
  2. Add each other participant to the right, in the order it’s first called.
  3. Draw a lifeline down from each one.

Add the messages and branchesCopied!Link to this section

  1. Draw each message as an arrow below the last, with a label that names the call and the detail that matters.
  2. Pick the arrowhead: filled if the sender waits, open if it doesn’t.
  3. Add a dashed reply under each synchronous call that returns something.
  4. Add activation bars where it helps to see who is busy.
  5. Wrap branches in alt or opt and repeats in loop, each with its guard in brackets.
  6. Walk the diagram with whoever owns each participant, and fix any arrow that waits when the code doesn’t.

In Whimsical, press S for diagram shapes and pick the sequence diagram actor, or search for it in the All tools menu with /. You can also paste Mermaid code onto a board, as shown further down. Getting started with sequence diagrams has the details, and the UML sequence diagram template is a finished example to start from.

What makes a good sequence diagram message label?Copied!Link to this section

A good message label names what is asked or sent, with the detail that matters: the route, the amount, the order number or the status code. Most weak labels are generic verbs like “request” or “response”, which tell the reader an arrow exists but not what it carries. Here are four labels as they often get written, and as the example writes them:

Coffee app → Orders API: Send request

Call: Coffee app → Orders API: POST /orders

Orders API → Payment provider: Payment

Call: Orders API → Payment provider: Charge card $4.50

Orders API → Barista tablet: Update

Async message: Orders API → Barista tablet: New order #142 (async)

Orders API → Coffee app: Response

Reply: Orders API → Coffee app: 402 Payment failed

What’s the difference between a sequence diagram and a flowchart?Copied!Link to this section

A sequence diagram shows who sends what to whom, in order, for one scenario. A flowchart, or its UML cousin the activity diagram, shows the steps and decisions of a process without saying which participant does each step. Pick by the question you’re answering: “who talks to whom?” needs a sequence diagram, “what happens next?” needs a flowchart.

Decision diagram that matches what you need to show to a sequence diagram, a flowchart or activity diagram, a communication diagram or a state machine diagram, with the sequence diagram as the first answer. The answers are listed in the text version below.

Figure 3Which diagram should you draw: sequence, flowchart, communication or state? One question, four answers. If your question is who talks to whom, and in what order, draw a sequence diagram; if it's what happens next, a flowchart.

Here’s how the sequence diagram compares with the two you’ll choose between most often:

Sequence diagram

Flowchart or activity diagram

Communication diagram

Shows

Messages between participants, in time order

Steps and decisions in a process

Links between participants, with numbered messages

Laid out by

Participants across, time down

Flow from step to step

Freely, like an object diagram

Best for

API calls, integrations, async behavior

Business processes, algorithms

Seeing who is connected to whom

Weak at

Many branches and decisions

Who does each step, unless you add swimlanes

Following the order of messages

A communication diagram carries much of the same information as a sequence diagram, but keeps order only through numbers on each message. Wikipedia’s comparison: communication diagrams show which elements interact better, while sequence diagrams show “the order in which the interactions take place more clearly” (Wikipedia).

How do you make a sequence diagram from Mermaid code?Copied!Link to this section

To make a sequence diagram from Mermaid code, start with the sequenceDiagram keyword, declare each participant, then write one message per line in the form Sender->>Receiver: label. Mermaid, a text syntax for diagrams, uses ->> for a solid arrow, -->> for a dotted reply, -) for an asynchronous message, + and - for activations, and alt, opt, loop and par for frames (Mermaid docs). This is Figure 2 as Mermaid:

sequenceDiagram actor C as Customer participant A as Coffee app participant O as Orders API participant P as Payment provider participant B as Barista tablet C->>A: Order a flat white A->>+O: POST /orders O->>+P: Charge card $4.50 alt card approved P-->>O: Approved O-)B: New order #142 (async) O-->>A: 201 Created, #142 A-->>C: Ready in 5 min else card declined P-->>-O: Declined O-->>-A: 402 Payment failed A-->>C: Try another card end

Paste that code onto a Whimsical board with Command + V (Mac) or Control + V (PC) and you get an editable sequence diagram with notes, frames and activation bars, not a picture (Mermaid article). It works the other way too: select the diagram and choose Copy as… → Mermaid to take it back out as code for a pull request or a README.

Figure 2 is that code, pasted: all five participants, the alt frame with its declined branch, both activation bars and all ten labels come through. One thing doesn’t: -) pastes with the same filled arrowhead as ->>, hence the (async) in its label.

Can ChatGPT create sequence diagrams?Copied!Link to this section

Yes. ChatGPT, Claude and coding agents like Cursor write good Mermaid sequence diagrams from a description or straight from code, because calls, routes and events are all there in the source. We’d check two things before sharing one: whether each arrow really waits, which a model can’t always tell from the code, and whether the error paths are real or invented.

With the Whimsical MCP, the assistant draws the sequence diagram straight onto a Whimsical board instead of handing you code to paste. In Cursor, Claude Code or another coding agent with the MCP connected, this prompt asks for the same notation as the example above:

Read the code for [the endpoint or feature, such as POST /orders] in this repository and write its sequence diagram as Mermaid sequenceDiagram code, then draw it on a new Whimsical board. Put whoever starts it on the left, then each service, queue and database in the order it's first called. Arrows: ->> when the sender waits, -) when it doesn't, -->> for replies. Label every message with the real route, call or event name and the detail that matters, such as an amount or a status code. Wrap error paths in alt/else and retries in loop, each with its condition. If you can't tell from the code whether a call waits for its answer, list it as an open question instead of guessing.

Frequently asked questionsCopied!Link to this section

What are the 7 types of structure diagrams in UML?

The seven UML structure diagrams are the class, component, composite structure, deployment, object, package and profile diagrams. They show what a system is made of. A sequence diagram isn’t one of them: it’s a behavior diagram, in the interaction group with the communication, timing and interaction overview diagrams.

What is a system sequence diagram?

A system sequence diagram treats the whole system as one black box, a single lifeline called System, and shows only the messages that cross its boundary from the actors. It’s drawn early, for a use case’s main success scenario, before anyone decides which classes or services sit inside the box.

Does a sequence diagram show how long each step takes?

No. A sequence diagram shows the order of messages, not their duration: a long gap between two arrows doesn’t mean a long wait. When timing matters, write it on the diagram as a note, or draw a UML timing diagram, which is built around timing constraints.

What does a dashed line mean in a sequence diagram?

In UML, a sequence diagram uses dashed lines for two things. The vertical dashed line under each participant is its lifeline, the participant’s existence over time, though some tools, including the figures here, draw it solid. A horizontal dashed arrow is a reply message, carrying a result back to whoever sent the request.

How many sequence diagrams does a feature need?

Draw one sequence diagram per scenario worth explaining. A short branch, like the declined card in the example above, fits inside the same diagram as an alt fragment. A branch with its own long chain of messages, such as a refund, is clearer as a separate diagram than as a frame inside a frame.

Map your own call flow

The UML sequence diagram template is a finished example: a task runner's run() call across six lifelines, with guards, an exception and a retry. Copy it and swap in your own participants.

Open the UML sequence diagram template

Related articles