Question

Difficulty: MediumSet Consistency Levels for Azure Cosmos DB

A company is developing an Azure Cosmos DB API for NoSQL solution that replicates data across East US and West US. The Cosmos DB account is configured with Session consistency as the default. You deploy two distinct instances of a web client, AppClient1 and AppClient2. AppClient1 writes a document update to the database. AppClient2 must immediately read the updated document, but it does not have access to AppClient1's session token. Which of the following describes the consistency behavior AppClient2 will experience when reading the updated document?

  1. A
    AppClient2 is guaranteed to read the updated data immediately because Session consistency scope automatically covers all client sessions targeting the same database container.
  2. B
    AppClient2 is guaranteed to read the updated data immediately if the developer configures the container to use a single partition key value for all documents to force them into the same physical partition.
  3. AppClient2 is not guaranteed to read the updated data immediately because Session consistency only guarantees read-your-writes for reads that occur within the same client session, unless the session token is explicitly passed.Answer
  4. D
    AppClient2 will experience Eventual consistency with no ordering guarantees because Session consistency falls back to Eventual consistency for all reads that occur outside the writer's active session.

Answer

AppClient2 is not guaranteed to read the updated data immediately because Session consistency only guarantees read-your-writes for reads that occur within the same client session, unless the session token is explicitly passed.
The correct answer is that AppClient2 is not guaranteed to read the updated data immediately. In Azure Cosmos DB, Session consistency is the default and provides read-your-writes, monotonic reads, and monotonic writes guarantees inside a single client session. Because AppClient2 is a separate instance and does not receive the session token of AppClient1's write, it reads data under Consistent Prefix consistency, which means it may observe a delay in replication between East US and West US.

Step-by-Step Solution

1
Analyze the configured consistency level and client setup in the scenario.
The Cosmos DB account is configured with Session consistency, and there are two independent clients (AppClient1 and AppClient2) operating without shared session tokens.
Understanding the session boundary is necessary to evaluate the consistency guarantees between separate clients.
2
Determine the consistency guarantees within and outside a session.
Session consistency guarantees read-your-writes and monotonic reads only within the same session. Outside the session (where the session token is not shared), reads default to Consistent Prefix consistency.
Knowing that AppClient2 is in a different session helps identify that it is subject to Consistent Prefix rather than strong read-your-writes guarantees.
3
Evaluate the likelihood of AppClient2 reading the most recent write immediately.
Since AppClient2 is outside AppClient1's session and does not pass the session token, it may read stale data (though writes will be in order).
This matches the behavior described where AppClient2 is not guaranteed to immediately read the updated document.

Key Concept

Session consistency scope and token passing across separate clients in Azure Cosmos DB
Estimated Time:1m 30s
Rate this question