What is Cosmos DB?
Cosmos DB is an updated version of Microsoft's existing Document DB Service which is a NoSQL model. The definition of Cosmos DB is a globally distributed, horizontal scale database with Multi-model and Multi-API support.
Is the definition quite confusing? Yes, let me explain it.
First, let’s see why the name is Cosmos. Cosmos means Universe, a well-ordered Universe. This name itself explains the main advantage of Cosmos DB which is globally distributed and interlinked.
What is globally distributed?
Your database will be running on multiple Geo location meaning multiple data centers of Microsoft Azure. It helps the responsiveness of your application by storing the data in the nearest possible data center from your location. You can pick which data centers where you wish to store data with a click of a button.
Why do I need a globally distributed Database?
Let’s take a scenario to explain it correctly. You have your database server running in the US & you have clients across the globe like Australia, UK, India, and the US as well. The problem you would face in your application is latency. It is not the same for all clients. Clients away from the US will take much time to load your application than from the US. This problem is solved by Cosmos DB where you can pick multiple data centers to store your data which is near to the clients. The data gets replicated to each of the data centers you choose.
Multi-model, multi-API support
Azure Cosmos DB natively supports multiple data models including documents, key-value, graph, and column-family. The service also supports popular database APIs for data access and querying. Cosmos DB’s database engine currently supports DocumentDB SQL, MongoDB, Azure Tables, Gremlin, Cassandra, Graphs and so on.
How it supports multi-model
The common question is how is it supported by multi-model and how does it understand the data types if so?
The answer is ARS (Atoms, Records, Sequences). Basically, the Cosmos DB translates all the data models into atom-record-sequences.
The core content-model of Cosmos DB’s database engine is based on atom-record-sequence (ARS).
- Atoms consist of a small set of primitive types like string, bool, and number. Atoms help achieve our relational database model.
- Records is also called a structure in a relational database; it is called rows and the record is a collection of columns and different data types.
- Sequences are arrays consisting of atoms and records. Sequences generate the numeric value. Each database needs a unique value in row sequence support for this. In Cosmos DB it helps to create the portioned key.
Advantages of Cosmos DB
- Globally distributed - You can select multiple geolocations to replicate the data.
- Low latency - Ensure the low latency for both write and read a data.
- High availability - Failover concept help us data availability in all time.
- Auto-indexing - Auto indexing help to reduce the latency in reading. It is also providing custom indexing which developer can do it.
- High consistency - It provides five level of choice consistency.
- Your system is always on because your data replicated in multiple datacentres.
- Low pricing - Compare with AWS DynamoDB Azure Cosmos DB is cheaper.
Pricing
Please look at the below link to get knowledge about pricing.
https://azure.microsoft.com/en-au/pricing/details/cosmos-db/
In this article, we have seen Cosmos DB as a globally distributed horizontally scaled multi-model and multi API support database service & how it works in ARS model. My next article will be focused on how global distribution works, and what is latency model support by Cosmos DB as well as the failover concept.