Azure Cosmos DB Consistency Levels for Predictable Cross-Region Writes

AI-200 By islever Editorial Last updated

Short answer

AC Bounded staleness and Strong consistency are the two levels that provide a guaranteed, predictable window for viewing writes across all regions.

Question

You deploy an AI application across multiple Azure regions. The application must be able to view writes across all regions within a predictable time window. You need to determine the appropriate consistency level. What are two consistency levels you can use to achieve the goal? Each correct answer presents a complete solution. Choose two.
  1. Bounded staleness Correct Answer
  2. Eventual
  3. Strong Correct Answer
  4. Session

Key Takeaways

Bounded staleness and Strong consistency are the correct Azure Cosmos DB models for ensuring reads reflect writes within a predictable time window across regions. Eventual and Session consistency fail to provide the necessary global bounds on data staleness.

Expert Analysis

Strong consistency guarantees reads reflect the most recent write across all regions, and bounded staleness guarantees reads are no more than a predictable window (K iterations or a time interval) behind writes.

This scenario presents a classic distributed systems trade-off in Azure Cosmos DB: balancing data freshness with latency and availability across multiple geographic regions. The critical constraint is that the application must view writes within a "predictable time window." This phrase eliminates any consistency model that offers no upper bound on how stale the data might be for a reader. In multi-region deployments, network partitions and replication lag are inevitable; therefore, the choice of consistency level directly dictates whether the application can guarantee its SLA regarding data visibility.

Option A, Bounded Staleness, is a correct answer because it explicitly addresses the "predictable time window" requirement. When configured, Bounded Staleness ensures that a read request will never see data older than a specified number of versions (K) or a specific time interval (e.g., 5 seconds). If a client writes data in Region A, they can configure the session token or query such that clients in Region B will not see stale data beyond that defined threshold. This provides the deterministic guarantee required by the prompt, making it suitable for applications where eventual consistency is too unpredictable but strong consistency is too expensive or slow.

Option C, Strong consistency, is also a correct answer. Under Strong consistency, every read reflects the most recent committed write globally across all replicas. Since the read always sees the latest write, the "staleness" is effectively zero. Zero is a predictable value. Therefore, Strong consistency inherently satisfies the condition of viewing writes within a predictable time window (specifically, immediately after the write is committed). While it incurs higher latency and lower availability during regional outages compared to other levels, it strictly meets the functional requirement of the question.

Why Option D, Session consistency, fails: Session consistency guarantees consistency only within a single user's session. It ensures that if a client writes data, subsequent reads from that same client will see their own write. However, it does not provide any guarantee about when other users or regions will see the write. There is no global bound on staleness; a user in another region could theoretically wait indefinitely before seeing the update. Thus, it cannot satisfy the cross-region predictability constraint.

Why Option B, Eventual consistency, fails: Eventual consistency offers the highest availability and lowest latency but provides no guarantees regarding the order of updates or the maximum age of stale data. Reads may return outdated information for an indefinite period until background reconciliation occurs. Because there is no defined time window or version limit, it is impossible to promise that a write will be visible within a specific timeframe, violating the core requirement of the scenario.

The distinction between Bounded Staleness and Strong lies in the cost-benefit analysis. Strong is absolute but rigid; Bounded Staleness is flexible but requires configuration. Both, however, share the property of providing a known, finite bound on data staleness, which is the defining characteristic needed to solve this problem.

Practice All AI-200 Questions

Access 69 questions with complete answers and detailed explanations.

View Full AI-200 Practice Test →

← Back to AI-200 Study Guide