Concepts
To perform manual failovers and move single master write regions in Microsoft Azure Cosmos DB, you can follow a few steps. Manual failovers are useful when you need to switch the write region in case of a region-wide outage or during planned maintenance. This article will guide you through the process of performing manual failovers in Azure Cosmos DB.
Step 1: Understand Azure Cosmos DB Regions and Regions Pairing
Azure Cosmos DB is a globally distributed database service, allowing you to replicate your data to multiple regions across the world. Each region in Azure Cosmos DB represents a separate geographical location where your data is stored. Regions are grouped into region pairs, where each pair consists of a primary and secondary region.
The primary region is responsible for handling write operations, while the secondary region serves as a backup and supports read operations. By default, the primary region is the region closest to your application, providing low latency for write operations.
Step 2: Determine the Current Write Region
Before performing a manual failover, you need to determine the current write region for your Azure Cosmos DB account. To do this, you can use the Azure portal or Azure CLI.
Using Azure Portal:
- Navigate to the Azure portal (
portal.azure.com
) and login with your Azure account. - Search for and select your Azure Cosmos DB account.
- In the account overview page, click on the Keys blade.
- Note down the value of the PRIMARY CONNECTION STRING field.
Using Azure CLI:
- Open Azure CLI or Azure Cloud Shell.
- Run the following command to get the connection string for your Azure Cosmos DB account:
- In the Azure portal, navigate to your Azure Cosmos DB account.
- In the account overview page, click on the Failover blade.
- Select the secondary region that you want to promote as the new write region and click on the Failover button.
- Open Azure CLI or Azure Cloud Shell.
- Run the following command to failover to the secondary region:
- If you retrieved the connection string in Step 2, update your application or service with the new primary connection string.
- If you’re using Azure CLI, you can run the same command as Step 2 to get the new write region’s endpoint URL.
az cosmosdb show --name
Note: Replace
with the name of your Azure Cosmos DB account and
with the name of your resource group.
Note down the output of this command, as it provides the endpoint URL of the current write region.
Step 3: Perform the Manual Failover
Once you have identified the primary region, you can initiate the failover process to promote the secondary region as the new write region. Follow the steps below to perform the manual failover.
Using Azure Portal:
Using Azure CLI:
az cosmosdb failover-priority-change --name
Note: Replace
with the name of your Azure Cosmos DB account,
with the name of your resource group, and
with the failover policy JSON array.
The failover policy JSON array specifies the order of failover regions. Include all the regions in the failover order, separating them with commas. The first region in the list will be promoted as the new write region.
Step 4: Verify the Failover
After initiating the failover, you should verify if the write region has been successfully switched to the new region. Make the following checks:
Step 5: Revert or Repeat Failover
Once the failed-over region is back online and operational, you have the option to revert the failover. Reverting the failover reinstates the original primary region as the write region.
To revert a failover, follow the same steps mentioned in Step 3 but select the original primary region instead of the secondary region.
Remember, manual failover requires careful consideration of the failover timing, network latencies, and application dependencies. It’s recommended to thoroughly test failover scenarios before implementing them in a production environment.
That concludes the process of performing manual failovers to move single master write regions in Azure Cosmos DB. By following these steps, you can ensure high availability and resilience for your applications using Azure Cosmos DB.
Answer the Questions in Comment Section
When performing a manual failover to move a single master write region in Azure Cosmos DB, the primary region becomes the new secondary region.
–
True
–
False
Correct answer:
False
Which Azure Cosmos DB API supports manual failovers to move single master write regions?
–
SQL API
–
MongoDB API
–
Cassandra API
–
Gremlin API
Correct answer:
SQL API
During a manual failover in Azure Cosmos DB, data is temporarily unavailable for read and write operations.
–
True
–
False
Correct answer:
True
How many regions can be designated as writable regions in Azure Cosmos DB?
–
Up to 2 regions
–
Up to 3 regions
–
Up to 4 regions
–
Up to 5 regions
Correct answer:
Up to 4 regions
Which Azure PowerShell cmdlet is used to initiate a manual failover in Azure Cosmos DB?
–
Invoke-AzCosmosDBManualFailover
–
Start-AzCosmosDBManualFailover
–
Do-AzCosmosDBFailover
–
Perform-AzCosmosDBFailover
Correct answer:
Invoke-AzCosmosDBManualFailover
During a manual failover in Azure Cosmos DB, the data consistency across regions is guaranteed.
–
True
–
False
Correct answer:
False
Which programming language can be used to perform a manual failover in Azure Cosmos DB using the Azure SDKs?
–
Java
–
C#
–
Python
–
All of the above
Correct answer:
All of the above
What happens to the original write region when a manual failover is performed in Azure Cosmos DB?
–
It becomes the new read region
–
It becomes disabled
–
It becomes unavailable
–
It remains as the write region
Correct answer:
It remains as the write region
In Azure Cosmos DB, automatic failover to a secondary region occurs when the primary region becomes unavailable.
–
True
–
False
Correct answer:
True
When performing a manual failover in Azure Cosmos DB, how is the new write region determined?
–
It is randomly assigned
–
It is based on the region with the lowest latency
–
It is based on the region with the highest throughput
–
It is manually selected by the user
Correct answer:
It is manually selected by the user
Great article! I was curious about the downtime involved during a manual failover. Could anyone share their experience on this?
Thanks for this informative blog post!
When moving single master write regions, how do you ensure data consistency?
Can someone explain how the choice of the new write region should be made in a practical scenario?
Nice blog! Helped me a lot in understanding the failover process.
Are there any additional costs associated with performing manual failovers?
Excellent breakdown. This was much needed!
What happens to the read replicas during a manual failover?