Question

Difficulty: MediumSet Consistency Levels for Azure Cosmos DB

An organization is developing a stateless API service and a separate background processing worker, both interacting with an Azure Cosmos DB API for NoSQL account. The Cosmos DB account is configured with the default Session consistency and is replicated across East US (write region) and West US (read replica). The API service in East US updates a customer's order status document and receives a write confirmation. Immediately after, the background worker in West US needs to read the updated order document to process a notification. Which action must you perform to guarantee that the background worker reads the updated order status?

  1. Retrieve the session token from the API service's write response and pass it to the background worker's read request.Answer
  2. B
    Ensure both the API service and the background worker execute operations using the exact same partition key.
  3. C
    Rely on the default Session consistency behavior, as it automatically guarantees read-your-writes across all independent clients globally.
  4. D
    Initialize both the API service and the background worker to use the same Azure Cosmos DB SDK client instance without sharing any session tokens.

Answer

Retrieve the session token from the API service's write response and pass it to the background worker's read request.
The correct answer is to retrieve the session token from the API service's write response and pass it to the background worker's read request. Session consistency provides consistency guarantees for a single client session. Because the API service and the background worker are distinct client applications, the session token must be explicitly passed from the writer to the reader to guarantee that the reader sees the latest update.

Step-by-Step Solution

1
Analyze the consistency requirements and deployment topography.
The application runs across two regions (East US and West US) with Session consistency and requires a read-your-writes guarantee across two separate client instances (the API service and the background worker).
Understanding the limits of Session consistency is required, as it is only guaranteed out-of-the-box within a single client session.
2
Determine the mechanism to share session state between different clients.
Passing the session token from the write operation response to the read operation request allows the reader to catch up to the writer's state.
Cosmos DB allows passing session tokens explicitly to extend the Session consistency guarantee to external clients.

Key Concept

Session consistency scope and session token passing in Azure Cosmos DB
Rate this question