What is Azure Cosmos DB?

Learn when to use Cosmos DB and how it can help you build modern cloud-native applications.

Introduction to Azure Cosmos DB

Azure Cosmos DB is a scalable and reliable NoSQL database service built by Microsoft. It runs in the cloud and promises great response times anywhere in the world.

We can describe it as:

  • Globally distributed

  • Multi-model

  • Document-oriented

  • Database service

It’s a long description! So, let’s go into more detail from the bottom up.

Database service

It’s not possible to install Cosmos DB. It is a service provided exclusively on the Azure cloud platform. It might seem obvious, but this limits its usage in any scenario where the database must operate offline or adhere to specific restrictions.

Document-oriented

This is the first big difference with traditional relational database management systems (RDBMS)!

The database projects documents to independent JSONs, so we lose relationships between different entities. We lose strong-type columns, consistency, and cross-table queries, but we gain a flexible and easy-to-distribute data structure.

Let’s see the difference between RDBMS and Cosmos DB terminology:

RDBMS

Cosmos DB (NoSQL)

Server

Account

Database

Database

Table

Container

Row

Document

It’s not a perfect translation; there are significant differences between the two architectures, but at least it gives an idea of the hierarchy.

Multi-model

Unlike other databases, we can interact with Cosmos DB with multiple different APIs, such as:

  • NoSQL

  • MongoDB

  • Cassandra

  • PostgreSQL (using Citus)

  • Gremlin (graph)

  • Table (key-value)

In this course, we will use the native NoSQL API and later briefly present the Gremlin API.

The MongoDB and Cassandra APIs allow companies to migrate to Cosmos DB with minimal effort. It’s out of the scope of this course to explain other databases’ APIs and concepts.

Note: However, remember that all those APIs are just an interaction layer!

Everything is stored as documents and follows the Cosmos DB architecture, so everything we learn during this course still applies to the other APIs.

Remember: Working with Cosmos DB’s MongoDB API is not the same as working with a MongoDB service.

Globally distributed

Cosmos DB, true to its name, can globally distribute data effortlessly. Azure promises single-digit millisecond response times and 99.999% availability.

During this course, we’ll learn how the distributed nature of this database influences every other aspect, from data modeling to queries.

Prerequisites

Basic knowledge of databases and cloud computing is needed, but don’t worry too much, because we’ll start from the beginning. There will also be comparisons with traditional SQL databases since they are the most popular.

We’ll apply some of the presented concepts during the course to a simple Asp.NET C# project. For this reason, a basic understanding of the language is needed.

Finally, an Azure account is required since Cosmos DB is a service (the free trial is more than enough).

What we’ll learn

We hope the introduction wasn’t too scary! If not, here is what we’ll be focusing on:

  • How to model data based on use cases

  • The NoSQL API

  • Use of the .NET SDK

  • Performance and cost optimization

  • Security

  • Leveraging the power of Cosmos DB while learning its limitations

  • Using it in a serverless architecture

  • The Graph API