Skip to main content

Multi-region reference architecture

This page shows how to keep the gateway running when one data center fails, and how to serve customers from more than one part of the world while each customer's data stays in the place it chose. It describes the layout Spanway Cloud uses, and the same layout works for a self-hosted gateway on AWS with the Terraform stacks or the Helm charts.

In plain words there are two separate goals. Multi-AZ protects against an outage: every part of the gateway runs in two availability zones (separate data centers in one region), so losing one zone does not stop traffic. Multi-region is about where data lives: each region is a complete, independent gateway with its own database, and a customer's keys, logs and usage records exist only in the region it belongs to.

A real-world scenario​

A company runs the gateway for its US teams in us-east-1. A new customer in Germany requires that its request logs never leave the EU. The platform team first turns on multi-AZ in us-east-1 so a zone outage no longer takes the gateway down, then deploys a second, independent gateway in eu-central-1 (Frankfurt) and gives the German customer the EU address. The EU gateway never sees US data and the US gateway never sees EU data.

The layout​

LayerOne region, multi-AZWhy
EdgeAn Application Load Balancer in both zones with a regional web application firewallThe load balancer keeps long streaming answers open, which a CDN in front would cut off.
GatewayAt least two gateway tasks, spread over both zones, scaling on CPUEither zone can carry all traffic while the other is down.
WorkersThe workflow queue workers in the same two zonesLong running steps survive a zone loss.
DatabasePostgreSQL with a Multi-AZ standby in the second zoneThe database fails over in about one to two minutes with the same address, so the gateway reconnects without a config change.
CacheValkey (Redis compatible) with a primary and a replica in different zones and automatic failoverRate limits, budgets in flight and router state keep working when a cache node is lost.
EgressOne NAT gateway per zoneCalls to model providers do not depend on a single zone.
Secrets and keysOne secret store and one set of encryption keys per regionNothing secret is shared between regions.
ConcernAcross regionsWhy
DatabaseOne independent database per region, no replication between themData stays in its region. A replica in another region would copy it out.
Keys and usersA virtual key works only in the region that issued itThe key lives in that region's database.
AddressesEach region has its own API and Admin UI address, for example api.example.com and eu.api.example.comCustomers are sent to their region on purpose. Latency based routing would move a customer's requests, and its logs, to whichever region answers first.
ImagesThe same release image in every region, pushed to each region's registryEvery region runs the same code.
LicenceThe same licence in each region's secret storeEach gateway checks it on its own.
Model providersChosen per deploymentThe data region decides where the gateway stores data. To keep prompts in the EU too, use models deployed in EU regions with data policy routing and data residency.

On Spanway Cloud a tenant picks its data region on the signup page, and the tenant row records it, see Data regions.

Steps​

  1. Turn on multi-AZ in the first region. With the gateway Terraform stack that is one variable, multi_az = true, which switches on the second NAT gateway, the database standby, the cache replica with failover and at least two gateway tasks with zone rebalancing. Plan first and check that nothing is replaced.

    terraform plan -var-file=prod.tfvars -out=multi-az.tfplan
    terraform show multi-az.tfplan | grep -E "must be replaced|will be destroyed" || echo "no replacements"
    terraform apply multi-az.tfplan

    The database converts at its next maintenance window, with one short failover. The second NAT gateway adds a new outbound address, so add it to any allowlist that names the old one.

  2. Check that both zones carry tasks and the database has a standby.

    aws ecs describe-tasks --cluster <cluster> --query 'tasks[].availabilityZone' \
    --tasks $(aws ecs list-tasks --cluster <cluster> --service-name <gateway service> --query 'taskArns' --output text)
    aws rds describe-db-instances --db-instance-identifier <database> --query 'DBInstances[0].[MultiAZ,SecondaryAvailabilityZone]'
  3. Deploy the second region as its own stack with its own state, its own network range and its own addresses, for example eu.api.example.com. It needs its own regional security baseline (threat detection, configuration recording, a log bucket and its key), because load balancer and flow logs can only write to a bucket in their own region.

  4. Set the region on each gateway. Spanway Cloud gateways carry general_settings.cloud.region and the other regions' signup pages in general_settings.cloud.region_signup_urls.

    general_settings:
    cloud:
    region: eu-central-1
    region_signup_urls:
    us-east-1: https://app.example.com/ui/cloud/signup
  5. Check each region on its own.

    curl https://api.example.com/health/readiness
    curl https://eu.api.example.com/health/readiness
    curl https://eu.api.example.com/cloud/plans
  6. In the Admin UI of either region, open /ui/cloud/signup and check that the Data region list shows both regions and that the region the page is served from is selected.

Expected result​

Each /health/readiness answers 200 with its own database connected. GET /cloud/plans on the EU gateway lists regions with eu-central-1 as served_here: true and us-east-1 with its signup page. Stopping one gateway task, or failing the database over in a maintenance window with aws rds reboot-db-instance --force-failover, leaves the readiness check green after the failover.

Monthly cost estimate​

These are on-demand AWS list prices for a small production gateway, read from the AWS price list on 24 November 2026: two gateway tasks of 1 vCPU and 2 GB, one worker task, PostgreSQL db.t4g.small with 20 GB, Valkey cache.t4g.micro, 50 GB of outbound traffic through NAT, 5 GB of logs and a health check every five minutes. Model provider charges, larger traffic and support plans are not included, and prices change, so check the AWS pricing calculator before you budget.

LayoutUS East (N. Virginia)EU (Frankfurt)Total per month
A. One zone, one regionabout 244 USDabout 244 USD
B. Multi-AZ, one regionabout 321 USDabout 321 USD
C. Multi-AZ US plus a one-zone EU regionabout 321 USDabout 288 USDabout 609 USD
D. Multi-AZ in both regionsabout 321 USDabout 375 USDabout 696 USD

Going from A to B adds about 77 USD a month: the second NAT gateway and its address (about 37 USD), the database standby (about 26 USD), the cache replica (about 9 USD) and traffic between zones (about 5 USD). The gateway tasks do not change, because two tasks already run. An EU region costs a little more than the same layout in the US, because Frankfurt prices compute, NAT and the database 10 to 15 percent higher, and it carries its own security baseline (about 16 USD). The biggest variable items in every layout are NAT data processing, since every model provider call leaves through it, and log ingestion.

Errors​

What you seeWhat it meansFix
The plan shows the database or the cache must be replacedA setting that cannot change in place was changed, for example the engine or the subnet group.Do not apply. Revert that setting and plan again. Multi-AZ itself never replaces either.
A signup answers 421 with workspaces in <region> are created at <signup_url>The signup chose a region another gateway serves.Send it to the signup_url in the answer.
A signup answers 400 with region <region> is not offered for new workspacesNo gateway offers that region.Add the region's signup page to region_signup_urls, or pick an offered region.
Every /cloud route answers 500 with general_settings.cloud is invalidregion_signup_urls names the gateway's own region, uses http://, or names an unknown region.Fix the entry the gateway log names.
A virtual key from one region answers 401 in the otherKeys live in the database of the region that issued them.Use a key issued in that region.

Logs​

LevelLineMeaning and action
INFOcloud: signup for region <region> pointed at <signup_url>, nothing storedA signup chose another region and was sent to its page. Normal.
INFOcloud: signup refused, region <region> is not offeredA signup named a region no gateway offers. Normal for a hand-written request.
ERRORcloud: general_settings.cloud is invalid: <reason>The cloud block, including the region keys, failed validation. Fix the key the reason names.

During a database failover the gateway logs its usual database connection errors for about a minute and then recovers, see the log reference.