Catalog My learning Blog
System Design Roadmap: 100-Day Course for Engineers · Phase 1 · Lesson 6 · 5 min read

Consistency Models: Strong vs Eventual vs Causal

On this page
  1. A reply that appears before its question
  2. Strong consistency and linearizability
  3. Eventual consistency and replica lag
  4. Causal consistency and read-your-writes
  5. How to choose a consistency model per feature
  6. Check yourself

A reply that appears before its question

A blog serves comments from two read replicas to handle traffic. Someone posts a comment; a friend replies within a second. A third reader loads the page from the slower replica and sees the reply, but not the comment it answers. Nothing crashed. The replicas were just at different points in time, and nothing guaranteed what order readers would see writes in.

A consistency model is the set of rules for exactly that: when a read is guaranteed to reflect an earlier write, once copies of data live on more than one node.

Note"Consistency" means three different things in this course. In ACID (Day 27) it means the database's constraints always hold. In CAP (Day 5) it means every read sees the latest write. In this lesson it's a spectrum of guarantees about what reads can see. When someone says "consistent", ask which one.

Strong consistency and linearizability

Every read returns the most recent completed write, whichever node answers. This is what a single PostgreSQL or SQL Server instance gives you, so it feels normal. The strictest form is called linearizability: the system behaves as if there's one copy and every operation happens at a single instant.

Across replicas it costs time, because a write must reach enough copies before it's confirmed. It also costs availability during a partition (Day 5).

Eventual consistency and replica lag

A write is accepted, often by one node, and spreads to the others in the background. If writes stop, all copies eventually match. Until then, different readers can see different values. It's fast and stays available, and it's what most read replicas give you by default.

The problems show up as user-visible oddities:

  • A reply appears before its parent comment.
  • A user edits their comment, refreshes, and sees the old text.
  • Two page loads show comments in different orders.

"Eventually" has no deadline. Replica lag is usually milliseconds to a few seconds, but a long-running query, a big batch write or a network problem can stretch it to minutes. Design for the bad case, and monitor lag (Day 25).

This catches .NET teams on SQL Server. Readable secondaries in an Always On availability group can lag the primary even in synchronous-commit mode, because changes are applied on the secondary by a separate redo step. Microsoft's guidance is to keep reads that can't tolerate latency on the primary (docs). Adding ApplicationIntent=ReadOnly to a connection string is a consistency decision, not just a performance one.

Causal consistency and read-your-writes

Between the two sits causal consistency: if one write depends on another, like a reply on its comment, everyone sees them in that order. Unrelated writes can still appear in different orders on different replicas, which nobody notices.

Several narrower guarantees fix the most visible problems at low cost:

  • Read-your-writes: a user always sees their own changes. The simple version sends a user's reads to the primary for a few seconds after they write. The precise version remembers the write's log position and only reads from a replica that has replayed past it; in PostgreSQL, compare pg_current_wal_lsn() on the primary after the write with pg_last_wal_replay_lsn() on the replica.
  • Monotonic reads: a user never sees data go backwards in time, for example by pinning their reads to one replica.
Strong consistency waits for agreement, eventual consistency accepts delay, and causal consistency keeps cause and effect in order.
Strong consistency waits for agreement, eventual consistency accepts delay, and causal consistency keeps cause and effect in order.

How to choose a consistency model per feature

Consistency is a per-feature decision. One system can use several:

DataModelWhy
Account balance, inventory, unique usernamesStrongStale reads cause real errors or money loss
A user's own profile editsRead-your-writesUsers must see their change; others can lag
Comments and repliesCausalOrder matters; exact timing doesn't
Like counts, view counts, recommendationsEventualBrief staleness is invisible and harmless

Databases often let you choose per request. DynamoDB reads are eventually consistent by default; a strongly consistent read costs twice the read capacity and isn't available on global secondary indexes (docs). MongoDB offers causally consistent sessions. Both make the trade explicit in code.

Check yourself

Read-your-writes. Route that user's reads to the primary briefly after a write, or to a replica known to have caught up with their write.

Fine: a post's like count. Not fine: the remaining balance on a gift card, where two stale reads could both spend the same money.

Synchronous commit makes the log durable on the secondary, but redo applies it slightly later, so reads can lag. Send reads that follow a user's own write to the primary.

With linearizability, once a write completes, every later read anywhere sees it or something newer, as if there were one copy of the data. Eventual consistency only promises replicas converge if writes stop, so a read right after a write may return old data for a while.

Route a user's reads to the primary for a short time after they write, or track the version of their last write and only read from replicas that have caught up to it. Other users can keep reading from replicas with eventual consistency.