Question

Difficulty: Very hardSet Consistency Levels for Azure Cosmos DB

You are designing a globally distributed IoT monitoring solution using Azure Cosmos DB. The account is configured with multi-region writes enabled across East US, West US, and North Europe. The container holding the sensor data was initially partitioned by Region, which resulted in poor write performance and partition rate-limiting. To resolve this, you repartition the container using a high-cardinality key, DeviceId. A stateless analytics service deployed on scaled-out container instances in all three regions reads from the container. Because the instances are stateless and dynamically scaled, they do not share state or Azure Cosmos DB SDK session tokens. The analytics service requires that reads must never see out-of-order writes (writes must be read in the order they were committed). However, the service must also minimize write latency and Request Unit (RU) costs. Which consistency level should you set as the default for the Azure Cosmos DB account to meet these requirements?

  1. Consistent PrefixAnswer
  2. B
    Session
  3. C
    Strong
  4. D
    Eventual

Answer

Consistent Prefix
Consistent Prefix guarantees that reads never see out-of-order writes. Because the analytics service instances are stateless and do not share session tokens, Session consistency falls back to Consistent Prefix-like behavior across different instances. Therefore, Consistent Prefix is the most relaxed consistency level that satisfies the ordering requirements while minimizing latency and Request Unit (RU) costs, and it is fully supported with multi-region writes.

Step-by-Step Solution

1
Analyze the write configuration of the Cosmos DB account.
The account has multi-region writes enabled.
Strong consistency is not supported with multi-region writes, eliminating Strong consistency from the options.
2
Evaluate the client architecture and session token sharing.
The client instances are stateless and do not share session tokens.
Without session token sharing, Session consistency falls back to Consistent Prefix-like behavior for cross-instance reads and cannot guarantee ordering across the different stateless instances.
3
Evaluate the ordering requirement for reads.
Reads must never see out-of-order writes.
Eventual consistency does not guarantee ordering, so it is eliminated. Consistent Prefix is the most relaxed consistency level that guarantees that reads never see out-of-order writes.
4
Evaluate cost and latency constraints.
Consistent Prefix provides the lowest latency and costs (1 RU per read) compared to Bounded Staleness (which has higher write latency and higher read RU cost under some configurations).
Consistent Prefix satisfies all requirements while minimizing cost and write latency.

Key Concept

Selecting the optimal Azure Cosmos DB consistency level based on global distribution, write replication constraints, client session token boundaries, and ordering guarantees.
Estimated Time:3m 0s
Rate this question