Domain 2 β€” Module 2 of 3 67%
13 of 28 overall
Domain 2: Design and Implement Data Distribution 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: Highest read latency (waits for quorum across regions)
  • RU cost: 2Γ— the RU cost of a standard read
  • Restriction: ⚠️ 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: ⚠️ Not available with multi-region writes
  • 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: Reads never see out-of-order writes. If writes happen as A → B → C, reads see A, A→B, or A→B→C — never A→C skipping B.

Analogy: Watching a TV show β€” you might be behind, but episodes always play in order.

  • 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: Lowest (slightly less than session for reads)
  • 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 ops or T seconds2Γ—High❌ No
Session (DEFAULT)Read-your-own-writes per session1Γ—Lowβœ… Yes
Consistent PrefixNo out-of-order reads1Γ—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.

Exam questions often ask about β€œcost-effective” consistency β€” if the scenario doesn’t require strong guarantees, Session is almost always the right answer (and it’s the default).

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, Jake’s DBA, uses Session consistency for the shopping cart (customers must see their own changes) but relaxes to Eventual for product review counts (a few seconds of staleness is fine and saves RU cost).

🎬 Video walkthrough

Flashcards

Question

What is the DEFAULT consistency level in Cosmos DB?

Click or press Enter to reveal answer

Answer

Session consistency. It guarantees read-your-own-writes within a single client session. It's the most popular choice because it balances consistency with low latency and standard RU cost.

Click to flip back

Question

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

Click or press Enter to reveal answer

Answer

Strong and Bounded Staleness. Both require quorum reads from multiple replicas, doubling the read cost. Session, Consistent Prefix, and Eventual all cost 1Γ— (standard).

Click to flip back

Question

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

Click or press Enter to reveal answer

Answer

K β‰₯ 100,000 operations AND T β‰₯ 300 seconds (5 minutes). For single-region: K β‰₯ 10 operations and T β‰₯ 5 seconds. The multi-region minimums are high because cross-region replication has inherent latency.

Click to flip back

Question

Can you strengthen consistency on a per-request basis?

Click or press Enter to reveal answer

Answer

No β€” you can only WEAKEN (relax) consistency per-request. If the account default is Session, you can relax to Consistent Prefix or Eventual, but you cannot request Strong or Bounded Staleness. Direction: Strong β†’ Bounded β†’ Session β†’ Prefix β†’ Eventual.

Click to flip back

Question

Which consistency levels are NOT available with multi-region writes?

Click or press Enter to reveal answer

Answer

Strong and Bounded Staleness. Both require a single authoritative write region to enforce their ordering guarantees. Multi-region writes support Session, Consistent Prefix, and Eventual.

Click to flip back

Knowledge Check

Knowledge Check

Jake's GlobeCart has multi-region writes enabled across three regions. He wants the strongest possible consistency. Which level should he choose?

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: Multi-Region Writes and Conflict Resolution β€” what happens when two regions write to the same document at the same time, and how Cosmos DB resolves the conflict.