Skip to content

Strong, eventual and read-your-writes

Working knowledgeConcept

You save a change, reload the page, and the old value is back. Which machine you read from decides what you see. Here are the main consistency levels, played out on three replicas.

01 You saved it, then it was gone

A user edits their display name and presses Save. The request succeeds. The page reloads and shows the old name. A second later, it shows the new one.

HTTP
PUT /me {"name": "Alice"}
← 200 OK
GET /me
← 200 {"name": "Al"} ← the old name
GET /me (a second later)
← 200 {"name": "Alice"}

Nothing is broken. The write went to one machine and the read came from another that had not caught up. What a reader may see after a write is called the system’s consistency level, and you get to choose it.

02 One leader, two followers

Most databases that scale reads use leader-follower replication. Writes go to the leader. The leader keeps a log of changes and each follower applies that log in order, a little behind. Reads can go to any follower, which spreads the load.

With asynchronous replication, which is the common default (for example in Postgres streaming replication and MySQL), the leader replies to the client before followers have the change. The gap is the replication lag: typically milliseconds, but seconds or more when a follower is busy or far away.

A moment after the save: the leader has v2, the followers do not yet
Alice’s name on each replica
nameversion
LeaderAlicev2
Follower 1Alv1
Follower 2Alv1
  • has the new write

03 Eventual: it gets there, later

Eventual consistency promises one thing: if writes stop, every replica will end up with the same value. It says nothing about how long that takes, or what you see in the meantime.

Reading from followers with no rules
Step 1 of 6
Alice’s name on each replica
nameversion
LeaderAlv1
Follower 1Alv1
Follower 2Alv1
What each request got back
Empty
  • just applied
  • serving a request
  • stale answer
  • all agree

One leader takes writes. Two followers copy its changes a little later and serve reads. All three hold Alice’s old display name, Al, at version v1.

04 Read-your-writes: you always see your own

Read-your-writes (also called read-after-write) adds one promise: after you write, your reads show that write or something newer. Other users may still see old data.

A common way to build it: the write returns a version, the client remembers it, and each read says how new it must be. A replica that is too far behind waits, or hands the read to the leader.

Read-your-writes with a version in the session
Step 1 of 6
Alice’s name on each replica
nameversion
LeaderAlv1
Follower 1Alv1
Follower 2Alv1
Alice’s session
Empty
What each request got back
Empty
  • just applied
  • serving a request
  • stale answer
  • all agree

Same three replicas, all at v1. Alice’s session has no note of her writes yet.

Simpler versions work too: send a user’s reads to the leader for a few seconds after they write, or always read your own profile from the leader and everyone else’s from followers.

05 Strong: everyone sees the latest

Strong consistency (linearizability) means the system behaves as if there were one copy. Once any write is acknowledged, every reader sees it, Alice and Bob alike.

To get it, a read must reach a replica that is sure it has the latest write. Typically that means reading from the leader while it holds a lease, or reading from a quorum of replicas.

EventualMaybe nobody, yetCheapest. Any replica answers, so reads are fast and spread out.
Read-your-writesThe writerA little routing logic. Others may still lag.
StrongEveryoneReads cost a trip to the leader or a quorum, and fail if neither is reachable.
Each level, what it promises, and how it is usually built
LevelPromiseTypical way to get it
EventualReplicas agree once writes stopRead from any follower
Read-your-writesYou see your own writesVersion token, or read from the leader after writing
Monotonic readsYou never go back in timeKeep each user on one follower
StrongEveryone sees every acknowledged writeLeader with a lease, or a read quorum

06 Monotonic reads and other in-between levels

Between eventual and strong sit several small promises. Each fixes one surprise users notice.

  • Monotonic reads: once you have seen v2, you never see v1 again. Without it, a user who refreshes twice and hits two followers can watch a comment appear, then vanish.
  • Consistent prefix: you see writes in the order they happened, so a reply never shows up before the post it answers.
  • Read-your-writes combined with monotonic reads is often called session consistency, and covers most of what a single user can see going wrong.

07 When the guarantee leaks

Another device has no tokenAlice saves on her phone and opens her laptop. The laptop’s session never saw v2. If the guarantee matters across devices, keep the version on the server, against her account.
A cache in front of the replicasA cached copy of /me is one more stale replica. Clear or bypass it for the writer, or the careful routing behind it does not help.
Lag grows under loadTesting with an idle database shows near-zero lag. A big batch job can push it to seconds, and that is when the old name appears in production.
Sticky follower goes downMonotonic reads by pinning a user to one follower breaks when that follower fails and the next one is further behind. Carry a version so the new follower can check.

08 Check yourself

Question

The system offers read-your-writes. Alice saves a new name. Bob reads straight after. Must Bob see it?

Question

A user refreshes and sees 5 comments, then refreshes again and sees 4. Which guarantee is missing?

Question

You route every read to the leader. What do you lose compared with reading from followers?

09 Practise this

Was this tutorial useful?Your vote tells us what to improve next.
Spotted a mistake, or something unclear?