다음을 통해 공유


Azure Cosmos DB part 2: How to Enable Geo replication of data

Introduction

In this article, we will learn how to replicate the data to any Azure region globally.

Global Distribution

Azure Cosmos DB allows to distribute the data globally to any available Azure region with a click. With, Azure Cosmos DB data is replicated in a transparent manner. Azure Cosmos DB also provides configurable options to replicate our data across multiple datacentres.

There are two ways to replicate the data –

  • Manual Replication
  • Automatic Replication

Each selected region is billed based on throughput (RUs) and data stored on SSDs for the cosmos db account. Throughput is billed as Request Units (RU) per second which is a currency for charging throughput for read, write and query operations on an Azure Cosmos DB container.

Consistency Levels

Cosmos DB has different consistency levels per account which applies automatically to all the databases and collections within cosmos account.

These consistency levels are –

  1. Strong - Strong consistency provides the most predictable and intuitive programming model and ensure that our versions of documents in our replica do not lag behind the primary. When we configure our account with strong consistency level, Cosmos DB provides linearizability guarantee which means that reads are guaranteed to see the most recent write. If our application requires all replica documents to exactly match the primary at any point in time, this strategy makes a lot of sense. The downside is that the primary write operation will be a lot slower than usual because that operation has to wait for every replica to confirm that the operation has been committed.
  2. Bounded Stateless - Bounded staleness consistency is most frequently chosen by globally distributed applications expecting low write latencies but total global order guarantees. Unlike strong consistency which is scoped to a single region, we can choose bounded staleness consistency with any number of read regions (along with a write region). Bounded staleness is great for applications featuring group collaboration and sharing, stock ticker, publish-subscribe/queueing etc.
  3. Session - Session consistency is most widely used consistency level both for single region as well as, globally distributed applications. It provides write latencies, availability and read throughput comparable to that of eventual consistency but also provides the consistency guarantees that suit the needs of applications written to operate in the context of a user.
  4. Consistent Prefix - Consistent prefix level guarantees that reads never see out of order writes. If writes were performed in the order `A, B, C`, then a client sees either `A`, `A,B`, or `A,B,C`, but never out of order like `A,C` or `B,A,C`. Consistent Prefix provides write latencies, availability and read throughput comparable to that of eventual consistency, but also provides the order guarantees that suit the needs of scenarios where order is important.
  5. Eventual - Eventual consistency is the weakest form of consistency which occurs because operations against the primary database commit immediately and do not wait for the replicas to confirm that they are committed. This is useful for scenarios where we need the highest tier of performance and the application does not require any ordering guarantees. Examples include count of Retweets, Likes or non-threaded comments.

 

Provision the replication of data globally

  1. Sign in to the Azure Portal (http://portal.azure.com).
  2. Create the Azure cosmos account as discussed in the part 1 -https://social.technet.microsoft.com/wiki/contents/articles/51596.azure-cosmos-db-introduction-part-1.aspx
  3. After the cosmos account created, open the Azure cosmos DB account.
  4. Click the Replicate data globally option on the left-hand side of the blade.
  5. In the Replicate data globally section, we need to select at least one region as read region to enable the manual failover and automatic failover for data replication.
  6. Here I have added the North Europe as the read region. We can associate multiple read regions with cosmos db account as per the need.


     7. Click the Save button to continue the locations as Read regions for account. This will enable the option of Manual and Automatic replication.

Let’s go through these options one by one.

Manual Failover

  1. In case of Manual failover, if any failure happens then the selected Read region will become the new Write region.
  2. In below screenshot, West Europe has been selected as Read Region and it will become the Write Region if any failure happens.

  1. Click OK button to save this setting for Manual Failover.

Automatic Failover

  1. To enable the Automatic Failure, we need to click the ON option.
  2. Now we need to select the read region which will be the Write region in case of failover.
  3. We can also select the multiple the Read region and set the priorities.  If we have selected multiple Read Regions, then we can drag and drop the read regions items to reorder the failover priorities.
  4. In below screenshot, two read regions West Europe and East Asia are selected. If any failover happens then Read region with high priority (West Europe has priority 1) will be Write Region. After this, if another failover happens then Read Region (East Asia) will automatically be Write Region.

Reference

/en-us/azure/cosmos-db/distribute-data-globally

So, this is how we can replicate the data globally to multiple Azure data regions.