Cosmos DB β The Big Picture
Understand the Azure Cosmos DB resource hierarchy, NoSQL API, throughput models, global distribution, SLAs, the emulator, and when to choose free tier vs serverless vs provisioned.
What is Azure Cosmos DB?
Think of Cosmos DB as a planet-scale filing cabinet. You have one account (the office), which holds databases (rooms), which hold containers (filing drawers), which hold items (individual documents). The magic? You can replicate your filing cabinet to offices around the world, and anyone reads from the nearest copy β in single-digit milliseconds.
You pay for how fast the drawers open (throughput in RU/s) and how much paper you store (GB). Thatβs really it.
Priyaβs scenario: choosing Cosmos DB for NovaSaaS
π Priya at NovaSaaS is architecting a multi-tenant SaaS platform serving 200K users across 12 countries. Her requirements:
- Low latency globally β users in Sydney, London, and SΓ£o Paulo all expect sub-10ms reads
- Elastic scale β Black Friday traffic is 5Γ normal; she canβt over-provision year-round
- Multi-tenant isolation β each tenantβs data stays logically separated
- 99.99%+ availability β SaaS customers expect always-on
Cosmos DB checks every box. Letβs see how itβs structured.
Resource hierarchy
Every Cosmos DB deployment follows this hierarchy:
Azure Subscription
βββ Cosmos DB Account β endpoint + keys, billing root
βββ Database β logical namespace, optional shared throughput
βββ Container β the "table" β partitioned, indexed, queried
βββ Item β a JSON document (max 2 MB)
| Level | What it does | Key facts |
|---|---|---|
| Account | Top-level resource. Holds the endpoint URI and keys. | Choose an API when creating the account; do not assume one account exposes every API. |
| Database | Logical grouping of containers. | Optional: you can provision shared throughput at this level. |
| Container | Where data lives. Think of it as a table or collection. | Has a partition key, indexing policy, TTL, unique keys, throughput. |
| Item | A single JSON document. | Max 2 MB per item. Identified by id + partition key value. |
Priya creates one account, one database novasaas, and separate containers per domain β users, projects, billing.
Throughput: database vs container
| Aspect | Database throughput (shared) | Container throughput (dedicated) |
|---|---|---|
| RU/s pool | Shared across all containers in the database | Dedicated to a single container |
| Minimum | 400 RU/s (or 1000 with autoscale) | 400 RU/s (or 1000 with autoscale) |
| Best for | Many containers with variable, low traffic | High-traffic containers that need guaranteed capacity |
| Override | Individual containers can opt out with dedicated throughput | N/A β each container has its own RU/s |
| Cost efficiency | Great when most containers are idle | Better when one container dominates traffic |
Priya uses shared throughput at the database level for dev/test environments (saves cost), and dedicated container throughput in production for her projects container that handles 80% of traffic.
Exam tip: RU/s minimum with shared throughput
The base shared-throughput minimum is 400 RU/s (manual) or 1,000 RU/s (autoscale max); storage, container count and throughput history can raise it. Containers share the pool without a guaranteed per-container allocation. Ten containers sharing 1,000 RU/s do not each receive a reserved 100 RU/s.
You can also mix: have some containers on the shared pool and others on dedicated throughput within the same database.
Global distribution and SLAs
Cosmos DB was built for global distribution from day one:
The applicable SLA depends on the configured regions, write model, service tier and qualifying features. Multi-region multi-write is a documented path to 99.999% availability. Eligible single-write accounts using per-partition automatic failover (PPAF) can also have five-nines write availability; multi-write is not a universal prerequisite.
Do not treat an availability percentage as a promised outage duration or the client-observed latency of every operation. Network distance, consistency, item size and workload affect application behavior. Check the current Cosmos DB availability guidance and the PPAF requirements.
Priya enables multi-region reads across Australia East, UK South, and Brazil South, with writes pinned to Australia East for now. Sheβll enable multi-write when her team is ready to handle conflict resolution.
Free tier vs serverless vs provisioned
| Feature | Free tier | Serverless | Provisioned |
|---|---|---|---|
| Throughput | First 1,000 RU/s free (then standard pricing) | Auto-scales per request, billed per RU consumed | You set RU/s (manual or autoscale) |
| Storage | First 25 GB free | Charged by stored data; resource limits apply | Charged by stored data; resource limits apply |
| Best for | Dev/test, learning, small apps | Bursty, unpredictable workloads | Production, predictable traffic |
| Global distribution | β Supported | β Single-region only | β Supported |
| Subscription allowance | One free-tier account | Account and service quotas apply | Account and service quotas apply |
| Idle cost | Eligible usage within allowance | No reserved RU/s floor; stored data still costs money | Minimum RU/s cost plus storage |
Raviβs mistake: Ravi leaves provisioned throughput running after a weekend prototype. It continues to incur a throughput charge while idle. Compare an eligible free-tier account, serverless request consumption and storage against the current Microsoft pricing rather than guessing a bill.
Exam tip: serverless limitations
Serverless is great for dev/test but has real limitations: single-region only (no global distribution), no dedicated throughput guarantees, and each physical partition supports at most 5,000 RU/s. The exam loves testing whether serverless supports multi-region β it doesnβt. Note: you can now convert a serverless account to provisioned throughput in-place (NoSQL API).
The Cosmos DB emulator
The emulator runs locally on Windows, macOS (Docker), or Linux (Docker). It provides a local endpoint that behaves like the real service:
Endpoint: https://localhost:8081
Key: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
This is the emulatorβs documented default development key, not a cloud-account secret. Supported emulator configurations can override it. The emulator does not reproduce every cloud feature or performance characteristic.
π¬ Video walkthrough
Flashcards
Knowledge check
Priya needs to choose a throughput model for NovaSaaS production. Her 'projects' container handles 80% of traffic. Which approach is best?
Ravi sets up a Cosmos DB account for a weekend prototype. He expects very light, unpredictable traffic, doesn't need multi-region, and hasn't used a free tier account in this subscription. Which model is cheapest?
Which of these is true about the Cosmos DB emulator?
Next up: Design Data Model β learn how to think access-pattern-first and design containers that match your queries, not your entity-relationship diagrams.