LLI Wiki — My Digital Knowledge Base

Cosmos DB: the five consistency levels explained simply

Strong, bounded staleness, session, consistent prefix and eventual, with a comparison table, practical advice and global distribution basics.

On SQL Server, consistency is effectively "strong": after a COMMIT everyone sees the data (readable secondary replicas aside). Cosmos DB offers five consistency levels between two extremes, because data is replicated, including across regions. Here is how I remember them, without jargon.

The five levels, strongest to weakest

Level What I understand Example
Strong You always read the latest committed write (linearizability) Bank balance
Bounded staleness You may read stale data, but bounded: at most K versions or T seconds behind Near-real-time dashboard across regions
Session Within my session I read my own writes (read-your-writes) A user editing their profile
Consistent prefix Reads are never out of order; you may be behind Ordered event feed
Eventual No ordering guarantee, it converges "someday" Like counters

A few details from the docs:

Practical comparison

Level Read quorum RU cost of reads Possible data loss in a regional outage (RPO), several regions, one write region
Strong Local minority (2 replicas) x2 0
Bounded staleness Local minority (2 replicas) x2 K and T
Session Single replica x1 under 15 min
Consistent prefix Single replica x1 under 15 min
Eventual Single replica x1 under 15 min

For the same amount of RUs, read throughput with strong and bounded staleness is half that of the other levels. Read and write latency is guaranteed under 10 ms at the 99th percentile for all levels, except strong on a multi-region account where write latency depends on network round trips between the farthest regions.

Practical advice

Global distribution and multi-region writes in brief

flowchart LR
    A["Application (region A)"] --> B["Write region A"]
    B -->|"asynchronous replication"| C["Read region B"]
    B -->|"asynchronous replication"| D["Read region C"]
    E["Application (region B)"] --> C

Lessons learned

Further reading

Mastodon LLIMastodon SocialFosstodon