Bounded Staleness - CosmosDB Consistency Models
Bounded Staleness Consistency Level
The Bounded Staleness consistency level is a feature provided by Azure Cosmos DB that allows reads to be served from replicas that are guaranteed to be no more than K updates behind the latest committed write operation.
Syntax
{"consistencyLevel": "BoundedStaleness", "maxStalenessPrefix": K }
Where K represents the maximum number of writes that can be behind the latest write operation.
Example
{
"id": "sample_id",
"name": "John Doe",
"age": 30
}
Output
If we have a maximum staleness prefix of 5, then the read operation will return a result that is guaranteed to be no more than 5 writes behind the latest write operation.
Explanation
Bounded staleness offers low latency guarantees, with reads being served from replicas that are geographically closest. The user requests the number of writes they are willing to wait for before reading stale data. The maximum staleness prefix (K) value is the maximum amount of time a user is willing to wait for a new request update.
Use
Bounded Staleness consistency level is suitable for applications that require low read latencies and can tolerate reading stale data. It is ideal for scenarios such as real-time telemetry and data analytics, or other scenarios where the most recent data is not critical.
Important Points
- Bounded Staleness guarantees to read data that is no more than K updates behind the latest write.
- The user needs to specify the maximum staleness prefix (K) value.
- Lower the maximum staleness prefix value, lower the data freshness and higher the latency of the read operation.
- It is suitable for real-time telemetry and data analytics or other scenarios where the most recent data is not critical.
Summary
Bounded Staleness consistency level is a feature of Azure Cosmos DB that allows users to read from replicas that are guaranteed to be no more than K updates behind the latest committed write operation. It offers low latency guarantees and is suitable for applications that require low read latencies and can tolerate reading stale data. With Bounded Staleness, the user can specify a maximum staleness prefix (K) value, and assign how many writes they are willing to wait for before reading stale data.