Azure Cosmos DB Configure multi-region writes and Enable service-managed failover for your Azure Cosmos DB account
By: Date: 24/08/2024 Categories: azure Tags:

Configure multi-region writes in your applications that use Azure Cosmos DB

In multiple region write scenarios, you can improve performance by writing just to the area closest to your application instance. Azure Cosmos DB handles the replication for you in the background.

After you activate your account for multiple write regions, you must make two adjustments to your application to the ConnectionPolicy. Within the ConnectionPolicy, set UseMultipleWriteLocations to true and pass the name of the region where the application is deployed to ApplicationRegion. This action populates the PreferredLocations property based on the geo-proximity from location passed in. If a new region is later added to the account, the application doesn’t have to be updated or redeployed. It automatically detects the closer region and auto-homes on to it should a regional event occur.

Note:: Azure Cosmos DB accounts initially configured with single write region can be configured to multiple write regions with zero down time

Azure Portal Console

To use multi-region writes, configure your Azure Cosmos DB account for several regions through the Azure portal. Specify which regions your application can write to.

To enable multi-region writes, use the following steps:

  1. Go to Azure portal
  2. Go to your Azure Cosmos DB account and select from the menu, open the Replicate data globally pane.
  3. Under the Multi-region writes option, choose enable. The existing regions are automatically added to the read and write regions.
  4. You can add more regions by selecting the icons on the map or by selecting the Add region button. All of the regions you add are read and write enabled..
  5. After you update the region list, select Save to apply the changes.

Enable service-managed failover for your Azure Cosmos DB account

The Service-Managed failover option allows Azure Cosmos DB to fail over to the region with the highest failover priority with no user action when a region becomes unavailable. When service-managed failover is enabled, the region priority can be changed. To enable service-managed failover, your account must have at least two regions.

  1. Go to Azure portal
  2. Go to your Azure Cosmos DB account and select from the menu, open the Replicate data globally pane.
  3. At the top of the pane, select Service-Managed Failover.

4. On the Service-Managed Failover pane, make sure that Enable Service-Managed Failover is set to ON.

Ref: Configure multi-region writes