Consistency Models

What 'up to date' means when your data lives on more than one machine — and why you usually get to choose.

Consistency models in 30 seconds

  • What: the contract for whether a read sees the latest write once data lives on multiple machines.
  • It's a spectrum, not a switch — weak, eventual, read-your-writes, monotonic reads, strong.
  • Strong: everyone sees the latest write; simplest to reason about but slower and less available during partitions.
  • Eventual: replicas converge once writes stop; fast and highly available but reads can be stale.
  • The rule: pick the weakest model that's still correct — strong everywhere needlessly slows the system.
  • The classic bug: your own update vanishes on refresh from a lagging replica — fixed by read-your-writes.

The whiteboard in every office

Imagine a company with offices in ten cities, each with a whiteboard listing today's prices. Head office updates the master board and phones each office to copy the change. For a few minutes, the boards disagree — a customer in one city sees the new price while another still sees the old one. Eventually every board matches again. Nobody is lying; the copies are just catching up.

That lag between 'the master changed' and 'every copy reflects it' is the entire subject of consistency models. The question each model answers is simply: when you read one of those whiteboards, what are you promised about how fresh it is? Some setups guarantee you always see the master's latest number; others only promise the boards will agree eventually. Keep the whiteboards in mind and the whole topic stays concrete.

The problem it solves

The moment data is copied across machines, a question appears: if I write here and read over there a millisecond later, do I see my write? A consistency model is the contract your system makes about that. It's not a yes/no switch — it's a spectrum, and where you sit on it trades correctness against speed and availability.

Why not just keep one copy and sidestep the whole problem? Because one copy is a single point of failure and a bottleneck — you replicate data precisely to survive failures and to serve reads fast and close to users. Replication is what buys availability and speed; consistency models are the bill that comes with it. You can't have the copies without facing the question of how fresh each one is.

Consistency is a spectrum; you pick the weakest model that's still correct for the use case.

Where staleness comes from: replication lag

Before the models, understand the mechanism that makes them necessary. Writes usually land on one copy — the primary — which then forwards them to the replicas. That forwarding takes time: a few milliseconds normally, seconds when the network is busy. In that window the replicas are behind, and a read served by a lagging replica returns old data. That lag is the root cause of every staleness bug on this page.

A read that lands on a replica mid-lag sees the old value — the write hasn't arrived yet.

The main models

ModelGuaranteeProsConsFits
StrongEvery read sees the latest write, everywhere.Simplest to reason about; no surprises.Slower; less available during partitions.Money, inventory, bookings.
EventualReplicas converge if writes stop.Fast, highly available.Reads can be stale; order not guaranteed.Feeds, likes, view counts.
Read-your-writesYou always see your own writes.Fixes the most jarring staleness for a user.Needs session routing or stickiness.Profiles, settings, 'did my save work?'
Monotonic readsYou never see data go backwards in time.Avoids confusing flip-flops.Must pin a user to a consistent view.Timelines, paginated reads.

Strong vs eventual, in plain terms

Strong consistency means the system behaves as if there's one copy of the data — everyone sees the same thing at the same time. It's the easiest to build on top of, but it requires coordination that costs latency and can block during network trouble. Eventual consistency lets replicas disagree briefly and promises they'll converge once writes settle. It's fast and stays available, but you must design for reading stale data and for resolving conflicting writes.

The reason strong consistency costs more is physical: to guarantee everyone sees the latest write, the system has to coordinate before confirming a write — wait for replicas to acknowledge, or route all reads through one authority. That waiting is latency, and during a network partition it can mean refusing to answer at all. Eventual consistency skips the waiting (answer now, reconcile later), which is exactly why it's faster and stays available — and exactly why it can hand you stale data.

The everyday symptom: your own write vanishing

The classic bug: a user updates their profile, the write goes to the primary, then their next read hits a lagging replica that hasn't caught up — so their change seems to vanish. This is why read-your-writes exists. You route a user's reads to the primary (or a known up-to-date replica) for a short window after they write, so they always see their own changes even in an otherwise eventually-consistent system.

Eventual read can go stale; read-your-writes pins the user (python)
primary.write(user_id, name="Ada")       # write lands on the primary

# Eventual: next read may hit a lagging replica
replica.read(user_id)   # -> name="Grace"  (old value, not caught up yet)

# Read-your-writes: route this user to an up-to-date copy for a short window
if recently_wrote(user_id):              # e.g. within the last few seconds
    primary.read(user_id)   # -> name="Ada"  (always sees own write)
else:
    replica.read(user_id)   # fine to serve stale reads to everyone else

Monotonic reads: when data appears to go backwards

Read-your-writes fixes your own changes vanishing. There's a sibling bug it doesn't cover: refresh a page and see a newer comment, refresh again and it's gone, refresh a third time and it's back. Nothing is broken — you're just bouncing between replicas that are at different points in catching up, so the data seems to travel backwards in time.

Monotonic reads is the guarantee that fixes this: once you've seen a value, you'll never see an older one on a later read. The usual mechanism is to pin a user to one replica (or route their reads consistently) so they always advance forward through the data, never flip-flop. It's a small guarantee, but its absence produces some of the most confusing bugs beginners ever chase.

The gap eventual consistency can't fill: conflicting writes

Stale reads are the obvious cost of eventual consistency, but there's a sharper one hiding behind it: what if two replicas accept different writes to the same thing at the same time? With no single authority forcing an order, both writes are 'valid' on their own replica, and when the copies sync, the system has to decide which one wins. This is a write conflict, and strong consistency sidesteps it entirely by funneling writes through one coordinator.

Eventually-consistent systems need an explicit rule to resolve the clash. The common strategies each have a catch:

Conflict strategyHow it decidesThe catch
Last-write-winsKeep the write with the latest timestamp.Silently throws away the other write; clocks between machines disagree.
Merge / CRDTsCombine both writes by data-type rules (e.g. union a set).Only works for data that can be merged meaningfully.
Let the app decideSurface both versions; business logic picks.Pushes complexity into every caller.
Last-write-wins silently drops a write when clocks disagree (python)
# Two replicas accept writes to the same key at 'the same time'.
write_a = {"value": "blue",  "ts": 1_000.000}   # replica A's clock
write_b = {"value": "green", "ts":   999.998}   # replica B's clock (running slow)

# On sync, last-write-wins keeps the larger timestamp:
winner = max(write_a, write_b, key=lambda w: w["ts"])
print(winner["value"])   # => "blue"

# But B's clock was just 2ms behind. If 'green' actually happened LATER
# in real time, it was silently discarded. Clock skew makes LWW lossy -
# which is why money and inventory never rely on it.

It all ties back to the CAP trade-off

Consistency models don't live in a vacuum — they're the knob you turn in the famous CAP trade-off. When the network between your copies breaks (a partition), you're forced to choose: refuse to answer until the copies can agree (consistency, but you're briefly unavailable), or keep answering from whichever copy you can reach (availability, but you might serve stale data). You can't have both while the partition lasts.

So picking a consistency model is picking a side of CAP for that data. Strong consistency leans toward refusing-rather-than-lying; eventual consistency leans toward answering-rather-than-waiting. The reason you choose per-capability is that the same app has both kinds of data — a payment that must never be wrong, and a like-count that can be a few seconds stale.

Strong consistency = wait for agreement; eventual = answer now (python)
N = 3   # three copies of the data

# STRONG: a write isn't 'done' until a MAJORITY acknowledge it,
# and a read checks a majority too (a quorum). Correct, but you WAIT -
# and during a partition you may not reach a majority, so you block.
def strong_write(key, value):
    acks = replicate(key, value, copies=N)
    return acks >= (N // 2 + 1)      # need 2 of 3 before confirming

# EVENTUAL: accept the write on ONE copy and return immediately;
# the other copies catch up in the background. Fast and always answers,
# but a read right after may hit a copy that hasn't caught up yet.
def eventual_write(key, value):
    nearest_replica().put(key, value)   # done - sync happens later
    return True
Under a network partition, a consistency model is really a choice between C and A.

Choosing a model per capability

The practical skill is drawing the line inside one system, feature by feature. Ask of each piece of data: 'if a user sees a slightly old value here, does anything actually break?' If no, lean eventual and reap the speed; if yes — money, stock, identity — pay for strong.

Data / capabilityModelWhy
Account balance, paymentsStrongA stale or double-counted value is real money lost.
Inventory / seats leftStrongOverselling the last item is a correctness bug, not a cosmetic one.
Like counts, view countsEventualA few seconds stale is invisible to users; speed matters more.
Social / activity feedEventualMissing one post for a moment is harmless; availability wins.
Your own profile editRead-your-writesYou must see your own save, even if others see it a beat later.

Consistency is the trade-off at the heart of distributed data — it's the lever you pull against latency and availability, and it quietly decides your database and replication strategy.

Why it matters

  • It's a correctness contract: get it wrong on money or inventory and you ship silent, expensive bugs.
  • Treating it as a spectrum lets you buy speed and availability exactly where staleness is harmless.
  • The model you choose ripples into replication, routing, and which database even makes sense.

If ignored

  • You default to strong consistency everywhere and cripple performance for data that never needed it.
  • You use eventual consistency on a bank balance or stock count and corrupt something that matters.
  • You forget read-your-writes and users watch their own saves disappear on refresh.

Where it fits

  • Sits in the data layer, deciding how replicas coordinate and how reads are routed.
  • Draws the line per capability — strong for the payment path, eventual for the feed.
  • Interacts tightly with the CAP trade-off whenever the network partitions.

Related topics

  • CAP theorem: the partition-time choice between consistency and availability
  • Replication: lag between replicas is what makes consistency a question at all
  • Distributed locking: how you enforce strong consistency on a contended resource
  • ACID transactions: strong consistency within a single database's guarantees

Interview lens

Questions it unlocks

  • Strong or eventual consistency here — and why?
  • A user says their update disappeared on refresh. What happened?
  • Where in your design can you tolerate stale reads?
  • Two replicas took conflicting writes — how do you resolve them?

60-second answer

Consistency is a spectrum and I pick the weakest model that's still correct for each piece of data. Money, inventory, and bookings get strong consistency; feeds, likes, and counts are fine eventually consistent and a bit stale. The vanishing-update bug comes from reading a lagging replica right after a write, which I fix with read-your-writes by routing a user's reads to an up-to-date copy for a short window. For eventual systems I also name a conflict-resolution rule, since last-write-wins can silently drop data when clocks disagree. I set the model per capability, not for the whole system.

Common traps

  • Defaulting to strong consistency everywhere and crippling performance.
  • Using eventual consistency for data where staleness is actually harmful.
  • Forgetting read-your-writes and surprising the user who just saved.
  • Choosing eventual consistency without naming how write conflicts get resolved.

Search topics

↑↓ to move · Enter to open · Esc to close