Consistency Levels: Five Choices, Real Trade-Offs
Master all five Cosmos DB consistency levels β strong, bounded staleness, session, consistent prefix, and eventual β with analogies, technical detail, and the trade-offs the exam loves to test.
The consistency spectrum
Think of a news broadcast. Strong consistency is a live broadcast β everyone sees the same thing at the same time, but thereβs a slight delay. Eventual consistency is a newspaper β fast to print, but different readers might get different editions for a while.
Cosmos DB gives you five points on this spectrum. More consistency = higher latency and cost. Less consistency = faster and cheaper, but readers might see stale data temporarily.
Jakeβs consistency dilemma
π Jake at GlobeCart has replicated his product catalogue to three regions. But now he faces questions:
- When a seller updates a price in East US, how quickly must customers in Europe see it?
- When a customer adds an item to their cart, must the next read reflect it immediately?
- Is it OK if product reviews appear slightly delayed across regions?
Each answer points to a different consistency level. Letβs explore all five.
The five levels
1. Strong consistency
Guarantee: Every read returns the most recent committed write. Linearizable β as if thereβs a single copy of the data.
Analogy: A live video call β everyone sees the same thing at the same millisecond.
- Latency: Reads use a local replica quorum; synchronous cross-region writes add latency
- RU cost: 2Γ the RU cost of a standard read
- Restriction: Strong is not available with multi-region writes
- Use case: Financial transactions, inventory counts where stale reads cause real-world harm
2. Bounded staleness
Guarantee: Reads may lag behind writes by at most K operations or T seconds, whichever is reached first.
Analogy: A sports ticker with a guaranteed maximum delay β you might be 5 seconds behind live, but never more.
- Configuration: You set K (version count) and T (time interval)
- Multi-region minimum: K β₯ 100,000 operations AND T β₯ 300 seconds
- Single-region minimum: K β₯ 10 operations AND T β₯ 5 seconds
- RU cost: 2Γ the RU cost for reads (same as strong)
- Restriction: Bounded Staleness with multi-region writes is a documented anti-pattern, not a blanket unsupported combination. PPAF currently excludes this level.
- Use case: Leaderboards, analytics dashboards where βnear-real-timeβ is acceptable
3. Session consistency (DEFAULT)
Guarantee: Within a single client session, reads always reflect that sessionβs own writes (read-your-own-writes). Other sessions may see older data.
Analogy: Your own notepad β you always see what you just wrote, but your colleagueβs notepad might not be updated yet.
- Latency: Low β no cross-region coordination for your own session
- RU cost: Standard (1Γ)
- Why itβs the default: Most applications need βI see what I just wroteβ without caring about other usersβ sessions
- Use case: Shopping carts, user profiles, most CRUD applications
4. Consistent prefix
Guarantee: Respect the documented transaction scope: changes within a multi-item transactional batch are observed together. Current documentation describes independent single-document writes as eventually consistent; do not infer a total application-wide event order from this setting.
Analogy: A sealed packet arrives together, even if a remote reader receives the packet later. It does not sequence every independently mailed packet for the application.
- Latency: Low
- RU cost: Standard (1Γ)
- Use case: Social media feeds, event logs, chat message history
5. Eventual consistency
Guarantee: Reads will eventually return the most recent write, but thereβs no bound on when. Reads may be out of order.
Analogy: A newspaper β eventually everyone gets the news, but different readers see different editions at different times.
- Latency: Lowest
- RU cost: Standard (1Γ), the same read-quorum cost group as Session and Consistent Prefix
- Use case: Like counts, view counters, telemetry, non-critical metrics
Comparison at a glance
| Level | Guarantee | Read RU Cost | Latency | Multi-Region Writes? |
|---|---|---|---|---|
| Strong | Linearizable β latest write always | 2Γ | Highest | β No |
| Bounded Staleness | Within K versions or T seconds | 2Γ | Workload-dependent | Documented anti-pattern; not supported by PPAF |
| Session (DEFAULT) | Read-your-own-writes per session | 1Γ | Low | β Yes |
| Consistent Prefix | Transaction-scoped consistency; no global event-order guarantee | 1Γ | Low | β Yes |
| Eventual | No guarantees on freshness/order | 1Γ | Lowest | β Yes |
Exam tip: consistency per-request relaxation
The account-level default consistency can be relaxed (weakened) on a per-request basis using SDK headers. You can go from Strong β Bounded Staleness β Session β Consistent Prefix β Eventual.
You cannot strengthen consistency per-request. If the account is set to Session, you cannot request Strong on individual reads. This is a favourite exam question β know the direction of relaxation.
Bounded staleness deep dive
Multi-region bounded staleness minimums:
K β₯ 100,000 operations
T β₯ 300 seconds (5 minutes)
Single-region bounded staleness minimums:
K β₯ 10 operations
T β₯ 5 seconds
Why the multi-region minimum is high: Cross-region replication has inherent latency. Setting K=10 across continents would cause constant consistency violations. The minimums ensure the staleness window is realistic.
// Bounded staleness is configured at the account level:
// az cosmosdb update --name globecart-cosmos \
// --default-consistency-level BoundedStaleness \
// --max-staleness-prefix 100000 \
// --max-interval 300
Exam tip: the 2Γ read cost trap
Both Strong and Bounded Staleness cost 2Γ RU for reads because they require quorum confirmation from multiple replicas. Session, Consistent Prefix, and Eventual all cost 1Γ because reads go to a single replica.
Compare the required guarantees with these cost groups. A Session-to-Eventual change alone does not establish a lower read RU charge.
Per-request consistency in code
// Account default: Session
// Relax to Eventual for a non-critical read
ItemRequestOptions options = new ItemRequestOptions
{
ConsistencyLevel = ConsistencyLevel.Eventual
};
ItemResponse<Product> response = await container.ReadItemAsync<Product>(
id: "product-123",
partitionKey: new PartitionKey("electronics"),
requestOptions: options
);
Sophieβs pro tip: Sophie uses Session for cart reads that must reflect the current sessionβs writes. A non-critical counter may tolerate Eventual, but Session and Eventual share the same standard read RU cost group; measure the request rather than promising savings from that override.
π¬ Video walkthrough
Flashcards
Knowledge Check
Jake uses multi-region writes and needs read-your-writes for the current client session without quorum-read cost. Which consistency level fits?
A Cosmos DB account is set to Strong consistency. A developer wants to read product reviews with Eventual consistency to save RU cost. How can they achieve this?
Sophie configures bounded staleness with K=50 operations and T=120 seconds on a multi-region Cosmos DB account. What happens?
GlobeCart needs to display a customer's shopping cart immediately after they add an item. Which consistency level is the most cost-effective choice?
Next up: Change Feed Processing β consume source changes and track processor progress.