Understanding the five consistency levels
Now that we have multiple replicas of our data around the globe, what about data consistency? Cosmos DB provides the following five options:
- Strong
- Bounded staleness
- Session
- Consistent prefix
- Eventual
In a replicated dataset, there is always a trade-off between consistency, availability, throughput, and latency. In theoretical computer science, Brewer's theorem (named after computer scientist Eric Brewer), also known as CAP Theorem, says that "
a distributed database can only give two of the three guarantees; consistency, availability, partition tolerance"
. With this context in mind, Cosmos DB offers five different consistency levels, letting us fine-tune our priorities.
Note
Keep in mind that high consistency levels will require more RUs as well.
The following screenshot shows the Default Consistency
option in the Azure portal, which allows us to pick the desired consistency level:
For those of you experienced with distributed databases, strong and eventual...