npmstart.
Exercises
中文

Explain a request round trip with a sequence diagram

Separate the user, browser and server, with explicit success and error responses.

Mermaid Live EditorReviewed 2026-11-10Original example exercise

What you will make

A sequence diagram with actors, message directions and failure behavior.

Before you begin
The Mermaid editor. No real API or account is required.

Menu names can change. The upstream demo is externally operated and may differ from the pinned local version.

Identify participants before messages

The exercise models saving a note with a user, browser and server. Lifelines represent separate responsibilities, not separate web pages. The browser collects input and displays feedback; the server receives a request and responds. The sample has no live service, and does not attempt to describe authentication, transactions or concurrency.

Describe directional messages

Read from the save click downward. Solid arrows express outgoing messages and dashed arrows express responses in this example. Name actions or results rather than writing only data. Vertical order matters: the browser cannot claim that the server saved the note before receiving the relevant response.

Example source
sequenceDiagram
  actor User
  participant Browser
  participant Server
  User->>Browser: Save note
  Browser->>Server: Send note
  alt Valid input
    Server-->>Browser: Saved record
    Browser-->>User: Show saved status
  else Invalid input
    Server-->>Browser: Validation error
    Browser-->>User: Keep draft and explain
  end

Include an alternative result

The alt and else blocks separate accepted input from a validation failure. Keeping the draft and explaining the problem is the behavior chosen for this exercise, not an automatic property of every system. For a real app, discuss timeouts, repeated submissions and permission failures separately. Finish one useful error branch before modeling all possible exceptions.

Make system boundaries visible

A changed button state proves only that the interface changed. It does not by itself establish persistence. Use the diagram to ask which response supports the success message, where a reload reads from and who preserves input on failure. If the actual product uses only browser storage, replace the server lifeline with that storage boundary rather than inventing an API.

Use the diagram to review an implementation

Keep the source with the project brief. Ask the implementer to identify the outgoing request, error handling and success-state update in the code. Demonstrate invalid input and compare the interface with the failure branch. The diagram supports discussion and review; it does not supply authentication or a reliable persistence layer.

Check your result

  • Participants map to real responsibilities.
  • The success message follows the successful response.
  • The error branch states whether input is preserved.

Messages are hard to follow?

Reduce participants and clarify message names. Use a flowchart for choices and a sequence diagram for message order.

Sources and further reading

This exercise is original. Consult these primary sources for project behavior and syntax.