map / distributed-systems / consistency

Distributed Systems · principle 4 of 6

Consistency models

Consistency models are promises about which values a read may return; stronger promises cost coordination, and coordination costs latency.

01 · Why it’s true

Copying data between machines takes time. When a client writes to one replica and then reads from another that hasn’t received the update, it sees old data.

A system can hide this by making reads go to the leader or wait for replicas to catch up — at the cost of latency and availability — or accept it and give weaker guarantees, such as “eventually all replicas agree”. Many systems offer middle ground, such as read-your-writes: a client always sees its own updates.

02 · Picture it

Clientthe user’s appLeadertakes every writeReplicacopies the leader, a bitbehind1write name = “Ana”2ok, saved3read name4old name — stale read5replicate name = “Ana” (late)requestresponsewhere it goes wrongThe read reached a replica before the update did. Read-your-writes fixes it: send thisuser’s reads to the leader for a short while after they write.
WHO’S INVOLVEDClientthe user’s appLeadertakes every writeReplicacopies the leader, a bit behind1Client → Leaderwrite name = “Ana”2Leader → Clientok, saved3Client → Replicaread name4Replica → Clientold name — stale read5Leader → Replicareplicate name = “Ana” (late)requestresponsewhere it goes wrongThe read reached a replica before theupdate did. Read-your-writes fixes it:send this user’s reads to the leaderfor a short while after they write.
Replication takes time, so a replica can answer with old data.

03 · In the interview

  • Explaining replication lag and the user-visible bugs it causes.
  • Choosing which reads must be strongly consistent and which can be stale.
  • Naming practical patterns: read from the leader after a write, sticky sessions, version tokens.

04 · Practice question

“Users update their profile, refresh the page, and sometimes see the old version. What’s happening and how do you fix it?”

A strong answer covers

  1. Writes go to the primary, but reads are served from replicas that lag behind.
  2. Confirm by checking replication lag when the reports occur.
  3. Fixes: read-your-writes — send a user’s reads to the primary for a short window after they write, or pass a version and wait for a replica that has it.
  4. Keep cheap replica reads for data where a little staleness is fine.