A web application uses Azure Cosmos DB for its product catalog. The application frequently performs point reads (retrieving a single item by its ID) and range queries (retrieving items within a category). To minimize latency and ensure high availability, the Cosmos DB account is configured for multi-region writes. The product catalog data is updated infrequently but read very often. Which consistency level should be configured for the Cosmos DB account to balance strong consistency for writes with low-latency reads, while still allowing for some eventual consistency during failovers?
- ABounded Staleness
- BEventual
- CSession
- DStrong
Show answer & explanationAnswer & explanation
Correct answer: A. Bounded Staleness
Bounded Staleness offers a good balance. It guarantees that reads will not lag behind writes by more than 'K' versions or 'T' time interval. This provides stronger consistency than Session or Eventual, ensuring data isn't too stale, while still allowing for lower latency and higher throughput than Strong consistency, especially in a multi-region write environment where some eventual consistency is acceptable during propagation. Strong consistency would incur higher latency for reads in multi-region setups, and Session/Eventual might be too lax for 'infrequently updated but read very often' data where staleness needs to be bounded.
Why the other options are wrong
- B. Eventual consistency offers the lowest latency but the least consistency guarantee, which might be too weak for 'infrequently updated but read very often' data where some level of staleness bound is desired.
- C. Session consistency is good for user sessions but doesn't provide a global guarantee across different client connections or for general application reads when data staleness needs to be bounded globally.
- D. Strong consistency means all reads see the latest committed write globally, which is too restrictive for low-latency reads in a multi-region write scenario and would incur high latency.
Cosmos DB Bounded Staleness
Bounded Staleness is an Azure Cosmos DB consistency level that guarantees that reads are always within a specified number of versions or a specified time interval of the latest writes. It provides a balance between strong consistency and eventual consistency, allowing for higher throughput and lower latency than Strong consistency.
- Reads lag behind writes by at most 'K' versions or 'T' time interval.
- Offers a balance between strong and eventual consistency.
- Suitable for globally distributed applications.
- Higher throughput and lower latency than Strong consistency.
Memory trick: Consistency Choices: Strong, Bounded, Session, Consistent, Eventual.