Course contentsShow
← Software Engineering
Lesson 1402 of 1,93341. Scalability and Distributed SystemsFree lesson

Leader-Follower Replication

Single-leader replication with writes to the leader and reads from followers, including synchronous vs asynchronous modes.

Leader-Follower Replication

What You'll Learn

You'll understand how leader-follower replication distributes data across multiple nodes, with writes going to one leader and reads spread across followers.


Core Idea

Leader-follower replication (also called master-slave or primary-replica) is a pattern where one node—the leader—handles all write operations, then propagates those changes to one or more follower nodes. Clients can read from any follower, distributing read load while keeping a single source of truth for writes.

Think of it like a news organization: the editor-in-chief (leader) approves all articles (writes), then distributes them to regional offices (followers) where readers can pick them up locally.


How It Works

  1. All writes go to the leader: Clients send INSERT, UPDATE, DELETE operations only to the leader node
  2. Leader propagates changes: The leader forwards changes to followers through a replication log
  3. Followers apply changes: Each follower applies the log entries to stay synchronized
  4. Reads can go anywhere: Clients can read from the leader or any follower, reducing load on the leader

Synchronous vs Asynchronous Modes

Synchronous replication: The leader waits for at least one follower to confirm it received the write before acknowledging success to the client. Guarantees consistency but adds latency.

Asynchronous replication: The leader acknowledges writes immediately without waiting for followers. Faster, but followers may temporarily lag behind—creating the risk of reading stale data or losing recent writes if the leader fails.

Most systems use a hybrid: one synchronous follower for safety, others asynchronous for performance.


Key Takeaway: Leader-follower replication scales read capacity by distributing reads across followers while centralizing writes on a single leader, with synchronous mode trading speed for consistency and asynchronous mode prioritizing performance.