Consistency Levels
Learn how consistency is maintained in a distributed database and how to take advantage of it.
The distributed nature
To make Cosmos DB scalable and fast worldwide, data is distributed and duplicated in different nodes. Nodes can be in the same data center, region, and continent or on the other side of the world; it depends on the settings we use.
For this reason, we need to accept that to keep performance high, we need to lose consistency. For example, if we write a document in the West Europe region, it will take some time to be updated in the West US region.
In simple terms, we might not get the latest version when we read. However, based on our needs, we can select different levels of consistency. The following five are in order from the fastest to the slowest.
Eventual
Consistent Prefix
Session
Bounded Staleness
Strong
Available levels
Let’s see in detail all the available consistency levels. We start with the weakest consistency that has the best performance to the complete opposite.
Eventual consistency
It’s the weakest form of consistency and the easiest on performance. We don’t have any guarantees that documents are up to date; based on the node we hit, we might even get an older version compared to the last one we got. It’s ideal when we don’t need consistent data, just something to show, even if not precise, like generic statistics and counters.
Imagine a client making three document changes (