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?
- Retrieve the session token from the API service's write response and pass it to the background worker's read request.Answer
- BEnsure both the API service and the background worker execute operations using the exact same partition key.
- CRely on the default Session consistency behavior, as it automatically guarantees read-your-writes across all independent clients globally.
- DInitialize 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
Key Concept
Session consistency scope and session token passing in Azure Cosmos DB