Skip to main content
emnode
Site Reliability

Enable service-managed failover for Cosmos DB

One capability across every multi-region Cosmos DB account: make sure that when the primary write region goes dark, Azure promotes a secondary region's write region for you, automatically, instead of leaving your application stuck waiting for a human to react.

13 min·10 sections·AZURE

Last reviewed

Service-managed failover: the basics

What actually happens to a multi-region Cosmos DB account when its write region fails?

A Cosmos DB account that replicates to more than one region still has exactly one write region at a time when it is configured for single-region writes. Every insert, update and delete goes to that one region; the other regions serve reads from a replicated copy. This is a perfectly reasonable, lower-cost topology, and most production accounts run it. The catch is what happens when the write region has an outage. The read regions keep serving reads, but writes stop, because there is nowhere to send them, until the write region comes back or someone promotes a different region to take over.

Azure Advisor surfaces this gap as a reliability recommendation: 'Enable service managed failover for Cosmos DB account.' With service-managed failover turned on, Azure detects a primary region outage and promotes the next region in your failover-priority list to be the new write region, with no user action required. Writes resume against the new region automatically. With it turned off, a write-region outage means your application's writes are down until an operator notices, decides to fail over, and runs the promotion by hand, which is exactly the moment you least want to depend on someone being awake and confident.

Most accounts that lack this are not lacking it on purpose. An account gets a second region added for read latency or compliance, and the failover behaviour is simply left at its default. The work is to find every multi-region, single-write account in the estate, confirm its failover-priority order is the one you would actually want to promote, and switch service-managed failover on so the promotion happens for you rather than at three in the morning under pressure.

In this lesson you will learn how Cosmos DB expresses write-region failover, why a multi-region account on manual failover still has a single point of write failure, how to find every account in this state across a subscription, and how to switch them to service-managed failover safely after confirming the failover-priority order. The Advisor recommendation behind it is 'Enable service managed failover for Cosmos DB account', and the fix is a single command per account at no extra Azure cost.

Fun fact

The replica that could not rescue the write

Large regional cloud outages have a recurring pattern in the postmortems: teams discover that the expensive standby they were paying for did not take over on its own. The replica was healthy, the data was there, but the topology was configured to wait for a human decision, so writes stayed down until an operator stepped in. Cosmos DB's service-managed failover exists precisely to remove that human-in-the-loop decision for single-write accounts. Microsoft is explicit, though, that it is not instantaneous: declaring the outage and triggering service-managed failover can itself take significant time, potentially an hour or more, even for a full write-region outage. That is why Microsoft recommends a forced failover as the fast path when you need to restore writes quickly, and why you want the failover-priority order armed in advance rather than worked out during the event.

Finding accounts that cannot fail over on their own

Priya is the platform reliability lead at a payments company that runs several Cosmos DB accounts, most of them replicated to a second region for read latency and regional compliance. Azure Advisor has raised 'Enable service managed failover for Cosmos DB account' against three of them.

Rather than click through each recommendation, Priya starts by listing which accounts have more than one region but still have automatic failover switched off, so she can see exactly where the company is paying for a second region without getting the availability it should buy.

Start by listing every account, how many regions it spans, and whether automatic failover is on. The dangerous accounts are multi-region with failover off.

$ az cosmosdb list --query "[].{name:name, rg:resourceGroup, regions:length(locations), autoFailover:enableAutomaticFailover}" -o table
Name Rg Regions AutoFailover
---------------- ------------ --------- --------------
payments-prod payments-rg 2 False
ledger-prod payments-rg 2 False
analytics-read data-rg 1 False
# payments-prod and ledger-prod span 2 regions but will not fail over on their own.
# analytics-read is single-region, so failover does not apply to it.

A multi-region account with automatic failover off is paying for resilience it cannot use without a human. A single-region account is a different problem, and is not what this recommendation is about.

How Cosmos DB decides a write region and how failover changes thatdeep dive

A Cosmos DB account configured for single-region writes keeps an ordered failover-priority list of its regions. The region at priority 0 is the current write region; the rest are read regions ranked by the order in which they should be promoted. The 'enableAutomaticFailover' property on the account governs what happens when the priority-0 region becomes unavailable. When it is false, nothing promotes on its own: a human must trigger a failover, which reorders the priority list and moves writes to a new region. When it is true, Azure performs that promotion for you, moving writes to the next region in the priority order with no user action.

Two details matter when you arm this. First, service-managed failover only applies to accounts with a single write region; an account configured for multi-region writes already accepts writes in every region and does not need it. Second, automatic failover honours the failover-priority order you have set, so the order is not a formality: it is the actual decision about which region your application runs in after an outage. Confirm it before you enable, because enabling automatic failover is also accepting that order as your recovery plan.

Microsoft is clear about the limits. Service-managed failover promotes a secondary on its own, but Microsoft documents that declaring the outage and triggering the failover can take significant time, potentially an hour or more, and this applies to a full write-region outage, not just an edge case. For faster recovery Microsoft recommends performing a forced failover yourself rather than waiting for the service to trigger. Service-managed failover is therefore not a promise of instant recovery; it removes the need for a human to decide and run the promotion, but the detection-and-trigger latency still sits with Microsoft. For partial-region resilience Cosmos DB offers per-partition automatic failover (PPAF), which fails over individual partitions to a secondary and recovers far faster than a whole-account failover. Service-managed failover also pairs naturally with zone redundancy within each region, which protects against a single datacentre failing without needing a cross-region failover at all.

What is the impact of leaving failover on manual?

The direct impact is write downtime measured in human reaction time. When the write region of a manual-failover account fails, reads may continue from the secondary, but every write fails until an operator notices the outage, decides to fail over, and performs the promotion. During a large regional event, that is the worst possible moment to depend on a person: alerts are noisy, the on-call engineer may be one of many teams scrambling, and the decision to fail over a production database carries its own hesitation. Minutes become hours, and every one of them is writes your application cannot accept.

The second-order impact is that the cost of the resilience is already being paid without the benefit being collected. A multi-region account is charged for the throughput and storage of every region it replicates to. If failover is manual, you are paying the full price of running in two regions and getting only the read-latency half of what that buys. The availability half, the reason multi-region exists, sits switched off until someone turns it on by hand under pressure.

On the reliability side, Azure Advisor raises this precisely because a single-write, multi-region account with manual failover has a single point of write failure that the account's own topology is already equipped to remove. Enabling service-managed failover is the cheapest, most defensible step you can take to close that gap, and it is the kind of recommendation that reads badly in a postmortem if it was open at the time of an outage.

How do you arm automatic failover safely?

Work this as one capability across the estate rather than clicking individual recommendations. The order matters: confirm the failover-priority order before you enable automatic failover, because enabling it is accepting that order as your recovery plan.

1. Inventory multi-region, single-write accounts

List every Cosmos DB account, how many regions it spans, and whether automatic failover is on. The accounts that matter are those with two or more regions and 'enableAutomaticFailover' set to false. A single-region account is a different conversation: it needs a second region added before failover means anything.

2. Confirm the failover-priority order on each

For each multi-region account, check the failover-priority list and decide whether the region at priority 1 is genuinely where you want writes to land after an outage, given latency, data residency and capacity. This order is your recovery plan, not a formality. Fix it before enabling automatic failover, so the automatic promotion goes where you intend.

3. Enable service-managed failover

Switch automatic failover on for each confirmed account. The change is a single command and takes effect without downtime: it does not move the write region, it only arms the account to promote the secondary on its own if the primary fails. Prioritise the accounts whose write outages cost the most: revenue paths and systems of record first.

4. Standardise it in your infrastructure code

Set 'enableAutomaticFailover: true' in the Bicep or template module that provisions Cosmos DB accounts, alongside an explicit failover-priority order and zone redundancy where the region supports it, so every new multi-region account is born with automatic failover armed rather than discovered missing on the next Advisor report.

# Arm service-managed failover on a confirmed multi-region account.
# This does NOT move the write region; it only enables automatic promotion.
az cosmosdb update \
  --name payments-prod \
  --resource-group payments-rg \
  --enable-automatic-failover true

# Confirm (or set) the failover-priority order: priority 0 is the write region,
# the rest are promoted in ascending order. This order IS your recovery plan.
az cosmosdb failover-priority-change \
  --name payments-prod \
  --resource-group payments-rg \
  --failover-policies 'North Europe=0' 'West Europe=1'

# --- Standardise it in Bicep so new accounts are born armed ---
# resource cosmos 'Microsoft.DocumentDB/databaseAccounts@2024-11-15' = {
#   name: accountName
#   location: primaryRegion
#   properties: {
#     databaseAccountOfferType: 'Standard'
#     enableAutomaticFailover: true
#     locations: [
#       { locationName: 'North Europe', failoverPriority: 0, isZoneRedundant: true }
#       { locationName: 'West Europe',  failoverPriority: 1, isZoneRedundant: true }
#     ]
#   }
# }

Quick quiz

Question 1 of 5

Azure Advisor raises 'Enable service managed failover for Cosmos DB account' against a two-region account configured for single-region writes. What does this recommendation actually change?

You can now treat write-region failover as one capability rather than a scatter of Advisor findings: inventory every multi-region, single-write account, confirm the failover-priority order is the recovery plan you actually want, arm service-managed failover so the secondary promotes itself, and standardise it in your infrastructure code so new accounts are born armed. The fix is a single command per account and adds nothing to the bill you are already paying for the second region.

Back to the library