# Azure Cosmos DB

> Chapter 25 of the Courseiva AZ-900 curriculum — https://courseiva.com/learn/az-900/azure-cosmos-db

**Official objective:** 2.4 — Azure Architecture Services

## Introduction

This chapter covers Azure Cosmos DB, Azure's globally distributed database service. AZ-900 tests this under objective 2.4, typically contrasted with the more traditional, single-region-focused Azure SQL Database.

## A Global Chain That Feels Local Everywhere

Imagine a retail chain designed from the ground up to operate consistently across many countries, with each local store able to serve customers quickly without waiting on instructions from a distant headquarters, while still staying in sync with the rest of the chain. Azure Cosmos DB is built with a similar philosophy for data: it's designed to distribute data across multiple regions globally, so applications can read and write data with low latency wherever their users are, while the underlying service keeps everything synchronized according to configurable consistency rules.

## Core explanation

### What Azure Cosmos DB is
Azure Cosmos DB is a fully managed, globally distributed database service designed for applications that need low-latency access to data from multiple geographic locations, and that need to handle a variety of data structures beyond strictly relational tables.

### Multi-model support
Unlike Azure SQL Database, which is specifically relational, Cosmos DB supports multiple data models (sometimes called NoSQL models) — including document, key-value, graph, and column-family structures — making it flexible for different kinds of applications, not just traditionally structured relational data.

### Global distribution
Cosmos DB can replicate data across multiple Azure regions, letting applications read and write data from whichever region is closest to a given user, reducing latency for globally distributed applications, while the service manages keeping data consistent across those regions according to configurable settings.

### When Cosmos DB is a good fit
Cosmos DB suits applications that need fast performance for users spread across the globe, need to handle large volumes of rapidly changing data, or work with data that doesn't fit neatly into a traditional relational structure. A single-region application with straightforward relational data needs might be equally or better served by Azure SQL Database instead.

### How it compares to Azure SQL Database
Azure SQL Database is specifically relational and typically operates from a primary region (with options for broader resilience). Cosmos DB supports multiple data models and is built from the ground up for global distribution — the right choice depends on the specific data structure and geographic distribution needs of the application.

## Real-world context

A global gaming company uses Azure Cosmos DB to store player data, since players connect from many different countries and need consistently fast access to their data regardless of location — something Cosmos DB's global distribution is specifically designed to support.

A separate company running a regional accounting application with straightforward relational data and users in a single country uses Azure SQL Database instead, since global distribution isn't a requirement and the relational structure of SQL Database fits their data well without needing Cosmos DB's additional flexibility.

## Exam focus

Objective 2.4 expects candidates to recognize Azure Cosmos DB as Azure's globally distributed, multi-model database service, and to distinguish it from the specifically relational Azure SQL Database.

A common wrong answer is assuming Cosmos DB is simply "a faster version of SQL Database" — they serve different purposes; Cosmos DB's key differentiators are global distribution and support for multiple data models beyond relational. Another common trap is assuming every application needs Cosmos DB's global distribution — many applications are well served by a simpler, single-region relational database instead.

Stable terms: **Azure Cosmos DB**, **globally distributed**, **multi-model**. Recognizing Cosmos DB as suited to globally distributed, non-relational, or rapidly changing data is the core exam-relevant distinction from SQL Database.

Memory trick: Azure SQL Database = structured, relational, typically single-region-focused. Azure Cosmos DB = flexible data models, built for global distribution and low latency worldwide.

## Step by step

1. **Determine if global distribution is needed** — If an application serves users across multiple geographic regions and needs low-latency access everywhere, Cosmos DB's global distribution capabilities become relevant.
2. **Choose an appropriate data model** — Cosmos DB supports multiple models (document, key-value, graph, column-family) — the right one depends on how the application's data is structured and accessed.
3. **Configure regions for replication** — Data can be replicated across multiple Azure regions, letting the application read and write closer to wherever its users are located.
4. **Compare against Azure SQL Database for the specific need** — If the data is strictly relational and the application doesn't need global distribution, Azure SQL Database may be a simpler, equally appropriate fit instead.

## Comparisons

### Azure SQL Database vs Azure Cosmos DB

**Azure SQL Database:**
- Strictly relational data model
- Typically operates from a primary region
- Well suited to traditional structured applications

**Azure Cosmos DB:**
- Supports multiple data models (document, key-value, graph, column-family)
- Built for global distribution across multiple regions
- Well suited to globally distributed or rapidly changing data

## Common misconceptions

- **Misconception:** Azure Cosmos DB is just a faster version of Azure SQL Database. **Reality:** They serve different purposes — Cosmos DB's key strengths are global distribution and support for multiple data models beyond relational, not simply raw speed for the same kind of workload.
- **Misconception:** Every application needs Cosmos DB's global distribution capabilities. **Reality:** Many applications, especially single-region ones with straightforward relational data, are well served by Azure SQL Database instead — Cosmos DB fits a more specific set of needs.
- **Misconception:** Cosmos DB only supports one type of data model. **Reality:** Cosmos DB supports multiple data models — including document, key-value, graph, and column-family — making it more flexible than a strictly relational database for certain kinds of applications.

## Key takeaways

- Azure Cosmos DB is a fully managed, globally distributed database service supporting multiple data models.
- Unlike Azure SQL Database's strictly relational model, Cosmos DB supports document, key-value, graph, and column-family structures.
- Cosmos DB is well suited to applications needing low-latency access across multiple geographic regions.
- Not every application needs Cosmos DB's capabilities — simpler, single-region relational needs are often well served by Azure SQL Database.

## FAQ

**What is Azure Cosmos DB?**

It's a fully managed, globally distributed database service that supports multiple data models (document, key-value, graph, and column-family), designed for applications that need low-latency access to data from users spread across the globe.

**What's the difference between Azure Cosmos DB and Azure SQL Database?**

Azure SQL Database is specifically relational and typically single-region-focused. Azure Cosmos DB supports multiple data models beyond relational and is built from the ground up for global distribution across multiple regions, suiting a different set of application needs.

**When should I use Cosmos DB instead of a relational database?**

Cosmos DB fits well when an application needs global distribution with low latency worldwide, needs to handle large volumes of rapidly changing data, or works with data that doesn't fit a traditional relational structure. For straightforward, single-region relational data, Azure SQL Database may be a simpler fit.

---

Interactive version with quiz and diagrams: https://courseiva.com/learn/az-900/azure-cosmos-db
