Dev Skills

Consistency models in distributed systems: strong vs eventual

Exact words for how out of date a read is allowed to be, once data lives on more than one machine.

By devskills editorial team · Last updated

1

What problem does a stronger consistency model solve?

In a distributed system, once data lives on more than one machine, "is this current?" stops having one answer. Consistency models give you precise words for how old a read may be, so you can choose per feature instead of waving your hands.

This is where interviews separate people. "It is eventually consistent" is a phrase. "A user sees their own comment immediately, and sees other people's within about two seconds" is a design.

2

What a stronger consistency model costs you

What it costs you
Stronger promises cost speed on every operation, and availability during failures. Weaker promises cost you correctness bugs that only appear under load, in production, and cannot be reproduced on your laptop. They also move the difficulty into application code, where mistakes do not raise errors.
3

When to reach for a stronger consistency model, and when not to

Use it when

  • Strong: money, stock, seats, unique usernames, permission checks. Anything where being wrong cannot be undone.
  • Read-your-own-writes: anywhere a user edits something and then immediately looks at it. That is most user-facing writes.
  • Eventual: counts, feeds, search results, analytics, presence. Anything a person cannot tell is two seconds old.

Do not, when

  • Do not use strong consistency by default because it feels safer. You are paying on every read for a promise most of your features do not need.
  • Do not use eventual consistency for a decision the user cannot undo.
4

How a stronger consistency model actually works

Strongread sees the writeAlways currentcosts latency alwaysRead-your-writesyou see yoursOthers lagcheap, feels correctEventualeveryone lagsConverges latercheapest, most available
Same write, three promises. Each row is a promise you can offer per feature. Pick the cheapest one that keeps users from seeing something wrong.

Strong (linearizable): once a write is confirmed, every later read anywhere returns it. The system behaves like a single machine. It costs a majority round trip on writes, and often on reads too, and it goes unavailable on the smaller side of a network split.

Eventual: if writes stop, all copies end up the same. It promises nothing about when. It also allows a read to go backwards in time. You refresh and see an older value than the one you just saw. That is allowed, and it surprises people.

Read-your-own-writes: you always see your own changes, and other people's may lag behind. This is the sweet spot for user-facing products, and it is far cheaper than strong consistency, because you only have to route one user's reads carefully instead of making the whole system agree. You get it by pinning a user to the leader briefly after a write, or by tracking the write position and reading from a replica that has caught up to it.

Monotonic reads: you never see time run backwards. You get it by keeping a user on one replica, so they at least see one steady version of history. It is cheap, and it removes a whole class of "the page keeps flipping between two values" complaints.

Causal consistency: things that depend on each other show up in the right order. Nobody sees the reply before the comment. It is weaker than strong and much cheaper, and it is often what people mean when they say a system "feels" correct.

The practical move in an interview is to go feature by feature. "The like count is eventual, a second of lag is invisible. The comment you just posted is read-your-own-writes, or you will think it failed. The seat you just booked is strong, because two people cannot have it."

Strong vs eventual consistency, concretely. With strong consistency, a read that starts after a write is confirmed returns that write, wherever it lands. To give that promise, a write must reach a majority (or a leader that every read goes through) before it is confirmed, so every write pays a round trip to other machines, and a replica cut off from the majority must refuse requests rather than answer with old data. With eventual consistency, any replica can answer at once and accept writes locally, and copies converge in the background. Reads are fast and stay available during a network split, and for a while different users see different values.

Which real systems offer which. Many databases let you choose per request instead of per system. DynamoDB reads are eventually consistent by default and can be made strongly consistent per read, at twice the read cost. Cassandra sets a consistency level per query: reading and writing at QUORUM gives you overlap between the two, while ONE is fast and can return stale data. Google Spanner offers external consistency, stronger than linearizability, using synchronised clocks (TrueTime). A PostgreSQL primary with asynchronous read replicas is strong on the primary and eventual on the replicas, which is exactly where read-your-own-writes bugs come from. Check each product's documentation for the exact promise; the names vary.

The isolation level inside one database is a related but separate idea: it is about concurrent transactions, not copies on different machines. Isolation levels covers that side.

ModelWhat a reader is promisedCostUse it for
Strong (linearizable)Every read sees the latest confirmed write, as if there were one copyA majority round trip per write (often per read); unavailable on the minority side of a splitMoney, stock, seats, unique names, permissions
CausalEffects never appear before their causes (no reply before its comment)Tracking dependencies between writesComments, messaging, collaborative edits
Read-your-own-writesYou always see your own writes; others may lagRoute that user's reads carefully for a short timeProfile edits, posts, settings
Monotonic readsYou never see an older value after a newer oneKeep a user on one replicaAny page a user refreshes
EventualCopies converge if writes stop; no promise whenCheapest and most availableCounts, feeds, search, analytics
Consistency models from strongest to weakest. Each row is a promise you can choose per feature.
UserLeadertakes writesReplicaserves reads
the user posts, then immediately reloadsthe replica answers before the copy arrives — their own comment is missingreplication catches up a moment too late
Read-your-writes, or the lack of it: the user posts and reloads faster than replication can copy the row. Nothing is broken. The read went to a machine that has not heard yet.
Common trap
  • Saying "eventually consistent" as if it were a design. How long is eventual, and what does the user see in the meantime?
  • Applying one model to the whole system instead of per feature.
  • Forgetting that eventual consistency lets reads go backwards.
Say this
"Feed and counts are eventually consistent, a couple of seconds of lag nobody notices. A user's own posts are read-your-own-writes, so I pin their reads to the leader for ten seconds after they write. The balance check at payment is strongly consistent, and I accept the extra latency there, because being wrong costs real money."
In depth · 20 min

Consistency models in depth

The summary said "precise words for how out of date a read is allowed to be". This part makes them precise. It covers the six models in the order of what they cost, how to pick one per feature rather than per system, the mechanics of read-your-own-writes, why eventual consistency lets reads go backwards, what strong consistency costs on a good day, and the sentence that turns this from vocabulary into a design.

01

The six models, cheapest first

These are not a quality ladder where stronger is better. They are prices. Each one costs more than the one below it, and the skill is choosing the cheapest one that keeps users from seeing something wrong.

In short
  • Read-your-own-writes covers most user-facing complaints for a fraction of the cost of strong consistency.
  • Monotonic reads is nearly free and removes a whole class of "the page keeps flickering" bugs.
  • Causal consistency is usually what people mean when they say a system "feels" correct.
  • Strong consistency is the one that adds a network round trip to every operation, whether or not anything is broken.
ModelPromiseCost
EventualCopies agree if writes stopReads can go backwards in time
Monotonic readsYou never see an older value than one you sawPin a user to one replica
Read-your-own-writesYou always see your own changesRoute that user's reads carefully
Consistent prefixCauses appear before effectsRoute related writes through one partition
CausalEverything with a dependency appears in orderTrack causality metadata
Strong (linearizable)Any read anywhere sees the last confirmed writeA majority round trip, forever
What each model promises, and what it costs to promise it.
Common trap
Treating the list as a ladder and reaching for the top. Strong consistency on a like count means paying a majority round trip so nobody ever sees a number one lower than the true value for two seconds.
02

Eventual consistency lets reads go backwards

This is the property that surprises people, and it is legal rather than a bug. Under eventual consistency there is no promise about *when* copies agree, and no promise that a sequence of reads sees a non-decreasing view of the world.

Concretely: you load a page and see a comment count of 42, served by a replica that is caught up. You refresh and see 41, because the load balancer sent you to a replica that is three seconds behind. Nothing failed. Both answers were legal.

In short
  • The fix is monotonic reads: pin a user to one replica, usually by hashing their session id, so their view of history only moves forward.
  • It costs almost nothing, and it means one slow replica affects a fixed set of users rather than randomly affecting everyone.
  • A refresh that shows an older value looks like a bug to users, and it is hard to reproduce because it depends on which replica served each read.
  • "Eventually consistent" without a number is a phrase, not a design. Say how long eventual is, and what the user sees in the meantime.
read 1read 2UserReplica Acaught up — 42Replica B3s behind — 41refresh lands on B, count drops, nothing is broken
Two reads, two replicas, time moving backwards. Both answers are legal under eventual consistency. Pinning the user to one replica is what makes their view monotonic.
03

Read-your-own-writes, mechanically

This is often the highest-value guarantee in a user-facing product, because many "the app lost my change" reports are this: the write succeeded, and the next read hit a lagging replica. It is also far cheaper than making the whole system strongly consistent, because you only have to be careful about one user's reads rather than about everybody's.

There are three implementations, in increasing precision and increasing effort.

In short
  • Session pinning: after a user writes, mark their session and send their reads to the leader for a fixed window, say ten or thirty seconds. Two lines of code. The window is a guess, and leader read load rises with your most active users.
  • Write position tokens: the write returns the log position it committed at, the client carries it, and a read waits for a replica that has reached at least that position. Precise, no guessed window, no unnecessary leader load. The catch is that reads can now block, which is a new latency risk.
  • Client-side rendering: do not re-fetch at all. The client already has the value it just submitted, so render that. Free, and it only covers the exact thing they just wrote.
  • A common pattern is the third where it fits and the first everywhere else, moving to the second when leader load becomes measurable.
Say this
"A user's reads go to the leader for ten seconds after they write, so they always see their own changes. Everyone else reads replicas with a second or two of lag. Cost: leader read load rises with my most active users, and I would move to write-position tokens if that became the bottleneck."
04

What strong consistency costs

People choose strong consistency because it feels safe, and then are surprised that the system is slow when nothing is broken. That surprise comes from learning only the first half of PACELC.

Strong consistency means a write is not confirmed until a majority agrees, and often that a read consults a majority too. That is a round trip added to every operation, permanently. Inside one datacenter the network part is about half a millisecond, which is cheap. Across regions it is 80 milliseconds or more, and it applies on every good day, not just during failures.

In short
  • Strong consistency also means unavailability on the minority side of a network split. That is a choice you make on purpose, and for seats or balances it is the right one.
  • It does not scale by adding nodes: a bigger majority is slower to convince.
  • Use it on the specific operation that needs it, not on the whole system. The same product can have a strongly consistent checkout and an eventually consistent feed.
Local write, no coordination~1 ms
Majority within one datacenter~2 ms
Majority across regions~80 ms, on every write, forever

The last row is not a failure cost. It is what you pay on a completely healthy Tuesday, which is the half of PACELC that is easy to forget.

The permanent price of strong consistency, by where your replicas live.
What it costs you
Choosing strong consistency for the whole system to avoid thinking about it per feature means every read of every like count pays for a guarantee only your payment path needed.
05

Choosing per feature: the sentence that scores

The move that turns this from vocabulary into design is going feature by feature, out loud, in one breath. It shows you treat these as prices rather than as qualities.

A worked version for a social commerce product: "The like count is eventually consistent. A second of lag is invisible and I am not spending a round trip on it. A user's own posts are read-your-own-writes, or they will think it failed and post again. Comments under a post are causally consistent, so nobody sees a reply above the thing it replies to. The stock check at checkout is strongly consistent, and I accept the extra latency there because selling the same item twice costs real money."

In short
  • Anything a human cannot tell is two seconds old: eventual.
  • Anything the user just did: read-your-own-writes.
  • Anything with a visible cause and effect: causal or consistent prefix.
  • Anything contested and irreversible: strong, and say you accept the latency.
  • Naming four features with four different answers is worth more than any definition you could recite.
Say this
"Feed and counts eventual, own posts read-your-own-writes, comment threads causally ordered, checkout strong. Four features, four different prices, and the reason each one is different is what the failure costs, not what the database supports."
06

The mistakes that cost points

These come up repeatedly and each one is avoidable with a single extra sentence.

In short
  • Saying "eventually consistent" with no number. How long is eventual, and what does the user see meanwhile?
  • Applying one model to the whole system. Most products need several different answers, and saying so is what the interviewer is listening for.
  • Forgetting that eventual consistency permits reads to go backwards, then being unable to explain the flickering count.
  • Checking a value in application code and then writing. That gap is a race no consistency model closes for you.
  • Confusing consistency with durability. A write can be strongly consistent and still lost if it was never fsynced.
  • Confusing the C in ACID with the C in CAP. They are unrelated: the first means database constraints hold, the second means linearizability: every read sees the latest confirmed write, as if there were one copy.
Common trap
The last one matters more than it sounds. Saying "those are two different properties that happen to share a letter" is a small sign of seniority, and mixing them up undermines everything you say next about consistency.
5

The follow-up an interviewer will ask about a stronger consistency model

"Two users click at the same millisecond. What happens?"

What a strong answer sounds like

It depends on whether the thing they are clicking is contested. If it is a like button, both writes land, the count settles, and nobody cares. I would use an eventual counter and not spend a transaction on it. If it is the last seat, one must win, and the way to guarantee that is to make the decision at a single point. That means a conditional update in the database that only succeeds if the seat is still free, or a unique constraint on (event, seat) so the second insert simply fails. I am not suggesting we check and then write in application code, because that is the race itself. The loser gets a clear message and a suggested alternative. Cost: that write path is now strongly consistent, so it is slower, and it goes unavailable if the owning partition is unreachable. I accept that, because selling one seat twice is worse than an error message.

6

Consistency models: common questions

What is the difference between strong and eventual consistency?

Strong consistency means every read after a confirmed write returns it, as if there were a single copy. Eventual consistency means replicas may return older values for a while but converge once writes stop. Strong costs latency and availability during failures; eventual costs correctness windows that your product has to tolerate.

Is eventual consistency ever acceptable for money?

For displaying a balance, sometimes, with a clear "pending" state. For deciding whether a payment may go ahead, no: that check must read the authoritative value, in the same operation that records the payment.

How is a consistency model different from an isolation level?

Consistency models describe what reads see when data is copied across machines. Isolation levels describe what concurrent transactions see of each other inside one database. Strict serializability combines the strongest of both.

7

Your turn

60-second self-check

A user posts a comment and refreshes, and it is not there. Which consistency guarantee was missing, and what is the cheapest way to add it?

Stuck? Take one hint at a time0 of 3 used
0 / 25 characters
Worked example

Four features, four different answers

You are designing a marketplace. It has a product page with a view count, seller inventory, buyer reviews with replies, and a checkout. A junior engineer proposes making the whole system strongly consistent "to be safe". Your job is to price that proposal and then decide feature by feature.

  1. 1
    Price the blanket proposal

    Strong consistency everywhere means a majority round trip on every read and write. The product page alone does about eight reads, so at about 2 ms of coordination each, run one after another, that is 16 ms added to a page nobody needed protected. If replicas ever span regions it becomes 640 ms and the product is unusable. It also means the page goes down entirely on the minority side of a network split, including the parts that could have been served perfectly well. The proposal was not free, and for most of the page it protected nothing.

  2. 2
    View count: eventual

    Nobody can tell a view count is two seconds old, and nobody makes a decision from it. Eventual consistency, sharded counters, cached total refreshed every few seconds. The cost is that the number can briefly go backwards on refresh, which I remove cheaply by pinning a user to one replica: monotonic reads for almost nothing.

  3. 3
    Seller inventory: two answers, not one

    This is the interesting one, because the same data needs different guarantees in different places. The "3 left" badge on the browse page can be eventually consistent and slightly wrong. The worst case is mild disappointment. The stock check inside checkout must be strongly consistent, and specifically must be a conditional update inside the transaction that reserves the item, not a read followed by a decision. Same field, two guarantees, chosen by what being wrong costs at that moment.

  4. 4
    Reviews and replies: causal

    A reply appearing above the review it answers is not slow, it is nonsense, and users report it as a bug. But full strong consistency is not needed. A review taking two seconds to appear is fine; what matters is it appears in the right order relative to its parent. So route all writes for one review thread through one partition, and ordering comes free, with no cross-partition coordination.

  5. 5
    The seller's own listing: read-your-own-writes

    A seller edits a price and reloads. If a lagging replica serves that read, they see the old price, assume it failed, and edit again, which creates a support ticket and possibly a duplicate. Pin their reads to the leader for ten seconds after any write. This is the cheapest fix on the page, and it prevents the complaint sellers are most likely to raise.

  6. 6
    Say the whole thing in one breath

    "Counts eventual with monotonic reads. Browse-page stock eventual, checkout stock strongly consistent via a conditional update. Review threads causally ordered by partitioning on thread id. A seller's own edits read-your-own-writes for ten seconds. Four features, four prices, each chosen by what being wrong costs."

Result: The design pays for strong consistency on one operation, the one where being wrong means selling stock you do not have, and pays nothing for it everywhere else. The blanket proposal would have cost 16 ms on every page load and taken the whole product down during a network split, in exchange for protecting a view counter nobody was going to complain about.
8

Learn it from the source