Menu Close

Introduction to Azure Cosmos DB

In this article, we discussed the Introduction to Azure Cosmos DB why it is used, and what benefits of Cosmos DB. Azure Cosmos DB is intended to overcome the difficulties associated with current application development. Traditional databases frequently fail to meet the requirements of today’s dynamic, dispersed, and globally networked applications. Please read my previous article on How to Build ASP.Net Core API using Azure Cosmos DB Local Emulator.

What is Azure Cosmos DB?

Cosmos Database (DB) is a globally distributed, low latency, multi-model database for managing data at large scales. It is a cloud-based NoSQL database offered as a PaaS (Platform as a Service) from Microsoft Azure. It is a highly available, high throughput, reliable database and is often called a serverless database. Cosmos database contains the Azure Document DB and is available everywhere.

azure-cosmos-db

To understand of Cosmos DB, we need to know what relational, NoSQL, distributed, and Multi-model databases

Relational Database

A relational database is a type of database that stores data that is connected to one another. Data in a relational model is stored as rows and columns in tables. The columns are used to hold specific types of information about several items, whereas the rows represent various aspects of one object. Primary keys can be used to uniquely identify rows, and foreign keys can be used to connect distinct tables.

NoSQL Database

NoSQL databases are used for data that is not modeled in the same manner that relational databases are. NoSQL supports data structures such as key-value pairs, broad columns, graphs, and documents that are not found in relational databases. This makes them more adaptable and allows for speedier operations.

Differences between Relational and NoSQL Database

Relational DatabaseNoSQL Database
Data is stored in tablesData can be stored as documents, graphs, key-value pairs, etc.
Vertically scalableHorizontally scalable
Predefined schemaNo predefined schema, hence easier to update
Supports powerful query languageSupports simple query language
Can handle data in moderate volumesCan handle data in very high volumes
Has a centralised structureHas a decentralized structure
Data can be written from one or a few locationsData can be written from many locations

Benefits of Azure Cosmos DB

The key features of Cosmos DB are:

  • Globally Distributed: With Azure regions spread out globally, the data can be replicated globally.
  • Scalability: Cosmos DB is horizontally scalable to support hundreds of millions of reads and writes per second.
  • Schema-Agnostic Indexing: This enables the automatic indexing of data without schema and index management.
  • Multi-Model: It can store data in Key-value Pairs, Document-based, Graph-based, Column Family-based databases. Global distribution, horizontal partitioning, and automatic indexing capabilities are the same irrespective of the data model.
  • High Availability: It has 99.99 % availability for reads and writes for both multi-region and single-region Azure Cosmos DB accounts.
  • Low Latency: The global availability of Azure regions allows for the global distribution of data, which further makes it available nearest to the customers. This reduces the latency in retrieving data.

How does Cosmos DB Work?

Due to network latency concerns, persons near the location will be able to retrieve data faster than the rest of the globe if a website used by people all over the world publishes its data into a primary database in one location (non-multi-master mode).

However, Cosmos DB supports multi-master, allowing data to be written into many databases dispersed throughout the globe at the same time. The data is thereby copied onto the user’s nearby region, allowing for speedier access. However, there may be a millisecond discrepancy between the data being copied, which compromises the consistency.

Consistency determines whether or not the data are in sync and in the same condition at any given time. Cosmos DB provides several levels of consistency, each with varied performance and availability.

The following consistency levels are available:

  • Data is written on the primary node and eventually distributed to read-only secondary nodes. It may take some time for users to receive new info.
  • Clients can read data in the same order as it is written if the prefix is consistent.
  • Session: Users who have recently committed data will be able to see it, but it will take some time for others to see that data version.
  • Bounded Staleness: A staleness period can be specified here, after which data will not be replicated to secondary nodes.
  • Strong: This provides the most recent copy of data to all users but has a low performance.

Cosmos DB Containers

Cosmos DB on Azure Container is a schema-independent scalability unit. A container is partitioned horizontally and copied across many regions. Added objects in the container and provisioned throughput are automatically allocated over a series of logical partitions based on the partition key. Items in the container do not have to be similar (for example, Person, Vehicle, Business Entity, etc.) and can have arbitrary schemas. Collections in containers can be fixed or limitless. Because everything is stored in a single partition, fixed collections are limited to a single partition and do not require a partition key set. The number of partitions in a collection is not restricted in limitless.

Azure Cosmos DB Pricing

Please check the below link for Azure Cosmos DB pricing

Azure Cosmos DB Pricing- Microsoft Link

Conclusion

We have discussed here the Introduction to Azure Cosmos DB. In conclusion, Azure Cosmos DB is not just a database; it’s a comprehensive solution that redefines how organizations manage and interact with their data. Its global distribution, multi-model support, scalability, consistency models, automatic indexing, and security features make it a versatile and powerful platform for modern applications. As businesses continue to evolve in the digital landscape, Azure Cosmos DB stands as a beacon of innovation, empowering developers to build scalable and responsive applications that can meet the demands of today’s interconnected world.

Related Articles

SUPPORT ME

Buy Me A Coffee

Leave a Reply

Your email address will not be published. Required fields are marked *