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
| Layer | One region, multi-AZ | Why |
|---|---|---|
| Edge | An Application Load Balancer in both zones with a regional web application firewall | The load balancer keeps long streaming answers open, which a CDN in front would cut off. |
| Gateway | At least two gateway tasks, spread over both zones, scaling on CPU | Either zone can carry all traffic while the other is down. |
| Workers | The workflow queue workers in the same two zones | Long running steps survive a zone loss. |
| Database | PostgreSQL with a Multi-AZ standby in the second zone | The database fails over in about one to two minutes with the same address, so the gateway reconnects without a config change. |
| Cache | Valkey (Redis compatible) with a primary and a replica in different zones and automatic failover | Rate limits, budgets in flight and router state keep working when a cache node is lost. |
| Egress | One NAT gateway per zone | Calls to model providers do not depend on a single zone. |
| Secrets and keys | One secret store and one set of encryption keys per region | Nothing secret is shared between regions. |
| Concern | Across regions | Why |
|---|---|---|
| Database | One independent database per region, no replication between them | Data stays in its region. A replica in another region would copy it out. |
| Keys and users | A virtual key works only in the region that issued it | The key lives in that region's database. |
| Addresses | Each region has its own API and Admin UI address, for example api.example.com and eu.api.example.com | Customers are sent to their region on purpose. Latency based routing would move a customer's requests, and its logs, to whichever region answers first. |
| Images | The same release image in every region, pushed to each region's registry | Every region runs the same code. |
| Licence | The same licence in each region's secret store | Each gateway checks it on its own. |
| Model providers | Chosen per deployment | The 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
-
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.tfplanterraform show multi-az.tfplan | grep -E "must be replaced|will be destroyed" || echo "no replacements"terraform apply multi-az.tfplanThe 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.
-
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]' -
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. -
Set the region on each gateway. Spanway Cloud gateways carry
general_settings.cloud.regionand the other regions' signup pages ingeneral_settings.cloud.region_signup_urls.general_settings:cloud:region: eu-central-1region_signup_urls:us-east-1: https://app.example.com/ui/cloud/signup -
Check each region on its own.
curl https://api.example.com/health/readinesscurl https://eu.api.example.com/health/readinesscurl https://eu.api.example.com/cloud/plans -
In the Admin UI of either region, open
/ui/cloud/signupand 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.
| Layout | US East (N. Virginia) | EU (Frankfurt) | Total per month |
|---|---|---|---|
| A. One zone, one region | about 244 USD | about 244 USD | |
| B. Multi-AZ, one region | about 321 USD | about 321 USD | |
| C. Multi-AZ US plus a one-zone EU region | about 321 USD | about 288 USD | about 609 USD |
| D. Multi-AZ in both regions | about 321 USD | about 375 USD | about 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 see | What it means | Fix |
|---|---|---|
The plan shows the database or the cache must be replaced | A 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 workspaces | No 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 invalid | region_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 other | Keys live in the database of the region that issued them. | Use a key issued in that region. |
Logs
| Level | Line | Meaning and action |
|---|---|---|
| INFO | cloud: signup for region <region> pointed at <signup_url>, nothing stored | A signup chose another region and was sent to its page. Normal. |
| INFO | cloud: signup refused, region <region> is not offered | A signup named a region no gateway offers. Normal for a hand-written request. |
| ERROR | cloud: 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.
Related
- Data regions on Spanway Cloud.
- Terraform on AWS for the self-hosted AWS stack.
- Componentised Helm chart for Kubernetes in several zones.
- Data policy routing to keep prompts with providers in a chosen region.