Mermaid exampleSequence Diagram

Web Request Lifecycle Sequence Diagram: CDN to Database

When a page is slow, the first question is where the time goes. This sequence diagram lays out every hop a single request takes, so performance discussions can point at a specific arrow instead of a vague "the backend".

  • http request sequence diagram
  • cdn cache diagram
  • request lifecycle
  • mermaid sequence diagram example
Web Request Lifecycle Sequence Diagram: CDN to DatabaseDatabaseCacheApp serverLoad balancerCDNBrowserDatabaseCacheApp serverLoad balancerCDNBrowseralt[Cache hit][Cache miss]alt[Static asset cached at edge][Dynamic request]GET /products/42200 from edge cacheForward requestRoute to healthy instanceGET product:42Product JSONSELECT product 42RowSET product:42 with 300s TTL200 HTMLResponse200 HTML
Open in editor → 25 linesrenders in GitHub, Notion, Obsidian

Mermaid code

sequenceDiagram
    participant B as Browser
    participant C as CDN
    participant L as Load balancer
    participant A as App server
    participant R as Cache
    participant D as Database
    B->>C: GET /products/42
    alt Static asset cached at edge
        C-->>B: 200 from edge cache
    else Dynamic request
        C->>L: Forward request
        L->>A: Route to healthy instance
        A->>R: GET product:42
        alt Cache hit
            R-->>A: Product JSON
        else Cache miss
            A->>D: SELECT product 42
            D-->>A: Row
            A->>R: SET product:42 with 300s TTL
        end
        A-->>L: 200 HTML
        L-->>C: Response
        C-->>B: 200 HTML
    end

Paste this into any tool that renders Mermaid, or into the editor to change the theme and export PNG or SVG. Syntax reference: Sequence Diagram guide.

What this diagram shows

Six participants run across the top: Browser, CDN, Load balancer, App server, Cache, and Database. The outer alt separates the two fates of a request at the edge: served from the CDN cache, or forwarded to origin. Inside the origin path, a nested alt shows the cache hit and the cache miss, including the SET that fills the cache after a database read. Dashed arrows (-->>) are responses, solid arrows (->>) are requests.

A sequence diagram is the right type here because order and nesting matter. The same system drawn as a flowchart would show the components but hide which calls happen inside which branch.

How to adapt it

  • Rename /products/42 and product:42 to one concrete request from your own app; a real URL makes the diagram easier to discuss than a placeholder.
  • Add activate A and deactivate A around the app server work to show how long an instance is busy.
  • Insert a Note over A,D: p95 = 40 ms line to attach measured latency to a hop.
  • Drop the CDN participant if your app has no edge cache; the diagram still reads correctly with five lanes.

FAQ

How deep can alt blocks nest?

Mermaid allows arbitrary nesting of alt, opt, loop, and par. In practice two levels is the limit for readability; split into two diagrams beyond that.

Why are the participant names single letters?

The participant B as Browser form keeps the message lines short while the lane headers stay descriptive. It also makes it painless to rename a participant later.