The core problem
Data in one place can be lost. So we replicate: store copies across multiple machines.
But replicas alone aren’t enough if we keep writing new data, how do we make sure all copies stay in sync? A copy that never updates isn’t a backup, it’s stale data waiting to cause bugs.
Solution #1: Leader-based replication (Raft-style)
- Pick one entry point the leader. All writes go through it.
- The leader appends the update and waits for a majority of replicas to confirm they have it.
- Why majority, not all? Because:
- Waiting for every replica would be slow and fragile (one dead node blocks everything).
- Majority guarantees overlap if the leader dies, whichever new leader gets elected is guaranteed to have seen the latest committed data (since majorities always intersect).
- If a replica hasn’t gotten the update yet, it’s not lost it’ll eventually catch up.
The read problem
If reads always go to the leader → safe, but slow and a bottleneck (single process serving everyone). If reads go to any follower → faster, but followers can lag → different clients might see different states.
This tension is what consistency models describe.
Consistency models (strongest → weakest)
-
Strong consistency (linearizability)
- Reads/writes only through the leader.
- Feels like there’s a single copy of truth once a write is “done,” everyone sees it immediately after.
- Cost: even the leader can’t trust its own local state blindly it must reconfirm with a majority that it’s still the leader before answering a read (leadership can silently change). This makes reads slow.
-
Sequential consistency
- Followers can serve reads and may lag behind the leader.
- Everyone still sees updates in the same order just possibly at different times.
- Like two people watching the same movie, one starting a bit later same scenes, same order, just offset.
-
Eventual consistency
- Any replica can answer, even far-behind ones.
- No ordering guarantee but the data isn’t lost, it will eventually arrive/converge if writes stop.
- Fine for things where slightly-stale data doesn’t matter (e.g. view counters).
CAP theorem
When a network partition happens (nodes can’t reach each other not necessarily a crash, just broken connectivity):
- Choose Consistency → fail the request rather than risk wrong data.
- Choose Availability → answer anyway, even if the data might be stale.
Partitions aren’t optional the real question CAP asks is: when one happens (not if), what does the system do?
PACELC theorem (extends CAP)
Even when there’s no partition at all, there’s still a tradeoff:
- Stronger consistency = leader must coordinate more (e.g. confirm majority) = higher latency.
- Lower latency = relax consistency guarantees.
So: Partition → Availability or Consistency. Else → Latency or Consistency.
Solution #2: Chain replication
A different topology no majority voting needed.
- Replicas arranged in a line (linked list): head → … → tail.
- Writes go only to the head, which forwards down the chain node by node.
- A write is committed the moment it reaches the tail not via voting, but because the chain’s structure guarantees every earlier node already has it too.
- Reads are served by the tail (in the base version) always fully consistent, no coordination needed per read.
Why it’s faster than leader-based (Raft) reads
- Raft: every read may need the leader to reconfirm majority → expensive.
- Chain: the tail already knows it’s committed → answers immediately, no coordination.
Dirty vs. clean reads (scaling reads further)
To let any node in the chain answer reads (not just the tail):
- Each replica tags its version of the data as:
- Dirty = received the update, but no confirmation yet that the tail committed it.
- Clean = confirmed (an ack has come back from the tail) safe to answer immediately.
- A read on a clean version → instant answer, no coordination.
- A read on a dirty version → must check with the tail first, since it’s not confirmed yet.
Who manages the chain itself?
A separate control plane (built using Raft/Paxos real consensus) handles:
- Detecting failed nodes.
- Reconfiguring the chain (new head, new tail, splicing around a dead middle node).
This works because:
- The data plane (actual client reads/writes) needs zero consensus just forwarding down the chain.
- The control plane only kicks in rarely (on failures) its cost never sits on the critical path of every request.
Fault tolerance limits
- The chain itself tolerates N−1 failures (as long as one node survives, it can be repaired).
- The control plane (Raft-based) only tolerates C/2 failures the fundamental limit of any majority-based consensus.
One-line summary
Leader-based replication (Raft) trades read speed for simplicity and majority-based safety. Chain replication removes the voting bottleneck entirely by forcing writes through every node in order making reads (even from any node, via dirty/clean tracking) fast and fully consistent, while pushing the rare job of “who’s in the chain” onto a separate, Raft-managed control plane.