Cloud / IaC · Freelance

Multi-Region Kubernetes on DigitalOcean for a Low-Latency Trading Web App

Front end, API and engine containers deployed to Kubernetes clusters in several countries, with geo-aware DNS routing and per-region configuration.

  • DigitalOcean Kubernetes
  • Docker
  • Helm
  • kubectl
  • Ingress NGINX
  • Geo DNS
  • doctl
  • Container Registry

// Why this matters

A multi region kubernetes digitalocean design matters when response time is part of the product. For a trading-style web application, a user in one continent waiting several hundred milliseconds for an API round trip sees stale prices and slow order feedback, and no amount of caching hides that from the engine's own path.

Running containers in the same country as users is the most direct fix, and DigitalOcean makes it cheap to try: managed Kubernetes in many regions, a simple load balancer and a built-in registry. You trade a bigger platform bill of materials for latency that can be measured and defended.

I deployed a front end, an API and a matching engine across nodes in different countries for exactly this kind of app. The key lesson was that not every component belongs in every region.

// The problem

A single-region deployment has a latency floor set by physics. Users far from it pay for the distance on every request, and TLS handshakes and chatty APIs multiply the cost. Putting only a CDN in front helps static assets but not API calls or live data.

Naively copying the whole stack to several regions creates a new problem: state. An engine that matches orders or maintains a position cannot be active in three places at once without a consistency story. Letting each region run its own engine on shared data produces divergent results.

There is also operational drift. Hand-edited manifests per region diverge within weeks, and a fix applied to one cluster is forgotten in another. Without a single source for the deployment definition, you cannot say whether two regions are running the same thing.

// The solution

Each region gets its own DigitalOcean Kubernetes cluster, created with doctl and sized from a values file. Regions share nothing at runtime; they are connected only by DNS and, where needed, by an explicit API call between engines. Independent clusters mean a regional incident is a regional incident.

The three workloads have different placement rules. The front end is static content served by a lightweight container and is deployed to every region. The API is stateless and also goes everywhere, reading from a regional cache and talking to the engine over an internal service. The engine is stateful or latency-critical against its data feed, so it runs in one primary region (with a warm standby elsewhere) and the other regions' APIs call it over the shortest path.

One Helm chart describes all three. A values-<region>.yaml file sets replica counts, image tags, resource requests and the engine endpoint. Images live in the registry and are tagged immutably, so a region cannot silently pick up a newer build. Rollouts go region by region: deploy, run the smoke test against the load balancer, then proceed.

For traffic steering, each cluster's ingress controller creates a load balancer, and a DNS provider with geo or latency policies maps users to the nearest one. DigitalOcean DNS is not geo-aware by itself, so I use a provider that is, with health checks that remove a failing region from rotation.

Alternatives rejected: a single stretched cluster with nodes in several countries (control-plane latency and split-brain risk), and a service mesh with multi-cluster federation (too much machinery for three services). For another Kubernetes delivery pipeline see CloudFormation EKS Platform with Per-Service CI/CD, and for region expansion discipline see Adding a Region Without Destroying Anything.

How it flows flow1. Build → 2. Clusters → 3. Chart → 4. Ingress → 5. Smoke test → 6. DNS → 7. Rollout → 8. Observe01Build02Clusters03Chart04Ingress05 · GATESmoke test06DNS07Rollout08Observe
How it flows. End-to-end flow. Dashed pink nodes are gates: points where a human or a check must pass before the next stage runs.
  1. BuildDocker images for front end, API and engine pushed to a registry
  2. Clustersone DOKS cluster per region via doctl
  3. Chartone Helm chart, one values file per region
  4. IngressNGINX and a load balancer per cluster
  5. Smoke test gatehealth endpoints checked before traffic is enabled
  6. DNSgeo or latency routing records point to each regional balancer
  7. Rolloutdeploy one region, verify, then the next
  8. Observeper-region latency and error dashboards
TrafficGeo DNSRegional load balancerIngress NGINXWeb tierFront end podsAPI podsRegional cacheEnginePrimary engineWarm standbyData feedPlatformDOKS clusterContainer registryHelm releases
Per-region stack. Every region runs the same layers; only the engine placement differs.
UserGeo DNSRegional LBAPIEngineresolve app hostnamenearest regional addresshttps requestroute via ingressinternal callresult
A request from a nearby user. DNS picks the region, the API calls the engine on the shortest path.

// Before you start

  • A DigitalOcean account with an API token available to doctl (stored in your secrets manager, not in files)
  • doctl 1.100 or later, kubectl 1.28 or later and Helm 3.12 or later
  • Docker for building images and a DigitalOcean Container Registry
  • A DNS provider that supports geo or latency routing with health checks
  • Container images for the front end, API and engine

// Step-by-step implementation

  1. 01 Create a cluster in each region

    Create one cluster per target region with the same node size and Kubernetes version so behaviour matches. doctl can wait for readiness and save the kubeconfig under a context name per region, which is how you avoid applying to the wrong one.

    Keep node counts small at first and rely on the autoscaler bounds for headroom.

  2. 02 Build images and push them to the registry

    Build each component once and tag by commit, not by latest. Immutable tags are what let you promote the same artifact through regions. Log the registry into the clusters so pods can pull.

    Linking the registry to the clusters is a one-time integration step per cluster.

  3. 03 Write one Helm chart for all three workloads

    Template the deployments and services so values drive everything environmental. A boolean decides whether the engine is installed in this region, and the API receives the engine endpoint as a value. That single flag expresses the placement policy.

    Add readiness probes; they gate both rollouts and load balancer health.

  4. 04 Add per-region values files

    The primary region installs the engine; the others point their API at it. Everything else is identical, which is the property you want. Keep these files small enough to compare in one screen.

    Review them side by side whenever a region misbehaves.

  5. 05 Install the ingress controller and deploy the release

    Install ingress-nginx in each cluster; DigitalOcean provisions a load balancer for it. Then deploy the chart using the right context and values file. Always pass the context explicitly so a stray current-context cannot send a deploy to the wrong region.

    Roll out one region at a time and stop on the first failed check.

  6. 06 Smoke test, then enable geo DNS

    Before any user sees a region, hit its balancer directly with a health request. Only after it passes do you add it to the DNS policy. Configure health checks on the DNS records so a failing region drops out automatically.

    The exact DNS commands depend on your provider, so the check below is the portable part.

// How to verify it works

  • kubectl get nodes in each context shows Ready nodes and the expected version.
  • helm list in each cluster shows the same chart version and image tag.
  • The smoke test returns 200 for every regional balancer.
  • Resolving the hostname from vantage points in different countries returns different regional addresses.
  • Stopping the API pods in one region causes DNS health checks to move users to another region within the TTL.

// Design decisions and trade-offs

  • Run one independent cluster per region rather than one stretched cluster
  • Ship the same Helm chart everywhere with a small values file per region
  • Send users to the nearest region with geo or latency based DNS
  • Keep the stateful engine close to the data it trades on, with a single writer region
  • Roll out region by region with a smoke test as the gate

// Pitfalls and lessons learned

  • Using a stale current-context deploys to the wrong region. Always pass --kube-context.
  • A DNS TTL that is too long makes failover take minutes; keep it short for the geo records.
  • Floating latest tags make regions drift; use immutable tags everywhere.
  • Running a stateful engine in every region without a single-writer rule produces divergent state.
  • Forgetting to link the registry to each cluster gives ImagePullBackOff only in the new region.
  • Load balancers are billed per region; tear down test clusters promptly.

// Frequently asked questions

How do I run multi region kubernetes on DigitalOcean?

Create one DOKS cluster per region, deploy the same Helm chart with a values file per region, and route users with geo-aware DNS.

Should I stretch one cluster across regions?

Generally no. Control-plane latency and failure coupling make independent clusters simpler and safer.

Where should the stateful component run?

Next to its data source in one primary region, with a warm standby; other regions call it over the shortest path.

Does DigitalOcean DNS do geo routing?

Not natively; use a DNS provider with geo or latency policies and health checks in front of the regional load balancers.

How do I keep regions identical?

One chart, one image tag and small values files, deployed by script rather than by hand.

// The outcome

Users reach a nearby front end and API, the latency-sensitive engine runs in the region closest to its data feed, and every region is rebuilt from the same chart and a short values file.

// Where to take it next

// Keep reading