Domain 1 β€” Module 11 of 15 73%
11 of 31 overall
Domain 1: Design and develop database solutions Free ⏱ ~18 min read

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

Simple explanation

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

LevelGuaranteeRead RU CostLatencyMulti-Region Writes?
StrongLinearizable β€” latest write always2Γ—Highest❌ No
Bounded StalenessWithin K versions or T seconds2Γ—Workload-dependentDocumented anti-pattern; not supported by PPAF
Session (DEFAULT)Read-your-own-writes per session1Γ—Lowβœ… Yes
Consistent PrefixTransaction-scoped consistency; no global event-order guarantee1Γ—Lowβœ… Yes
EventualNo guarantees on freshness/order1Γ—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

Question

What is the DEFAULT consistency level in Cosmos DB?

Click or press Enter to reveal answer

Question

Which two consistency levels cost 2Γ— RU for reads?

Click or press Enter to reveal answer

Question

What are the minimum bounded staleness values for a multi-region Cosmos DB account?

Click or press Enter to reveal answer

Question

Can you strengthen consistency on a per-request basis?

Click or press Enter to reveal answer

Question

How do multi-write and PPAF consistency restrictions differ?

Click or press Enter to reveal answer

Knowledge Check

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?

Knowledge Check

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?

Knowledge Check

Sophie configures bounded staleness with K=50 operations and T=120 seconds on a multi-region Cosmos DB account. What happens?

Knowledge Check

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.