A single Region is a single failure domain. Running in two Regions protects against losing one, and the design choice comes down to two numbers the business sets: RTO (recovery time objective: how long you may be down) and RPO (recovery point objective: how much recent data you may lose). From cheapest to most resilient: backup and restore, pilot light, warm standby, active/passive at full scale, and active/active, where both Regions take traffic. This lesson takes one orders service through a Region failure, and shows the two failures that catch teams out: active/active writes that conflict, and a standby Region that cannot scale when it is needed.
Difficulty: Master · Know this first: Lesson 158, Lesson 72
By the end of this lesson you can work at four levels:
This page teaches it with a plain-language analogy, an animated diagram with normal and failure scenarios, a simulator, a quiz, basic, intermediate, advanced, and master checks, the expert detail ("Go deeper"), a production incident, a hands-on lab with commands and their output, and a production design exercise.
This bar adds up minutes from a Region failing to orders flowing again. It is a worked example, not a measurement. The capacity and write-conflict hops are where multi-Region designs fail on the day.
Pick the pattern, the replication, and whether quotas are raised in the second Region. The readouts show the RTO and RPO you would get, and the cost against a single Region.
Three questions. No score is saved anywhere — this is just you against the material.
Multi-Region design grows in four levels: reading RTO and RPO, choosing a pattern, building and rehearsing failover, and running active/active safely.
At the basic level you can explain what each number protects and what a pattern achieves.
Where it breaks: asking for "zero and zero" without asking what it costs.
Try it: Basic
Which pattern keeps data replicated but compute switched off in the second Region?
Now do it: Map three of your services to a pattern.
At the intermediate level you choose and cost a pattern per service.
Try it: Intermediate
A service needs RTO 4 hours and RPO 1 hour. What is likely enough?
Now do it: Price two patterns for one service.
At the advanced level failover is a tested procedure.
Try it: Advanced
What should a failover drill measure?
Now do it: Run a drill for one service in a test environment.
At the master level both Regions serve, and the data model is built for it.
Trade-off: active/active doubles running cost and adds data complexity; it buys near-zero RTO and capacity that is always tested.
Try it: Master
How do you stop a retry in the other Region from creating a duplicate order?
Now do it: Add an idempotency key to one write API.
Measuring the real RPO and checking the standby Region (read-only):
# Aurora Global Database: replication lag to the secondary Region
aws rds describe-global-clusters --query "GlobalClusters[].GlobalClusterMembers[].[DBClusterArn,IsWriter]"
aws cloudwatch get-metric-statistics --namespace AWS/RDS --metric-name AuroraGlobalDBReplicationLag \
--dimensions Name=DBClusterIdentifier,Value=orders-eu-central-1 --statistics Maximum \
--start-time "$(date -u -d '-1 day' +%FT%TZ)" --end-time "$(date -u +%FT%TZ)" --period 3600
# quotas in the standby Region, against what peak needs
aws service-quotas get-service-quota --region eu-central-1 --service-code ec2 --quota-code L-1216C47A
# Azure SQL: failover group state; Google Cloud SQL: replicas
az sql failover-group list -g rg-orders -s sql-orders-weu --query "[].{name:name, role:replicationRole, state:replicationState}" -o table
gcloud sql instances list --filter="masterInstanceName:orders" --format="table(name,region,state)"
The pattern ladder with typical numbers (yours depend on data size and automation):
Homing writes for active/active: route each customer to a home Region (by a customer ID hash or residency), let both Regions serve reads, send writes to the home Region, and on a Region failure move its customers' home to the survivor after the data has caught up. This keeps each record with a single writer.
This is a composite of a failure pattern that keeps repeating; the details are illustrative. Two Regions, one order, two writers.
Each customer has a home Region for writes, reads are served locally, every write API takes an idempotency key, and a conflict counter is monitored with an alert.
Everything here runs on any Linux machine: your own laptop, WSL on Windows (run wsl --install in PowerShell once), or a small cloud VM. The Python needs only Python 3 and its standard library; check that you have it with python3 --version.
Before you start: Python 3 for the program. The cloud steps need the AWS CLI with read access; adapt the Region names to yours.
Type each one, read what it prints, and compare it with the note above it.
Measure round-trip time between two Regions from a VM in one of them: it is the cost synchronous replication adds to every write.
for host in ec2.eu-central-1.amazonaws.com ec2.us-east-1.amazonaws.com; do
printf "%s " "$host"; curl -s -o /dev/null -w "%{time_connect}\n" "https://$host"
doneCheck a quota in the standby Region before you need it: running on-demand standard instances (vCPUs).
aws service-quotas get-service-quota --region eu-central-1 --service-code ec2 --quota-code L-1216C47A --query "Quota.[QuotaName,Value]" --output text
List global database clusters and which member writes.
aws rds describe-global-clusters --query "GlobalClusters[].GlobalClusterMembers[].[DBClusterArn,IsWriter]" --output table
multi_region.pyThis program replays a Region failure for each pattern to give the RTO and RPO it achieves, including what happens when the standby Region's quotas were never raised. Then it runs a day of active/active writes with asynchronous replication, first with last-writer-wins and no idempotency, then with records homed in one Region and idempotency keys. Save it as multi_region.py, then run it.
# multi_region.py
import random
PATTERNS = { # minutes: detect, decide, data, compute at standby quotas, routing; RPO in seconds
"backup and restore": (5, 6, 180, 120, 3, 3600),
"pilot light": (5, 6, 10, 35, 3, 1),
"warm standby": (5, 6, 1, 9, 3, 1),
"active/passive": (5, 6, 1, 0, 3, 1),
}
print(f"{'pattern':<20} {'RTO min':>8} {'RPO':>7} with default quotas in the standby Region")
for name, (detect, decide, data, compute, route, rpo_s) in PATTERNS.items():
rto = detect + decide + data + compute + route
capped = rto + (240 if compute else 0)
rpo = f"{rpo_s // 60} min" if rpo_s >= 60 else f"{rpo_s} s"
print(f"{name:<20} {rto:>8} {rpo:>7} {capped} min" + ("" if compute else " (already at full scale)"))
print("target: RTO 30 min, RPO 1 min\n")
rnd = random.Random(3)
LAG = 1.5 # seconds of replication lag between the Regions
def day(homed, idempotent):
store = {} # order -> (value, region, time)
seen = set() # idempotency keys already applied
lost = dup = 0
for t in range(20000):
order = rnd.randrange(150) # busy day: popular orders and stock rows are hot
region = "eu-west-1" if (homed and order % 2 == 0) else ("eu-central-1" if homed else rnd.choice(["eu-west-1", "eu-central-1"]))
now = t * 0.5
key = (order, t // 3) # a client retry reuses the same key
if idempotent and key in seen:
continue
seen.add(key)
prev = store.get(order)
if prev and prev[1] != region and now - prev[2] < LAG:
lost += 1 # the other Region's write was not replicated yet: last writer wins
if not idempotent and rnd.random() < 0.02:
dup += 1 # a timed-out request retried in the other Region
store[order] = (t, region, now)
return lost, dup
for label, homed, idem in (("active/active, last-writer-wins", False, False), ("records homed, idempotency keys", True, True)):
lost, dup = day(homed, idem)
print(f"{label:<34} lost updates {lost:>4} duplicate orders {dup:>4}")
Run it, and you should see this output:
$ python3 multi_region.py pattern RTO min RPO with default quotas in the standby Region backup and restore 314 60 min 554 min pilot light 59 1 s 299 min warm standby 24 1 s 264 min active/passive 15 1 s 15 min (already at full scale) target: RTO 30 min, RPO 1 min active/active, last-writer-wins lost updates 134 duplicate orders 422 records homed, idempotency keys lost updates 0 duplicate orders 0
The same Linux steps, made into a real script you can keep and run again. It uses the Bash features a production script needs: functions (one per step), an array of step names, arguments to choose steps, a case for options, exit codes recorded for each step, and a trap that prints a summary even when you stop it with Ctrl+C. Make a folder for this lesson (mkdir -p ~/labs/multi-region-active-active-and-active-passive && cd ~/labs/multi-region-active-active-and-active-passive) and save this as lab.sh.
#!/usr/bin/env bash
# The Linux steps of "Multi-Region Architecture: Active/Active, Active/Passive, RTO, and RPO", as one script (save it as lab.sh).
#
# ./lab.sh run every step, in order
# ./lab.sh 2 4 run only steps 2 and 4
# ./lab.sh --list list the steps
#
# The steps share one shell, so a later step can use what an earlier one set up (a folder,
# a variable, a container): run them all in order the first time. Your own scripts should
# start with "set -euo pipefail"; this one runs teaching commands, and some of them fail on
# purpose, so it records each step's exit code instead of stopping at the first failure.
STEPS=(
'Measure round-trip time between two Regions from a VM in one of them: it is the cost synchronous replication adds to every write.'
'Check a quota in the standby Region before you need it: running on-demand standard instances (vCPUs).'
'List global database clusters and which member writes.'
)
step_1() {
for host in ec2.eu-central-1.amazonaws.com ec2.us-east-1.amazonaws.com; do
printf "%s " "$host"; curl -s -o /dev/null -w "%{time_connect}\n" "https://$host"
done
}
step_2() {
aws service-quotas get-service-quota --region eu-central-1 --service-code ec2 --quota-code L-1216C47A --query "Quota.[QuotaName,Value]" --output text
}
step_3() {
aws rds describe-global-clusters --query "GlobalClusters[].GlobalClusterMembers[].[DBClusterArn,IsWriter]" --output table
}
# print a step that has to be run by hand, instead of running it
by_hand() {
echo " (run this one yourself: $1)"
sed 's/^/ /'
}
RESULTS=()
run_step() {
local n=$1 start=$SECONDS code
printf '\n== step %d of %d: %s\n' "$n" "${#STEPS[@]}" "${STEPS[n-1]}"
"step_$n"
code=$?
RESULTS+=("step $n: exit code $code, $((SECONDS - start)) s")
}
summary() {
echo
echo "== summary"
local r
for r in "${RESULTS[@]}"; do echo " $r"; done
}
case "${1:-}" in
-h|--help) sed -n '2,6p' "$0"; exit 0 ;;
--list) for i in "${!STEPS[@]}"; do echo "$((i + 1)). ${STEPS[i]}"; done; exit 0 ;;
esac
[ $# -eq 0 ] && set -- $(seq 1 "${#STEPS[@]}")
for n in "$@"; do
if ! [[ $n =~ ^[0-9]+$ ]] || (( n < 1 || n > ${#STEPS[@]} )); then
echo "there is no step '$n'; try --list" >&2
exit 2
fi
done
trap summary EXIT
trap 'echo; echo "stopped with Ctrl+C"; exit 130' INT
for n in "$@"; do run_step "$n"; done
Then make it executable and run it:
chmod +x lab.sh ./lab.sh --list # the steps ./lab.sh # every step, then a summary of exit codes and times ./lab.sh 2 3 # only steps 2 and 3
New to a feature used above? These W3Schools pages explain each one from zero, with examples you can run in the browser.
curl, Loops.An online retailer wants to survive the loss of a Region. Design the multi-Region approach for its checkout, catalogue, and reporting services.
What RTO and RPO does each service need, and who signs them off? Which pattern does each use? How is data replicated, and what is the real RPO? How is traffic shifted, and who decides? How is capacity guaranteed? How often is it rehearsed, and what is measured?
Say checkout loses $60,000 an hour when down, the catalogue $10,000, reporting nothing urgent; peak of 2,000 orders a minute; two EU Regions.
Checkout: warm standby or active/passive with Aurora Global Database (lag under a second), Global Accelerator, quotas at 120% of peak, a one-command failover by the incident commander, quarterly drills; catalogue: active/active for reads from replicated storage and caches, writes homed in one Region; reporting: backup and restore with a 24-hour RTO; idempotency keys on checkout writes; failback rehearsed; costs reported per service.
Active/passive at full scale doubles checkout's compute cost and removes scaling risk; warm standby is cheaper and depends on quotas and autoscaling; active/active reads are cheap to add, active/active writes are expensive to get right.
Each row is one way this system went wrong in the diagram's scenarios. The hop number is where to look first.
| Scenario | Where | Effect | What goes wrong |
|---|---|---|---|
| Active/active, no conflict plan | Hop 7: Write conflicts | Breaks | Users are routed by latency, so the same customer's requests can reach either Region. Order updates and stock decrements happen in both within the replication lag. |
| Standby cannot scale | Hop 6: Capacity | Breaks | Failover starts on time, but eu-central-1's vCPU and Elastic IP quotas are still at defaults. Scaling stops at about 20% of peak capacity, and other customers are failing over to the same Region. |
Review the design in this lesson, or your own, against these ten areas. Tick an area when you can answer its question with evidence: a number, a test, a document, or an owner. Your ticks stay in this browser.
The official documentation and standards behind this lesson. Versions and defaults change; when a command or field here differs from them, trust the official page.
Last updated . Next review due by November 2027. Found something out of date? Tell me.