Azure Cosmos DB: The Global Database
Azure Cosmos DB is Microsoft's globally distributed, multi-model NoSQL database. It's designed for apps that need single-digit millisecond latency at any scale, anywhere in the world.
What is Azure Cosmos DB?
Cosmos DB is a super-fast, world-wide database that handles any shape of data.
Imagine a pizza chain with shops in Auckland, London, and New York. Each shop needs to check inventory and take orders instantly. With a normal database in one location, shops far away get slow responses. Cosmos DB puts copies of the data in every region — so every shop gets fast responses, no matter where they are.
Plus, Cosmos DB doesn’t force you into one data model. It can store JSON documents, key-value pairs, graphs, or even table-like data.
When to use Cosmos DB
Cosmos DB shines when your application needs:
| Need | Why Cosmos DB |
|---|---|
| Global distribution | Replicate data to any Azure region for low-latency reads worldwide |
| Guaranteed speed | Single-digit millisecond response times, SLA-backed |
| Massive scale | Handle millions of requests per second across regions |
| Flexible schema | Store JSON documents with varying structures |
| Multi-model | Choose the right API for your data: document, key-value, graph, or table |
| Always available | 99.999% availability with multi-region writes |
Common use cases
Jake’s CloudPulse example: The SaaS app serves customers globally. Session state and real-time user activity data go into Cosmos DB:
- Users in Auckland, Singapore, and London all get sub-10ms reads
- Each user’s session data is a JSON document with flexible fields
- The app auto-scales during peak hours without manual intervention
Other common use cases:
- E-commerce: Product catalogues with varying attributes per category
- IoT: Ingesting millions of sensor readings per second
- Gaming: Leaderboards, player profiles, real-time game state
- Social media: User feeds, activity streams, content graphs
- Personalisation: Recommendation engines, user preferences
Consistency levels
Cosmos DB offers five consistency levels — a spectrum between strong consistency (always the latest data, slower) and eventual consistency (might be slightly stale, faster):
- Strong — every read returns the most recent write (like a relational database)
- Bounded staleness — reads may lag behind writes by a defined time/operations window
- Session — reads within a session are consistent (default and most popular)
- Consistent prefix — reads never see out-of-order writes
- Eventual — no ordering guarantee, but fastest and cheapest
Session consistency (the default) is what most apps need — your own writes are immediately visible to you, while other regions catch up in the background.
Exam tip: Cosmos DB vs relational databases
The exam tests your ability to choose between Cosmos DB and relational databases:
- “Global distribution needed” → Cosmos DB
- “Flexible schema, varying document structures” → Cosmos DB
- “Millions of operations per second” → Cosmos DB
- “Need SQL joins across tables” → Relational database (NOT Cosmos DB)
- “Need ACID transactions across multiple tables” → Relational database
- “Fixed schema, strong referential integrity” → Relational database
Request Units (RU/s) — how you pay
Cosmos DB measures throughput in Request Units per second (RU/s). One RU is the cost of reading a single 1KB document by its ID.
- More complex queries cost more RUs
- You provision a target RU/s capacity (or use serverless for variable workloads)
- Throughput can be provisioned per database or per container
This is fundamentally different from relational databases where you provision CPU and memory.
Flashcards
Knowledge check
Jake's SaaS application needs to serve users in Auckland, London, and New York with sub-10ms response times. User profiles are JSON documents with flexible schemas. Which Azure database should he use?
A gaming company needs to store player leaderboards that handle 500,000 writes per second during tournaments, with players connecting from 30 countries. Which service fits BEST?
🎬 Video coming soon
Next up: Cosmos DB APIs: SQL, MongoDB & More — Cosmos DB supports multiple data models through its API layer.