Course contentsShow
← Computer Science
Lesson 2639 of 2,87259. Consensus and ReplicationFree lesson

Leader-Based Replication

Learning the leader-follower pattern where one primary node handles writes and replicas receive updates.

Leader-Based Replication

You'll learn: How the leader-follower pattern coordinates writes through a single primary node and distributes updates to replicas.

What Is Leader-Based Replication?

Leader-based replication (also called primary-replica or master-slave replication) is a replication strategy where one designated node—the leader—handles all write operations, while one or more follower nodes receive and apply those updates to maintain copies of the data.

Think of it like a classroom: the teacher (leader) writes notes on the board, and students (followers) copy them into their notebooks. Only the teacher writes; students replicate what they see.

How It Works

  1. Write requests go exclusively to the leader
  2. The leader processes the write and updates its local storage
  3. The leader sends the change to all followers (often through a replication log)
  4. Followers apply the change to their local copies
  5. Read requests can be handled by the leader or followers (depending on consistency requirements)

Why Use This Pattern?

  • Simplicity: No conflict resolution needed since all writes go through one node
  • Consistency: The leader serializes all writes, establishing a clear order
  • Read scalability: Followers can serve read traffic, distributing load
  • Familiar model: Matches how many traditional databases work

Trade-offs

The leader is a single point of failure for writes. If it crashes, the system must elect a new leader (failover), which adds complexity. Also, followers may lag behind the leader, creating replication lag for reads.

Key Takeaway: Leader-based replication centralizes writes at one node for simplicity and consistency, while distributing read load across followers—but introduces a single point of failure and potential replication lag.