UML Sequence diagram Tutorial
Sequence diagrams are part of the Unified Modelling Language (UML) that aims to standardize visual representation of systems design. It is the most popular interaction diagram in the field of software engineering.
What is a Sequence diagram?
In UML, a sequence diagram is a visual representation of the interaction between two or more systems. It more specifically shows the messages the systems exchange, and in what order. Sequence diagrams may also be called event diagrams or event scenarios.
Purpose of Sequence diagrams
- Model high-level interaction between multiple systems
- Visualize complex procedures
- Model complex API call sequences
- Explain how a chain of events impacts a system
- Understand how multiple services interact in a micro-services architecture
How to read a Sequence diagram?
The horizontal axis of a Sequence diagram shows the systems that are involved in the interaction and the vertical axis represents time.
The diagram should be read from top (older interactions) to bottom (most recent interactions).
The vertical axis, or time axis, is not representative of the duration of the interaction, it only specifies the order in which the interactions take place.
Benefits of Sequence diagrams
- Sequence diagrams are language neutral
- They are a common language that coders and non-coders understand
- UML Sequence diagrams facilitate communication within a team and accross multiple teams
Sequence diagram examples
The following Sequence diagram is directly taken from Google's documentation on OAuth 2.0 and shows how to integrate OAuth to your app:
Sequence diagram notation
A lifeline represent a participant in the interaction. It is visualized by a vertical dashed line with the participant's name at the top. Lifelines are spread horizontally across the diagram.
Messages are depicted using arrows, they represent an interaction between two participants.
Synchronous messages use a solid arrow head, they are used when the sender has to wait for the receiver to send a response to continue. The response message uses a dashed line as shown in the example bellow.
Asynchronous messages use a lined arrow head, they do not require a response from the receiver to continue with the interaction.
In some scenarios a participant might need to send a message to itself, those messages are called self-messages and are represented by a U shaped arrow.
Sometime we want to highlight messages latency. Duration messages are messages that take some time to transit. Duration messages are shown using a tilted arrow.
A thin rectangle over a lifeline represent the time a participant is active and performing an operation. The top of the rectangle is the beginning of the operation and the bottom the end.
How to make a sequence diagram?
You can use any drawing application to draw simple shapes and create a sequence diagram, or you can use a dedicated tool like GraphUp to build any type of sequence diagram without having to drag-n-drop shapes, resize, and align things yourself.
The benefits of using a tool like GraphUp also include the ability to share and integrate your sequence diagrams in one click across many platforms including Notion, GitHub, Jira, and Confluence.Start building now!