Monday, June 21, 2021

Azure Cosmos DB Dedicated Gateway Server & Integrated Cache

 


     Cosmos DB team announced a new way named Dedicated Gateway to connect to Azure Cosmos DB. As you might know, there is already a standard gateway to connect to Cosmos DB. A dedicated or Standard gateway means that there is a computer staying between the Cosmos DB replica set and your application. Your application request goes to the gateway server and then goes to the Cosmos DB database. The biggest difference between Standard Gateway and Dedicated Gateway is, that you do not share the dedicated gateway server with other Cosmos DB customers.

     Dedicated Gateway is totally yours and you are responsible for its costs. Depending on your application size, you can select different sizes of gateway servers. Here are the current options.

Name vCPU Memory Price
D4s 4 16 GB $0.41 per hour
D8s 8 32 GB $0.82 per hour
D16s 16 64 GB $1.63 per hour

     Select it wisely because you can not change the size of your gateway server later. You can have up to five dedicated gateway servers for your Cosmos DB database. All gateway servers use the same connection string, and each dedicated gateway server works independently. You should start with one dedicated gateway server and add more nodes when you need to. 

    If you have global distribution feature for your databases, there will be identical dedicated gateway server/s in each region. For now, Dedicated Gateway Servers support only SQL API accounts. Adding a Dedicated Gateway server to your account is easy. Select Dedicated Gateway from the left side and select the size and the number of Gateway Server you like to have. Click Save and your gateway server should be up and running.


     After the Dedicated Gateway server is up and running, you can use a specific connection string for your dedicated gateway server in the Keys tab. Copy and paste the new connection string to your application to use the dedicated gateway server.



Why do we need a Dedicated Gateway server?

     It looks like Microsoft wants to use the dedicated gateway server to add more features like In-Memory Caching to Azure Cosmos DB without using the Cosmos DB server's resources. I am sure we will see all types of features will be introduced to Cosmos DB thanks to Dedicated Gateway servers.

     Caching data is a great way to improve the performance of any solution. Microsoft added In-Memory cache to Azure Cosmos DB by using Dedicated Gateway Server. Unlike SQL Server's In-Memory features, data is getting cached out of the database server in Azure Cosmos DB. Caching data operations does not take any resources from Cosmos DB servers.

     The integrated cache feature can cache query results or point reads done by SDK. It uses Least Recently Used(LRU) eviction policy to remove cached items from memory. If item or query results are cached, the gateway server returns data without calling Cosmos DB. This means you end up with 0 Request Unit charge for cached data. Integrated Cache can save you money if your application is read-heavy and calls the same data frequently.

     Integrated Cache supports only Eventual Consistency, if your data request has a different consistency level, your request will bypass the integrated cache to get the latest version of data from a database. This is where things get tricky. I am sure you are not going to change the consistency level of your database to eventual to use an Integrated cache. You need to find the queries or read points that read the same data repeatedly. Or you might have a couple of queries that might be fine with stale data. You can change these queries or read point's consistency to Eventual in SDK to use the Integrated Cache feature.

     The Integrated Cache feature is free, and it can save you money. You still need to pay for the Dedicated Gateway server. You want to be sure that you are still saving money after paying for the Dedicated Gateway server.





No comments:

Post a Comment