Azure Cosmos DB Overview
1. What is Azure Cosmos Db?
Azure Cosmos Db is Microsoft's proprietary globally distributed, launched in May 2017.
This is a Cloud-based database. That means your database is built, deployed, and delivered through a cloud platform.
It is a NoSQL database. Your database could be stored in multi models-database, such as JSON documents store, Graph DBMS, Key-value store, and Wide column store, instead of columns and rows used by relational databases, such as SQL, Oracle, etc.
With Azure Cosmos Db, which is highly responsive and always online, we can build an application with low latency and high availability, and get the response data in milliseconds.
2. Why should we use it?
Azure Cosmos Db support multi-model database.
You can store data in multiple ways, by using different APIs:
API | Database |
SQL API |
JSON document database: non-relational database, store and query data as JSON documents |
MongoDB API |
MongoDB: A source-available cross-platform document-oriented database program |
Cassandra API |
Apache Cassandra: an open-source, NoSQL database, and designed to handle large amounts of data across many commodity servers with high availability and no single point of failure |
Gremlin API |
Graph database: Store data in graph structures, semantic queries with nodes, edges, and properties |
Table API |
Azure Table Storage: Store NoSQL database (non-relational structured data) in the cloud by using a schemaless design and a key/attribute store |
Azure Cosmos Db will save your life from building a multi-center data environment.
If you want to build a large-scale globally distributed application, a multi-center data environment should be required, which will take a lot of time, but Cosmos DB has already supported it and will help you skip those steps. You only have to configure it to replicate your data to all of your targeted regions.
Low latency.
With 60+ announced regions, you can easily place the data closer to the users, then they can have the minimum latency.
Elastic Scale.
Your cost is calculated by RU, which is calculated by 1 KB of data in 1 second. We can define max RU to manage throughput requirements and your money.
When you set max RU = 1000 RU/s, if the throughput is over 1000 RU/s, an exception will be thrown. Cosmos DB starts rejecting the requests with 429 http status code then you can check your throughput, or update max RU in 2 ways: via the Azure portal or automatically via the Azure CLI.
Support to create social media applications. (2)
Social media applications need to store User Generated Content (UGC), such as text, images, videos, comments, posts, tweets, etc. UGC is unstructured data, it is a combination of free-form text, relationships, tags, etc. UGC required different and dynamic structures, that's why they cannot be stored in relational databases, which have fixed schema. But NoSQL database, schema-free, can do it. Easy to search content with Azure Cognitive Search - a cloud search service. Azure Cognitive Search provides APIs, and tools for building a search engine within a few minutes. Graph database with gremlin API is the best for sorting social media followers.
Cost.
100 RU/s will cost £8.71 per month, a very cheap price for a global data center when compared with planning a multi-center data.
So imagine that you have a global data center, and in order to support your applications smoothly, you have to spend plenty of money and time. That’s why we can say: 100 RU/s will cost £8.71 per month is too cheap
On the other hand, we can try CosmosDb for free.
You can try this link to download: Install and develop locally with Azure Cosmos DB Emulator | Microsoft Learn
Step by step instructions to install:
You have to accept the license term
Install - Agree
then, installing
Installing
finish
Install - Finish
After installing, you can go to this Azure Cosmos Db Emulator shortcut to open the emulator
Emulator - Shortcut
After opening, you will get the notification at the corner of the screen
Emulator - Starting
and here is the notification when Azure Cosmos Emulator started
Emulator - Started
Here is the UI:
UI - Web - Url
Yes, we got the Web UI,
with default URL is LOCAL-Azure Cosmos DB Emulator
In the web UI, we can try a sample at 1
UI - 1
or learn more by reading document at 2
UI - 2
here is the explorer
UI - Explorer
the query UI
UI - Query
the result
UI - Result
you also have a minimap (code outline)
UI - Minimap
3. Behind the scenes
Case sensitive and only order by 1 column at default search
Quite expensive if we only have a small or medium system
The migration of data from on-premises to cloud may take some time
Be careful when using partitioning. Every partition has to have PartitionKey. Microsoft guarantees that all the documents with the same PartitionKey are stored in the same Logical Partition. The maximum size of a logical partition (and consequently a physical partition) could not exceed 20 GB. We should choose the correct PartitionKey to make sure that every logical partition cannot exceed 20 GB.
4. When should we use it?
Transactional volumes have many thousands of transactions per second
You will get some challenges: concurrency, latency, and availability
Distributed databases are the solution, but maintenance can still be a costly and time-consuming exercise.
Azure CosmosDb will handle these challenges. It will be deployed worldwide across all Azure regions. Cloud-based will provide minimum latency and high availability
Database contain many parent-child relationships
In this case, document-oriented databases are much better with object-oriented approaches, and Azure CosmosDb provides NoSQL document database.
Your system is complex networks and relationships
Relational databases present a less-than-optimal solution. Because relationships between entities do not actually exist in a relational database.
Graph database engines could be considered a re-emergence of the network database paradigm, and Azure CosmosDb has Azure CosmosDb for Gremlin.
When you want to build social media applications
5. Azure Cosmos Database vs SQL Server
|
Azure Cosmos Database |
SQL Server |
Type |
NoSQL database |
Relational database |
Cloud-based |
Yes |
No |
Server Operating Systems |
Hosted |
Linux Windows |
Data Scheme |
Schema-free |
yes |
Query Language |
SQL-like |
SQL |
APIs |
DocumentDB API Graph API (Gremlin) MongoDB API RESTful HTTP API Table API |
ADO.NET JDBC ODBC OLE DB Tabular Data Stream (TDS) |
Supported Programming Languages |
.Net C# Java JavaScript JavaScript (Node.js) MongoDB Python |
C# C++ Delphi Go Java JavaScript (Node.js) PHP Python R Ruby Visual Basic |
Scalability Methods |
Scale-out: add more components in parallel to improve performance |
Scale-up: update component to bigger, faster to improve performance |
Database sharding |
Automatically |
Manually |
Hierarchical data(1) |
Document-oriented |
Object-oriented |
(1):
Hierarchical Data- Relation and CosmosDb
Price
Price-Cosmos
Azure CosmosDb Price with Region = East US and currency = USD
Price-SQL