Global Replication and Failover
Learn when and how to distribute Cosmos DB data globally, configure automatic failover policies, and perform manual failovers β including the critical detail that a recovered region returns as read-only.
Why go global?
Imagine GlobeCart has warehouses in 12 countries. If all your product data sits in one warehouse in Sydney, customers in London wait for every request to fly halfway around the world.
Global replication copies your data to multiple Azure regions so reads (and optionally writes) happen close to each customer. If Sydney burns down, London keeps serving.
Jakeβs scenario: taking GlobeCart global
π Jake at GlobeCart has 50M products served from East US. European customers complain about 200ms+ latency on product searches. His plan:
- Add West Europe and Southeast Asia as read replicas and measure the resulting application read latency.
- Configure automatic failover β if East US goes down, West Europe takes over writes.
- Keep a single write region (for now) β simpler consistency, lower cost.
Single-write vs multi-write architecture
| Aspect | Single-Write Region | Multi-Write Regions |
|---|---|---|
| Write latency | Low in write region, high everywhere else | Low everywhere β writes go to nearest region |
| Availability SLA | Configuration-dependent; eligible PPAF configurations can provide five nines | Qualifying multi-region multi-write configurations provide five nines |
| Conflict resolution | Not needed β one writer | Required β Last-Writer-Wins or custom |
| Consistency options | All five levels in supported account configurations; PPAF excludes Bounded Staleness | Strong is not supported; Bounded Staleness is a documented anti-pattern |
| Cost | Standard RU/s Γ regions | Higher β every region serves writes |
| Complexity | Simple β one source of truth | Complex β conflict handling, eventual consistency |
Automatic failover
For classic account-level service-managed failover (also called automatic failover), enable the feature and configure regional priority. Microsoft decides when to declare an outage and promotes an eligible healthy region in that order. This is not a separate always-on feature with a different customer-enabled automatic mechanism.
Failover priority (Jake's config):
Priority 0: East US β current write region
Priority 1: West Europe β first to promote if East US fails
Priority 2: Southeast Asia β second in line
Critical exam detail β the recovered region: After classic account-level failover, a recovered East US does not automatically reclaim the write role. Once regions are healthy, use the supported change-write-region operation to return writes there. PPAF is different: it automatically fails affected partitions back after recovery.
Exam tip: automatic failover timing
Service-managed account failover is not instant. Declaring an outage and triggering recovery can take significant time, potentially one hour or more. Do not invent a customer-configurable detection timer or a guaranteed five-minute recovery interval.
Writes can remain unavailable while recovery is pending; healthy regions can continue serving eligible reads. Choose the recovery mechanism against the applicationβs actual requirements.
Planned write-region change versus forced failover
An operator can change the write region while all regions are healthy. Replication catches up before promotion, so this planned operation has no data loss. Use it for:
- Planned maintenance or region migration
- Disaster recovery drills
- Moving the write region closer to shifting traffic patterns
During an active outage, the planned operation might not be available because it requires healthy regions. A region-offline / forced-failover operation is a different recovery path. With weaker-than-Strong consistency, acknowledged writes that have not replicated can be lost. Do not apply a blanket βmanual means zero data lossβ rule to both operations.
# Trigger manual failover β promote West Europe to write region
az cosmosdb failover-priority-change \
--name globecart-cosmos \
--resource-group rg-globecart \
--failover-policies "westeurope=0" "eastus=1" "southeastasia=2"
// Verify current write region via SDK
AccountProperties account = await client.ReadAccountAsync();
foreach (AccountRegion region in account.WritableRegions)
{
Console.WriteLine($"Write region: {region.Name}");
}
Account-level failover versus PPAF
| Feature | Service-managed account failover | Per-partition automatic failover |
|---|---|---|
| Scope | Account write-region promotion | Only affected partitions |
| Trigger | Microsoft declares outage and initiates recovery | Automatic partition-health detection |
| Recovery timing | Can take an hour or more to trigger | Documented partition recovery objective under three minutes at P99 |
| Data loss risk | Depends on consistency and replication state | Strong preserves RPO zero; weaker levels can diverge |
| Failback | Operator changes write region after recovery | Automatic, with incremental catch-up |
| Configuration | Enable service-managed failover and regional priorities | Eligible single-write provisioned NoSQL account, Direct mode, supported SDK and tier |
Exam tip: identify the actual recovery operation
- Planned change-write-region requires healthy regions and catches up replication before promotion.
- Region-offline recovery during an outage can lose unreplicated writes with weaker consistency.
- Classic account-level service-managed failover and PPAF have different scope, timing and failback behavior.
- Check the current SLA and eligibility; multi-write is not the only documented path to five-nines availability.
π¬ Video walkthrough
Flashcards
Knowledge Check
GlobeCart uses classic account-level service-managed failover, not PPAF, with priority: East US (0), West Europe (1), Southeast Asia (2). West Europe is promoted during an East US outage. After East US recovers, which region remains the writer without an operator change?
All GlobeCart regions are healthy. Jake wants to move its write region from East US to West Europe for planned maintenance without data loss. Which operation fits?
Which listed consistency level is unsupported with multi-region writes?
Next up: Multi-Region Writes β configure active-active writes and understand conflict handling.