- Print
- DarkLight
- PDF
Understanding Azure Cosmos DB Consistency Levels
- Print
- DarkLight
- PDF
Consistency in Cosmos DB refers to the level of guarantee that the data read from the database will reflect the most recent writes.
Cosmos DB offers five consistency levels to choose from:
Strong: All reads and writes are guaranteed to be always consistent across all replicas of the data. Strong consistency is the most restrictive level and can result in higher latencies.
Bounded Staleness: A guarantee that the data read is at most a certain number of versions or time interval behind the latest write. This consistency level may have lower latency than strong consistency.
Session: All read-and-write operations made by a client in a session are guaranteed to be consistent with each other. This consistency level has lower latency than bounded staleness.
Consistent Prefix: This guarantees that a read operation will return the most recent version of the data, but it may not reflect all writes made to the database at the time of the read. This consistency level may have lower latency than session consistency.
Eventual: This does not guarantee that the read operation will reflect the most recent write, but it guarantees that all writes will eventually be reflected in the read operation. This consistency level may have the lowest latency of all.
When you create a Cosmos DB account, you can choose a default consistency level for the entire account or set a consistency level per request. The consistency level you choose will depend on the requirements of your application and the acceptable level of data inconsistency.