Learn about Azure Cosmos DB Globally Distributed Databases

By:   |   Updated: 2022-02-22   |   Comments   |   Related: > Azure Cosmos DB


Free SQL Server Performance and Monitoring Report


Dear Database Professional,

Download your free copy of the MSSQLTips.com SQL Server Performance and Monitoring Report. This survey was conducted in 2022 and polled 588 database professionals about various aspects of tuning and optimizing SQL Server.

Click here to download the free report

Problem

Azure Cosmos DB supports a globally distributed database for reading and writing local database replicas. In this tutorial, we will explore the purpose and benefits of a globally distributed database and the way to configure it using the Azure portal.

Solution

In today's digital world, applications require high responsiveness and availability. The applications can be social media platforms, e-commerce websites, international financial systems, etc. Users should get the required data with low latency, consistency, and availability. It means the application response should not change with the location wherever it may be in the world.

Azure Cosmos DB globally distributed database feature replicates data to associated regions. It is designed to meet the requirement of low latency, high throughput, and data consistency. It also supports elastic scalability of the storage and throughput as per the application workload.

The Cosmos DB administrator can configure the globally distributed database in any supported Azure region. Once we configure it, Cosmos DB replicates a single system image of the globally distributed database for the application to read and write locally. Another benefit of Cosmos DB is that you do not need to pause or redeploy applications to configure (add/remove) a region.

You can browse products available by region to get a supported Azure Cosmos DB regions list.

Azure Cosmos DB regions list

The benefit of a global distribution database

The global distribution database offers the following benefits:

  • Build global active-active apps: Azure Cosmos DB supports read and writes in every region using the novel multi-region write replication protocol. The multi-region write enables unlimited write and reads scalability, 99% read\write availability, and guaranteed read-write with less than 10ms latency.
Azure Cosmos DB global distribution

Image Reference: Microsoft docs

  • Build highly responsive and available applications: You can build applications with multi-region writes capabilities, guaranteed data consistency level, and 99.999% highly available database. If a region is down, another region automatically handles the database requests.

The following image shows that the container data is distributed in the following ways:

  • Within a region
  • Across region
Azure Cosmos DB physical partitions
  • Automatic and Manual failovers for business continuity: Azure Cosmos DB automatically performs the failover during a regional outage. It ensures the minimum latency, consistency, and throughput SLAs. You also get manual failover for performing disaster recovery (business continuity) drills.
  • Scaling read and write throughput: You can configure auto-scaling reads and writes throughput in all Azure regions. Azure uses financially backed SLAs for the guaranteed provisioned throughput. You can refer to SLA for Azure Cosmos DB for more details.

How do we configure Azure Cosmos DB regions?

In this section, we will configure the globally distributed Azure Cosmos DB. Before proceeding, you can follow earlier tips to implement the Azure Cosmos database.

As shown below, my demo database has the following configurations:

  • Read Locations: East US 2
  • Write Locations: East US 2
configure the globally distributed Azure Cosmos DB

Currently, my Cosmos DB account has no read regions. Click on the Replicate Data Globally option from the Azure Cosmos DB account. As shown below, by default, multi-region writes are disabled.

configure the globally distributed Azure Cosmos DB

Click on the +Add Region option to configure a region for reads, writes, and availability zone. Alternatively, you can click on the hexagons on the map to select your desired Azure region. Add the region and click on save for configuring it.

It displays a message at the top – when you add a region to your account, you will be billed for the additional RU/s and storage copied to the region.

configure the globally distributed Azure Cosmos DB

Click on Save to configure the Azure regions for the Cosmos DB account.

configure the globally distributed Azure Cosmos DB

After the configuration, the map shows the two regions for the Azure Cosmos DB account.

  • Write region: East US 2
  • Read region: North Europe

It highlights the regions in the map with a tick configured for the reading and writes regions in Azure Cosmos DB.

configure the globally distributed Azure Cosmos DB

Configure Multi-Region writes

As shown in the replicate data globally page, Azure Cosmos DB multi-region writes are disabled by default.

Azure Cosmos DB multi region writes

Click on Enable, and it changes the configured regions with options – Reads Enabled and Writes Enabled, as shown below.

Azure Cosmos DB multi region writes

Note: Once we enable multi-region writes, all the current read regions on the account will become read and write regions.

Enable automatic failover in Azure Cosmos DB

In the replicate data globally page, you get options for manual failover or automatic failover. You need to configure the automatic failover and failover priorities in region failovers.

Azure Cosmos DB enable automatic failover

Toggle the switch to enable automatic failover. If you have multiple read regions, it displays the priorities for them.

Azure Cosmos DB enable automatic failover

You can drag-drop regions up-down in the list for choosing the read regions priorities as per your choice. For example, the above screenshot sets priority 1 for the North Europe region.

In the below screenshot, we adjusted the regions list to mark the East US region for priority 1.

Azure Cosmos DB enable automatic failover

Click on Save to configure the automatic failover with the specified priorities.

Perform manual failover on an Azure Cosmos DB

You can manually failover to promote a read region as the new writer region. This way, you can test your application resiliency and perform regular DR drills to ensure business connectivity.

Click on Manual Failover and select the read region to become the new write region.

Azure Cosmos DB manual failover

For example, I selected East US as a new write region. You need to check – I understand and agree to trigger a failover on my current Write Region.

Azure Cosmos DB manual failover

Click OK, and it triggers the manual failover.

Azure Cosmos DB manual failover

Refresh the Azure Cosmos DB account for updated write and read locations after the manual failover. As shown below, East US is the write location for my Cosmos DB.

Azure Cosmos DB manual failover
Next Steps
  • Configure a globally distributed database in Azure Cosmos DB per your preferred Azure regions.
  • Configure automatic failover for Cosmos DB in case of any issue with the primary region.
  • Refer to Microsoft official documentation on Cosmos DB.





get scripts

next tip button



About the author
MSSQLTips author Rajendra Gupta Rajendra Gupta is a Consultant DBA with 14+ years of extensive experience in database administration including large critical OLAP, OLTP, Reporting and SharePoint databases.

View all my tips


Article Last Updated: 2022-02-22

Comments For This Article

















get free sql tips
agree to terms