Skip to content
Low Level Design Mastery Logo
LowLevelDesign Mastery

Replication Strategies

Copies of data that keep your system alive

Replication means keeping copies of the same data on multiple machines. Think of it like having backup copies of important documents in different locations—if one is destroyed, you still have access.

Diagram
GoalHow Replication Helps
High AvailabilityIf one node dies, others continue serving
Read PerformanceDistribute reads across replicas
LatencyPlace replicas closer to users geographically
Disaster RecoveryReplicas in different data centers survive regional failures

Strategy 1: Leader-Follower (Primary-Replica)

Section titled “Strategy 1: Leader-Follower (Primary-Replica)”

The most common replication strategy. One leader handles all writes; followers replicate from the leader and serve reads.

Diagram
  1. Client sends a write to the leader
  2. Leader persists the data locally
  3. Leader sends data to all followers
  4. Followers apply the changes to their copies
  5. Reads can go to any follower (or the leader)

The critical question: Does the leader wait for followers before confirming the write?

Diagram

How it works: Leader waits until ALL (or some) followers confirm they received the data before telling the client “write successful.”

Like: Sending a registered letter—you wait for delivery confirmation.

Trade-off: If any follower is slow or down, the entire write is delayed or blocked.

How it works: Leader immediately tells client “write successful,” then sends data to followers in the background.

Like: Sending a regular letter—you drop it in the mailbox and assume it’ll arrive.

Trade-off: If the leader crashes before replication completes, those writes are lost forever.


Multiple nodes can accept writes. Each leader replicates to others. This is common for geo-distributed systems.

Diagram
  • Multi-datacenter deployment — Users in US write to US leader, EU users write to EU leader
  • Offline clients — Mobile apps that work offline (each device is a “leader”)
  • Collaborative editing — Google Docs-style real-time collaboration

What happens when two leaders accept conflicting writes at the same time?

Imagine this scenario:

  1. User A in the US changes their username to “alice_new”
  2. User B in the EU changes the same username to “alice_updated”
  3. Both leaders accept the write locally
  4. When they sync… which one wins?
Diagram
StrategyHow It WorksBest For
Last-Write-Wins (LWW)Most recent timestamp wins; older write is discardedSimple data, acceptable to lose updates
First-Write-WinsFirst timestamp wins; reject later writesImmutable records
MergeCombine both values using domain logicShopping carts, sets, counters
Custom/User ResolutionStore both, let app or user decideDocuments, complex data

No designated leader — any node can accept reads and writes. Used by systems like Cassandra, DynamoDB, and Riak.

Diagram

The key concept is quorum — a voting system for consistency:

  • N = Total number of replicas
  • W = Number of nodes that must confirm a write
  • R = Number of nodes that must respond to a read

The Rule: If W + R > N, you’re guaranteed to read at least one node with the latest data.

Diagram
ConfigWRTrade-off
Balanced22Good consistency + availability
Write-heavy13Fast writes, slower reads
Read-heavy31Slow writes, fast reads

With async replication, followers may be behind. This creates read consistency challenges:

Diagram
LevelWhat It GuaranteesHow To Achieve
EventualData will sync “eventually”Read from any replica
Read-Your-WritesSee your own writes immediatelyRead from leader after write, or track write timestamps
Monotonic ReadsNever see older data than beforeStick to same replica, or track read positions
Strong/LinearizableAlways see latestRead from leader only

AspectLeader-FollowerMulti-LeaderLeaderless
Write ScalabilityLimited (1 leader)Good (multiple leaders)Best (any node)
Read ScalabilityGood (add followers)GoodGood
ConsistencyEasier to achieveConflict resolution neededQuorum-based
Latency (geo)High (single leader)Low (local leaders)Low
ComplexitySimplestComplex (conflicts)Complex (quorums)
ExamplesMySQL, PostgreSQLCouchDB, Google DocsCassandra, DynamoDB

Replication ConceptLLD Implementation
Sync ReplicationWrite-through cache pattern, blocking writes
Async ReplicationWrite-behind pattern, background jobs, message queues
Conflict ResolutionStrategy pattern for merge logic, domain-specific resolvers
Read ConsistencyStrategy pattern for read routing, client-side timestamp tracking
FailoverObserver pattern for leader changes, Circuit breaker for failed replicas


Now that you understand how data is replicated, let’s learn about building systems that survive failures:

Next up: Fault Tolerance & Redundancy - Learn to design systems that work even when things break.