Database / Azure Cosmos DB interview questions
What are the five consistency levels in Azure Cosmos DB?
Consistency levels in Cosmos DB define the tradeoff between data freshness and system availability/latency when data is replicated across multiple regions or replicas. Azure Cosmos DB offers five levels, from strongest to weakest:
| Level | Guarantee | Latency Impact |
|---|---|---|
| Strong | Reads always return the most recent committed version. Linearizability guaranteed. | Highest — writes must be acknowledged by all replicas before returning |
| Bounded Staleness | Reads lag behind writes by at most K versions or T time interval (you configure both) | High — similar to Strong within a region; slower for cross-region reads |
| Session | Monotonic reads, monotonic writes, read-your-own-writes, and write-follows-reads — within a single client session | Low — the default and most practical level for most applications |
| Consistent Prefix | Reads never see out-of-order writes. If writes are A, B, C you will never read B without A. | Low — reads may be stale but always see a causally consistent prefix |
| Eventual | No ordering guarantees. Reads may return stale or out-of-order values temporarily. | Lowest — maximum throughput, minimum latency |
Session consistency is the default and the most widely used level. It gives strong consistency guarantees within a session token scope (a single user or client connection) while keeping cross-replica latency low. The session token is passed in request headers, and any replica that has caught up to that token can serve reads. This covers the most important correctness requirement for most apps: a user immediately sees their own writes.
Cosmos DB lets you relax consistency per request (weaken it, not strengthen it), so you can request eventual reads for a reporting query while keeping session consistency for writes.
More Related questions...