BossaBox

This is the playbook for engineering-playbook

Sequence Diagrams

Purpose

This document is intended to provide a baseline understanding for what, why, and how to incorporate Sequence Diagrams as part of an engagement. Regarding the how, the section at the bottom will provide tools and plugins to streamline as much as possible when generating Sequence Diagrams through VSCode.

Wikipedia defines UML Sequence Diagrams responsible to:

depict the objects involved in the scenario and the sequence of messages exchanged between the objects needed to carry out the functionality of the scenario

What is a scenario? It can be:

What is a message in this context? It can be:

What is an object in this context? It can be:

Essential Takeaways

A Sequence Diagram should:

It is okay for a single Sequence Diagram to have many different scenarios if they have some related context that merits them being grouped.

Another important thing to keep in mind, is that the objects involved in a Sequence Diagram should refer to existing Components from a Component Diagram.

There are 2 areas where complexity can result in an overly “crowded” Sequence Diagram, making it costly to maintain. They are:

  1. Large number of objects / components involved in a particular scenario
  2. Capturing all the possible “failure” situations that a scenario may encounter

Large Number of Objects

A Sequence Diagram typically starts with an end user persona performing an action, and then shows all the various components and request/data transfers that are involved in that scenario. However, more often than not, the complete end-to-end flow for that scenario may be too complex in order to capture within a single Sequence Diagram.

When this level of complexity occurs, consider creating separate sub-scenario Sequence Diagrams, and using it as an object in a particular Sequence Diagram. Examples for this are “Authentication” or “Authorization”. Almost all user persona scenarios will have several objects/components involved in either of these sub-scenarios, but it is not necessary to include them in every Sequence Diagram once the sub-scenarios have a stand-alone Sequence Diagram created.

Be sure that when using this approach of sub-scenarios to give it a name that encapsulates what the sub-scenarios is performing, and to determine the appropriate “actor” and “action” that initiates the sub-scenarios.

The combination and story telling between these end user Sequence Diagrams and the sub-scenarios Sequence Diagrams can greatly improve readability by distributing the level of complexity across multiple diagrams and take advantage of reusability of common sub-scenarios.

Handling Large Number of Failure Situations

Another factor of high complexity is the possible failure situations that a particular scenario may encounter. Each object / component involved in the scenario could have several different “failure” situations, which could result in a very crowded and messy Sequence Diagram.

In order to make it realistic to manage all these scenarios, try to:

When to Create?

Because Sequence Diagrams represent a detailed overview of the behavior of the system, outlining the various messages/requests sent within the system, it is recommended to begin the creation of these diagrams from the beginning of an engagement. While updating it as the various communications between Components are introduced into the system. The risks of not creating Sequence Diagrams early on are that:

Because of the inherent granularity of the system, the Sequence Diagrams won’t have to be updated as often as Class Diagrams, but may require more maintenance than Component Diagrams. Things that might merit updating a Sequence Diagram could be:

Examples

Place Order Scenario:

image

Facebook User Authentication Scenario:

image

Versioning

Because Sequence Diagrams are more expensive to maintain, it’s recommended to “publish” an image of the generated diagram often, whenever a new “use case” or “scenario” is identified as part of the system behavior or requirements.

The most important element to these diagrams is to ensure that the latest version is accurate. If the latest diagram shows a sequence of communication between components that are no longer valid, then the diagram causes more harm than good.

The below approach can be used to assist the team on how often to update the published version of the diagram:

Depending on the tool being used, automatic versioning might be performed whenever an update to the Diagram is performed. If not, it is recommended to capture distinct versions whenever there is a particular customer need to have a snapshot of the project at a particular point in time. The hard requirement is that the latest diagram should be published and everyone should know how to access it as the customer hand-off approaches.

Resources