Skip to content

Multi-region platform

A global load balancer sends traffic to region A, with region B on standby. Each region runs a cluster of services and its own database, kept in sync by replication. Three scenarios: a checkout request, a region failover and a rolling deploy.

Static images

Multi-region platform, light

Multi-region platform, dark

Multi-region platform, contrast theme Multi-region platform, contrast theme

The same diagram in the built-in contrast theme (diagr build --theme contrast), in the site's light or dark scheme.

Views

This diagram has views: parts of it built as their own images and pages, next to the whole diagram's.

Checkout request

A dynamic view of the checkout scenario. checkout-flow: written as multi-region-checkout-flow-light.svg, multi-region-checkout-flow-dark.svg and multi-region-checkout-flow.html.

Checkout request Checkout request

Source

version: 1
title: Multi-region platform
description: >-
  A global load balancer sends traffic to region A, with region B on standby. Each region runs a cluster of
  services and its own database, kept in sync by replication. Three scenarios: a checkout request, a region
  failover and a rolling deploy.
grid: {col: 200, row: 150}

# One region, defined once.
components:
  region:
    params: {name: {required: true}, role: primary, database: primary}
    groups:
      region:
        title: $name
        sub: $role
        groups:
          cluster:
            title: Cluster
            tone: blue
            groups:
              checkout:
                title: Checkout
                tone: teal
                nodes:
                  api:    {icon: api,    title: Checkout API}
                  worker: {icon: server, title: Workers, sub: v1, stack: 2}
              catalog:
                title: Catalog
                tone: violet
                nodes:
                  prices: {icon: function, title: Pricing}
          data:
            title: Data
            tone: amber
            nodes:
              db: {icon: database, title: Orders, sub: $database}
    edges:
      api    -> worker: jobs
      api    -> prices: prices
      worker -> db:     write

# Two instances. Their nodes are a/api, a/worker, ... and b/api, b/worker, ...
instances:
  a: {component: region, with: {name: Region A}}
  b: {component: region, with: {name: Region B, role: standby, database: replica}}

nodes:
  health: {icon: clock,   title: Health checks, sub: every 10 s}
  user:   {icon: browser, title: Customer}

groups:
  edge:
    title: Global edge
    tone: neutral
    nodes:
      lb: {icon: globe, title: Load balancer, sub: anycast}
  delivery:
    title: Delivery
    tone: green
    nodes:
      ci: {icon: pipeline, title: Deploy pipeline, cells: [build, test, canary, rollout]}

edges:
  user   -> lb:       HTTPS
  health --> a/api:   probe
  lb     -> a/api:    active
  lb     --> b/api:   standby
  a/db   --> b/db:    replication
  ci     -> a/worker: {label: rollout, hidden: true}
  ci     -> b/worker: {label: canary, hidden: true}

scenarios:
  checkout:
    title: Checkout request
    trigger: {at: user, label: Place order}
    ready: Press Place order to follow one request.
    end: Order stored in region A and replicated to B.
    steps:
      - Request:
          at: user
          text: The customer's browser sends the order to the global load balancer.
          do: [flow user -> lb]
      - Route to region A:
          at: lb
          text: Region A is active, so the load balancer sends the request there.
          do: [flow lb 600ms -> a/api]
      - Price and accept:
          at: a/api
          text: The checkout API asks the pricing service for the total, then queues the order for the workers.
          do:
            - activate a/api
            - parallel: [draw a/api -> a/prices, activate a/prices]
            - done a/prices
            - flow a/api -> a/worker
      - Persist:
          at: a/worker
          text: A worker writes the order to the primary database.
          do: [flow a/worker 800ms -> a/db 600ms done]
      - Replicate:
          at: b/db
          text: The write is replicated to region B, which stays ready to take over.
          do:
            - draw a/db -> b/db
            - b/db.sub: replica, in sync
            - done b/db

  failover:
    title: Region failover
    trigger: {at: health, label: Fail region A}
    ready: Press Fail region A to see the standby region take over.
    end: Region B serves all traffic.
    steps:
      - Probe fails:
          at: health
          text: The health check stops getting answers from region A.
          do: [activate health, draw health -> a/api, fail a/api a/worker, health.sub: region A down]
      - Drain region A:
          at: lb
          text: The load balancer stops sending traffic to region A.
          focus: [lb, a/api, a/worker]
          do: [hide lb -> a/api, lb.sub: draining A, wait 1200ms]
      - Promote the replica:
          at: b/db
          text: Region B's database is promoted from replica to primary.
          do: [activate b/db 1200ms, b/db.sub: primary, done b/db]
      - Reroute:
          at: b/api
          text: All traffic now goes to region B.
          do:
            - draw lb -> b/api
            - lb -> b/api.label: all traffic
              lb.sub: anycast, to B
            - activate b/api
            - draw b/api -> b/worker
            - draw b/worker -> b/db
            - done b/api b/worker health

  deploy:
    title: Rolling deploy
    trigger: {at: ci, label: Deploy}
    ready: Press Deploy to roll a new version out, region B first.
    end: Both regions run v2.
    steps:
      - Build and test:
          at: ci
          text: The pipeline builds the new version and runs the tests.
          do: [activate ci, cells ci build..test]
      - Canary in region B:
          at: b/worker
          text: The standby region gets the new version first, as a canary with no customer traffic.
          # Drawing the hidden edge from the pipeline brings it out.
          do:
            - draw ci -> b/worker
            - cells ci canary
            - activate b/worker 1000ms
            - b/worker.sub: v2 canary
            - done b/worker
      - Roll out to region A:
          at: a/worker
          text: Region A is updated one replica at a time, so it keeps serving during the rollout.
          do:
            - draw ci -> a/worker
            - cells ci rollout
            - activate a/worker
            - repeat 2:
                - a/worker.sub: replica $i of 2 on v2
                - wait 1000ms
            - a/worker.sub: v2
              b/worker.sub: v2
            - done a/worker ci

# A dynamic view: only what the checkout scenario uses, with each edge numbered by the step that draws it.
views:
  checkout-flow: {title: Checkout request, scenario: checkout}