Microsoft Azure Data FundamentalsDescribe how to work with non-relational data on AzureHard

A large e-commerce platform uses Azure Cosmos DB to store its product catalog. The platform operates globally, with users accessing the catalog from various continents. To ensure the fastest possible response times for all users, the company wants to configure Cosmos DB so that data is written to the nearest regional replica and immediately available for reads from any replica, even if it means a slight chance of reading data that hasn't fully propagated globally. Which Azure Cosmos DB consistency level should the company choose?

  1. AStrong
  2. BEventual
  3. CSession
  4. DBounded Staleness
Show answer & explanation

Correct answer: C. Session

The Session consistency level guarantees monotonic reads, monotonic writes, read-your-own-writes, and write-follows-reads within a client session. This means a user will always read their own latest writes, and subsequent reads will be consistent with previous reads, which is crucial for a consistent user experience on an e-commerce platform. While not globally strong, it offers a good balance of consistency and performance for interactive applications.

Why the other options are wrong

  • A. Strong consistency guarantees global ordering and immediate visibility everywhere, but comes with higher latency due to synchronous replication across all regions, which is not ideal for 'fastest possible response times'.
  • B. Eventual consistency offers the lowest latency and highest throughput but provides no ordering guarantees, meaning users might read stale data, which is unacceptable for an e-commerce catalog where immediate visibility of updates (at least to the user who made them) is important.
  • D. Bounded Staleness provides an upper bound on staleness, but 'immediately available for reads from any replica' implies a stronger guarantee than just a bound, and 'read-your-own-writes' is best addressed by Session.

Azure Cosmos DB Consistency (Session)

Session consistency guarantees that within a single client session, all writes are visible to subsequent reads, and reads are monotonic. It provides a good balance between consistency and performance for interactive applications, ensuring a consistent user experience.

  • Guarantees Read-Your-Own-Writes within a session.
  • Guarantees Monotonic Reads and Monotonic Writes within a session.
  • Offers better performance and availability than Strong or Bounded Staleness.
  • Most commonly used for client-centric applications where users interact with their own data.

Memory trick: Think 'Strong, Bounded, Session, Consistent, Eventual' for the consistency spectrum.

More Describe how to work with non-relational data on Azure questions