Preview and edit six Mermaid sequence diagram examples, from API responses and asynchronous jobs to activation bars and optional interactions. Use the syntax reference, adapt the code, and open your diagram in the editor to share or export.
Your code, theme, and diagram configuration travel with the link. Flowchart spacing uses the Standard preset.
Sequence examples for API and service workflows
API request sequence example
Follow a browser request through an API to a database and back. Use this when explaining which service is responsible for each step.
sequenceDiagram
participant Browser
participant API
participant Database
Browser->>API: Request data
API->>Database: Query records
Database-->>API: Return records
API-->>Browser: Render response
Solid messages carry requests and dashed messages show replies in this example.
Rename the messages to actual operations; include only details relevant to the interaction being documented.
Document the two outcomes of a protected API call. Both branches respond to the client so the failure case is visible.
sequenceDiagram
autonumber
participant Client
participant API
Client->>API: GET /reports
alt Token valid
API-->>Client: 200 Report data
else Token missing or expired
API-->>Client: 401 Sign in required
end
alt and else represent alternative outcomes, not two responses sent for one call.
autonumber adds message numbers for discussion in a review.
Show when an API is actively handling a request. The activation bar starts on receipt and ends after the response.
sequenceDiagram
actor User
participant API as Web API
User->>API: Load profile
activate API
Note right of API: Read profile
API-->>User: Profile details
deactivate API
An alias gives a participant a readable display name without changing its ID.
Pair activate and deactivate for the same participant.
Add a diagnostic log only when tracing is enabled. The response stays outside the optional block because it is always sent.
sequenceDiagram
participant Client
participant API
participant Log
Client->>API: Fetch status
opt Tracing enabled
API->>Log: Record request
end
API-->>Client: Current status
Use opt for an optional section without a competing branch.
Use alt / else when the outcome has mutually exclusive alternatives.
Mermaid Viewer keeps the workflow focused: paste Mermaid code, preview the rendered diagram, choose a theme or layout preset, then export PNG/SVG when the result is ready for documentation or slides.