Last updated: May 2026
Azure DatabasesIntermediateAZ-104⏱ 14 min read

Azure Cosmos DB

Azure Cosmos DB is Microsoft's globally distributed, multi-model NoSQL database service. It's designed for applications that need guaranteed low latency (single-digit milliseconds at the 99th percentile), elastic scalability, and the ability to serve users from anywhere in the world. Cosmos DB is unique in offering five consistency models and support for multiple database APIs — all in one service.

What you'll learn Global distribution and multi-region writes · Five consistency levels · Multiple database APIs (SQL, MongoDB, Cassandra, Gremlin, Table) · Partitioning strategy · Request Units (RU/s) — how billing works · Serverless vs provisioned throughput · Change feed · SLA guarantees

Global Distribution

Cosmos DB can replicate your data to any Azure region with a single click — or configure it programmatically. Key capabilities:

  • Multi-region reads — Users automatically routed to nearest region
  • Multi-region writes — Write to any region; conflicts resolved automatically
  • Automatic failover — If a region fails, traffic moves to next available region
  • Manual failover — For testing DR procedures
ℹ️
Guaranteed Latency Cosmos DB guarantees <10ms reads and <15ms writes at the 99th percentile — regardless of which region you're in or how much data you store. This SLA is backed by Microsoft.

Five Consistency Levels

Cosmos DB offers five consistency models — from strongest (more consistent, more latency) to weakest (less consistent, less latency/cost). This is unique in the industry and a key exam topic.

LevelGuaranteesLatencyUse When
StrongAlways reads latest write — linearisableHighestFinancial transactions, inventory
Bounded StalenessReads lag behind writes by configurable time or operationsHighApps tolerating slight lag but needing order guarantees
Session (default)Consistent reads/writes within a session — monotonicMediumMost apps — social profiles, shopping carts
Consistent PrefixReads never see out-of-order writesLowSocial media feeds, logs
EventualNo ordering guarantee — replicas eventually convergeLowestLikes/views counts, non-critical data
💡
Session is the Sweet Spot Session consistency (the default) provides strong consistency for a single user's session — reads always reflect your own writes. For 90% of applications, this is the right balance of consistency and performance.

Database APIs

Cosmos DB supports multiple APIs — you can use your existing skills and client libraries:

APIUse WhenWire Protocol
NoSQL (SQL)Native Cosmos DB — JSON documents, SQL-like queriesCosmos REST API
MongoDBMigrating from MongoDB, existing MongoDB codeMongoDB wire protocol
CassandraWide-column data, existing Cassandra appsCassandra wire protocol (CQL)
GremlinGraph data — social networks, recommendation enginesGremlin (Apache TinkerPop)
TableMigrating from Azure Table Storage, need global distributionOData (Table Storage compatible)
⚠️
Choose API at Creation Time You select the API when creating a Cosmos DB account — you cannot change it afterwards. Choose carefully based on your data model and compatibility requirements.

Partitioning

Cosmos DB distributes data across partitions for scale. You must choose a partition key when creating a container. Good partition key design is critical:

  • High cardinality — Many unique values (userId, orderId) — not gender or country
  • Evenly distributed reads/writes — Avoid hot partitions where one key gets all traffic
  • Used in most queries — Include partition key in queries for efficiency
💡
Good Partition Keys userId, productId, deviceId, tenantId — high cardinality, evenly distributed.
Bad Partition Keys status (only a few values), createdDate (hot partition for today's date), country (uneven distribution).

Request Units (RU/s)

Cosmos DB billing is based on Request Units per second (RU/s) — not raw CPU/memory. One RU represents the resources needed to read a 1 KB document. Other operations cost more:

  • 1 KB point read: ~1 RU
  • 1 KB write: ~5 RUs
  • Complex query: 10–100+ RUs

You provision RU/s at the container or database level. If your app exceeds the provisioned RU/s, requests are rate-limited (429 errors) — you need to provision more RU/s or use autoscale.

Throughput Modes

ModeDescriptionBest For
Provisioned (Manual)Set fixed RU/s — guaranteed throughputPredictable, sustained workloads
AutoscaleSet max RU/s — scales 10% of max to max automaticallyVariable workloads with peak hours
ServerlessPay per RU consumed — no minimumDev/test, sporadic workloads

Change Feed

Cosmos DB's change feed is a persistent log of all changes (inserts, updates) to a container in order. Applications can read this feed to:

  • Trigger event-driven processing (Azure Functions)
  • Build real-time dashboards
  • Replicate data to other systems
  • Implement event sourcing patterns

SLA Guarantees

SLAGuarantee
Availability99.999% (5 nines) with multi-region writes
Read latency<10ms at 99th percentile
Write latency<15ms at 99th percentile
ThroughputProvisioned RU/s guaranteed
💡
AZ-104 Exam Tip Know the five consistency levels — especially Session (default), Strong, and Eventual. Know the five APIs and when to use each. Know partition key design principles. Know that RU/s is the billing unit and provisioned RU/s sets throughput limits.
📝 Practice Questions
Click an option to check your answer.
Q1. Which Cosmos DB consistency level guarantees that reads always reflect the latest writes?
A — Strong
B — Session
C — Eventual
D — Consistent Prefix
Q2. A team is migrating an existing MongoDB application to Azure. Which Cosmos DB API should they use?
A — NoSQL (SQL) API
B — MongoDB API
C — Cassandra API
D — Table API
Q3. What happens when an application exceeds the provisioned RU/s in Cosmos DB?
A — Cosmos DB automatically increases the provisioned RU/s
B — Requests are rate-limited and return HTTP 429 errors
C — Data is dropped to maintain performance
D — Requests are queued until RU/s capacity is available
Q4. Which Cosmos DB consistency level is the default?
A — Strong
B — Session
C — Eventual
D — Bounded Staleness
Q5. What is a good partition key for a Cosmos DB container storing user orders?
A — orderStatus (pending, shipped, delivered)
B — customerId
C — orderDate
D — country
Comments
Disclaimer: RedKite Cloud is an independent educational resource and is not affiliated with Microsoft Corporation.