Multi-Region for an AI App: Active-Passive vs Active-Active, RTO and RPO in Numbers, Write Homes and Data Residency
A support-ticket app adds an EU region. Active-passive recovers in 240 s, active-active in 90 s at 50% busy, and the RPO is the replication lag (60 writes at 1.5 s). Two writes inside the lag lose one silently, so each tenant gets a write home, which also keeps Nordbank's data in the EU. A drill with a 300 s DNS TTL fails at 480 s.
What you will learn
- Route users to a near region with GeoDNS or anycast and know how each behaves in a failover
- Add up the RTO of active-passive and active-active, and read the RPO from replication lag
- Avoid silently lost writes by giving every tenant one write home
- Keep data residency through backups, logs, prompts and failover, and prove the numbers with a drill
Before you start
- Latency Math: p50, p95, p99 and the Tail
- Cloud-Agnostic Architecture: The Portability Layers
Our support-ticket app, TicketHub, runs in one region today. Starting a second region is the easy part. The hard part is knowing what happens when one region goes away. Four ideas carry this article: routing users to a region, the RTO, the RPO, and a write home for every piece of data.
All numbers come from a small standard-library script, multiregion_math.py. They are example numbers, rounded.
One region, three problems
All of TicketHub's servers sit in one US region.
- Distance. A user in Berlin is about 6,700 km from the US region. Light in fibre covers about 200 km per millisecond, so the round trip is at least 67 ms before any work is done.
- Residency. A bank customer, Nordbank, writes in: our data must stay in the EU.
- Failure. The CTO asks what happens if the whole region goes down.
FIBRE_KM_PER_MS = 200 # light in glass, about 2/3 c
def rtt_ms(km):
"""Round trip over fibre, no work done."""
return 2 * km / FIBRE_KM_PER_MS
berlin -> eu 500 km rtt 5 ms
berlin -> us 6700 km rtt 67 ms
eu <-> us 6500 km rtt 65 ms
Getting users to a region
We add an EU region. Now each user must reach the right one, and there are two common ways.
- GeoDNS. When the browser looks up our address, the DNS server checks where the user is and answers with the EU address. Berlin to the EU region is 500 km, a 5 ms round trip. The answer carries a TTL: how long the browser may keep using it.
- Anycast. Both regions announce the very same IP address, and the network carries each user to the nearest one.
The difference shows in a failure. With GeoDNS, users only move once their cached answer expires. With anycast, the network reroutes them without waiting for a TTL.
Active-passive and its RTO
In active-passive, region one serves every user. Region two is a standby: it serves nobody and keeps a copy of the data sent over from region one. When region one fails, the team runs a failover and makes the standby the new primary. It's cheap, because the standby can run small. But those minutes are worth counting.
The time you are down is the RTO, the recovery time objective. The steps run one after another:
def failover_s(steps):
"""Recovery time: the steps run one after another."""
return sum(steps.values())
ap = {"detect": 3 * 10, "promote": 60,
"dns ttl": 60, "warm up": 90}
print("steps:", ap)
print("rto s:", failover_s(ap))
steps: {'detect': 30, 'promote': 60, 'dns ttl': 60, 'warm up': 90}
rto s: 240
Three failed health checks 10 seconds apart (30 s), promote the replica so it accepts writes (60 s), wait for old DNS answers to expire (60 s), and scale up the small standby and warm its caches (90 s). Four minutes of downtime, and every step is something you can shorten.
Replication lag is the RPO
The copy in region two is sent a moment after each write. That delay is the replication lag, 1.5 seconds here. TicketHub takes 40 writes a second, and if region one dies, every write still on the way is gone.
lag 1.5 s -> 60 writes at risk
lag 8 s -> 320 writes at risk
Lag isn't steady; under heavy load it can spike to 8 seconds. This is the RPO, the recovery point objective: how much data you can afford to lose. With async replication, your RPO is the lag at the moment you lose the region.
Sync or async
Synchronous replication makes the RPO zero, at a price. An async write finishes locally in 20 ms. A sync write must also wait for the other region to confirm, and EU to US is a 65 ms round trip:
sync write: 20 + 65 = 85 ms, rpo 0
That's on every single write. And if the link between regions breaks, sync writes can't finish at all, so your safety feature stops your app. Most teams split it: sync between zones inside one region, where the round trip is tiny, and async between regions with an RPO they agree on.
Active-active: both regions serve
In active-active, both regions serve users all the time. At peak TicketHub gets 230 requests a second, 115 per region. If one region fails, the survivor must take all 230 right away, so each region is sized for the full peak.
normal: 115 req/s per region
one lost: survivor takes 230
paid 460 for 230 used -> 50% busy
rto s: 90
You pay for 460 and use 230, 50% busy on purpose. What you get back is an RTO of 90 seconds instead of 240.
The write conflict
Active-active brings a new problem. Liam is in the US and Emma is in the EU, and both work on ticket 43. Liam marks it solved at 10.0 s. Emma sets it to waiting at 10.2 s in her own region. The lag is 1.5 s, so neither has seen the other's change.
writes = [ # (time s, region, user, status)
(10.0, "us", "liam", "solved"),
(10.2, "eu", "emma", "waiting"),
]
lag = 1.5
gap = writes[1][0] - writes[0][0]
print(f"gap {gap:.1f} s < lag {lag} s:", gap < lag)
winner = max(writes) # last write wins
print("kept:", winner[3], "by", winner[2])
lost = [w[2] for w in writes if w != winner]
print("silently lost:", lost)
gap 0.2 s < lag 1.5 s: True
kept: waiting by emma
silently lost: ['liam']
When the copies meet, last write wins keeps Emma's change. Liam's update disappears with no error and no warning.
One write home, pinned per tenant
The fix is to give every piece of data one write home. If ticket 43's home is the EU, Liam's write travels to the EU and lands after Emma's, in order. Reads can still come from the local copy in both regions, so they stay fast. The price is one round trip for a writer far from home.
Picking a home per ticket would be messy, so we pin the whole customer, the tenant:
home = {"acme": "eu", "globex": "us",
"nordbank": "eu"}
for tenant, at in (("acme", "eu"),
("nordbank", "us"),
("globex", "us")):
to = home[tenant]
extra = 0 if at == to else rtt_ms(6_500)
print(f"{tenant:<9} write at {at} -> home {to}"
f" +{extra:.0f} ms")
acme write at eu -> home eu +0 ms
nordbank write at us -> home eu +65 ms
globex write at us -> home us +0 ms
A travelling Nordbank agent whose request reaches the US region gets forwarded to the EU, paying 65 ms on that write while the order stays correct. Most of the time people write close to their own home anyway.
Data residency
Pinning also answers Nordbank. Data residency means a rule says where data may be stored, and it covers more than the main database: backups, logs and the prompts sent to the AI assistant must stay in the EU too. So scan where every record actually lives:
stored = [("acme", "eu"), ("nordbank", "eu"),
("globex", "us"), ("nordbank", "eu"),
("acme", "us")] # a backup copied out
bad = [(t, r) for t, r in stored if home[t] != r]
print("records:", len(stored), "outside home:",
len(bad), bad)
records: 5 outside home: 1 [('acme', 'us')]
An Acme backup was copied to the US, the kind of leak a scan catches.
The trap: if the EU region fails and you fail over to the US, you break the rule yourself. An EU tenant fails over to a second EU region, or it waits.
The failover drill
The target is an RTO of 300 seconds and an RPO of 5 seconds. Paper isn't proof, so the team switches region one off on purpose:
target_rto, target_rpo = 300, 5
for ttl in (300, 60):
steps = dict(ap, **{"dns ttl": ttl})
rto = failover_s(steps)
ok = "pass" if rto <= target_rto else "fail"
print(f"ttl {ttl:>3} s -> rto {rto} s {ok}")
print(f"lag at cut 1.5 s <= {target_rpo} s:",
1.5 <= target_rpo)
ttl 300 s -> rto 480 s fail
ttl 60 s -> rto 240 s pass
lag at cut 1.5 s <= 5 s: True
Drill one found the DNS TTL set to 300 seconds, not 60, and recovery took 480 s. Lowered to 60, the second drill passed at 240 s, and the lag at the cut was inside the RPO. A failover you have never run is a guess; a drill turns it into a number. For the provider side of a failover, see Fallback models for an LLM app.
How to choose
| Active-passive | Active-active | |
|---|---|---|
| RTO | Minutes (240 s here) | About 90 s or less |
| RPO | The replication lag | The same question |
| Capacity | Small standby | Each region sized for full peak (50% busy) |
| Writes | Simple: one primary | Needs a write home per tenant |
| Good when | A few minutes down is acceptable | Users are worldwide and downtime is costly |
Either way, if a rule says where data must stay, pin the tenant and keep its failover inside the same area. To weigh these choices against cost and latency in one review, see Design Review: Cost vs Latency vs Availability.
Common mistakes
- A long DNS TTL. It quietly adds to every GeoDNS failover, as drill one showed.
- Sync replication across regions. 85 ms per write, and writes stop when the link breaks.
- Active-active with writes anywhere. Last write wins drops updates without an error.
- Residency that stops at the database. Backups, logs and prompts count too, and so does the failover target.
Try it yourself
Using the same steps, what RTO does active-passive reach if you keep a warm standby (no warm-up step) and a 30-second TTL? And if the lag spikes to 8 seconds at the moment of the cut, does the drill still pass a 5-second RPO?
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
Fallback Models for an LLM App: A Chain That Checks Region and Fit, Flags Degraded Answers and Gets Rehearsed
When the main model goes down, the backup has to be allowed to take the data, able to read the whole request and tested before the bad day. A simulated four-model chain for an EU customer: a 6,000-token request lands on mid-eu, flagged degraded; a 10,000-token request is served by nobody, on purpose.
Back Pressure for LLM Traffic: Bound the Queue, Give Chat Its Own Lane, Count Tokens, Cancel When the Caller Leaves
A bulk upload buries the chat. In a small simulation, one shared queue grows to 199 waiting and the middle chat answer takes 80.2 s. A bound plus a chat lane brings it to 0.35 s while 178 bulk jobs are told to retry in 10 s, and cancelling abandoned calls saves 21,000 wasted tokens.
Load Balancing LLM Traffic: Count the Work, Weigh the Prefix Cache, Check Real Health, Drain Before Deploys
Six GPU replicas, two at 95% and four at 30%: round robin counts requests, and requests aren't equal. In a small simulation, least outstanding requests cuts p95 from 6.52 s to 3.05 s, prefix affinity lifts cache hits to 95% but pushes p95 to 11.45 s, a real health check takes errors from 48 to 2, and draining cuts 0 answers instead of 4.
A Message Queue for Document Ingestion: At Least Once, Leases, an Idempotent Consumer and a Dead Letter Queue
A queue doesn't lose a document, but it can hand one out twice. In a small simulation, a worker crash makes document two go from 3 to 6 chunks and the index holds 11 when the documents hold 8. An idempotent consumer brings it back to 8 with the same two deliveries, and a limit of three tries moves a poison file to a dead letter queue.
