You are currently viewing Azure Cosmos DB replicating data globally

Azure Cosmos DB replicating data globally

Now a days, most applications target global audience. People from all around the world can access the application, can create data in application and can view that data.

Why replication is required ?

If you are working on a global application and if you deployed the application and its Cosmos DB databases in only one region (e.g. let’s say United States), then it may perform good for the people in that region may be able to access the application very quickly. But the application may appear slower to the people who are accessing the application from other parts of world (e.g. Europe, India, China).

This is because the requests from other parts of world will have to travel farther to reach your application. This will result in high latency.

We know that application’s performance is measured in terms of latency and throughput.

Latency is end to end time for end user from issue requests till viewing the results. It should be as low as possible. The throughput is the number of requests that can be processed per second and it should be as high as possible.

So, if you are working on global application, how will you ensure low latency ?

The answer is Geo-replication.

What is Geo-Replication ?

Azure has data centers in different geographical locations. They are referred to as Azure regions. You can replicate your Cosmos DB database in different geographical region using single button click.

The requests to Cosmos DB account will be automatically redirected to the Azure region which is nearer to the location of client, reducing the overall latency.

Please note that this will not affect throughput of your application. Irrespective of the location from where the Cosmos DB is serving the client requests, the throughput will be same.

Replication vs Consistency Levels

Consistency level becomes very important when you replicate the data in Cosmos DB in multiple Azure regions. When you have Cosmos DB account in only one region, Azure maintains 3 copies of data. But updating these 3 copies so very swift operation and happens within few seconds. Hence there is very less chance of reading the stale data from Cosmos DB.

When you replicate data globally, the replication may take few minutes to reflect the latest data. That’s where consistency levels come into play.

There is one important point to note, you do not need to pay any additional cost for enabling geo-replication. But Geo-replication will have impact on the overall cost of the application as it will increase the number of read /write calls from one region to another. The number of calls will depend on the consistency level you have set on the Cosmos DB account.

For example. if you have set strong consistency level, then all your read requests will have to check with quorum of Cosmos DBs to ensure that the latest commit have been updated in every copy, increasing number of read calls. Also, when a commit happens on primary copy, it has to be replicated in other regions, increasing number of write calls.

In addition to low latency, one other major advantage of enabling geo-replication is, you can ensure business continuity even if there is an unfortunate natural disaster or failures in an Azure region.

Cosmos DB also allows you to enable multi-master scenarios, allowing your clients to write data to the Cosmos DB in the nearest Azure region. I will try to cover this topic in one of my future blogs.

How to enable Geo-Replication ?

If you are logged in to Azure portal, navigate to your Cosmos DB account.

Then select the replicate data globally option from the left side menu. It will bring a panel which will show different regions where you can replicate the data.

For enabling replication, you just need to click on the map. Alternatively, you can click on Add region hyperlink and type the name of region which you want to add.

I hope this article helps you to understand how you can enable geo-replication for your sites. Let me know your thoughts.

Leave a ReplyCancel reply