Leader and Followers

The Leader and Followers pattern (also known as Master-Slave or Primary-Replica) is the primary method for maintaining consistency and scaling read throughput in distributed systems. It simplifies the coordination of concurrent updates by designating a single authoritative node—the Leader—to manage all writes to the system state.

1. Role Definitions

The Leader

The Followers

2. Replication Strategies

The mode of replication determines the balance between Consistency and Latency.

ModeProtocolAdvantageDisadvantage
SynchronousLeader waits for all followers to confirm write.Strong consistency; no data loss.Extremely high latency; one slow node blocks the cluster.
AsynchronousLeader acknowledges client immediately after local log.Lowest latency; high write throughput.Risk of data loss if leader fails before logs propagate.
Semi-Synchronous (Quorum)Leader waits for a Majority of followers.Optimal balance of safety and performance.Requires odd number of nodes; complex election logic.

3. Handling Replication Lag

In distributed systems, followers often lag behind the leader due to network congestion or high load. This creates several "stale read" problems that must be addressed via consistency patterns:

4. Leader Election

A critical requirement of this pattern is a robust mechanism for picking a new leader when the current one fails. This is typically achieved through:

  1. Consensus Algorithms: Using Raft or Paxos to reach agreement on the new leader ID.
  2. Heartbeats and Leases: Nodes use Heartbeats to detect leader failure and Leases to prevent multiple nodes from claiming leadership simultaneously.

5. Real-World Usage

See Also