Logo
Published on

Leader and Follower Pattern - FAANG System Design Interview Guide

πŸ”· 1. Why Leader–Follower?

❗ Problem with Quorum Alone

  • Needs majority alive β†’ lower availability
  • Still can have inconsistent reads in edge cases

βœ… Solution

  • Elect one Leader
  • Others = Followers

πŸ‘‰ Leader = source of truth


πŸ”₯ FAANG Question

Q: Why is quorum not enough for consistency? A: Because concurrent writes or failures can still lead to inconsistent reads


🧠 Script

"Quorum ensures agreement but doesn't fully solve coordination; leader-based systems centralize control."


πŸ”· 2. Core Idea (Leader–Follower Model)

βœ… Roles

πŸ‘‘ Leader

  • Handles all writes
  • Replicates data to followers
  • Coordinates system

πŸ‘₯ Followers

  • Store replicated data
  • Serve reads (optional)
  • Backup for failover

πŸ”₯ FAANG Question

Q: Why allow only leader to handle writes? A: To avoid conflicts and ensure strong consistency


🧠 Script

"Leader handles writes to avoid conflicts, while followers replicate data for reliability."


πŸ”· 3. How It Works

βœ… Flow

  1. Client β†’ Leader (write)
  2. Leader β†’ Followers (replicate)
  3. Followers β†’ ACK
  4. Leader β†’ confirms success

πŸ”₯ FAANG Question

Q: When is a write considered successful? A: After replication to required followers (sync or async)


🧠 Script

"Leader writes data and replicates to followers before confirming success."


πŸ”· 4. Replication Types

βœ… Synchronous Replication

  • Wait for followers
  • βœ… Strong consistency
  • ❌ Higher latency

βœ… Asynchronous Replication

  • No waiting
  • βœ… Fast
  • ❌ Possible data loss

πŸ”₯ FAANG Question

Q: Sync vs Async replication trade-off? A: Sync = consistency, Async = performance


🧠 Script

"Synchronous replication ensures consistency; asynchronous improves performance."


πŸ”· 5. Read Strategy

βœ… Options

  • Read from Leader β†’ strong consistency
  • Read from Followers β†’ faster but may be stale

πŸ”₯ FAANG Question

Q: Why can follower reads be stale? A: Due to replication lag


🧠 Script

"Follower reads improve performance but may return stale data due to lag."


πŸ”· 6. Leader Election (Failure Handling)

βœ… What happens if Leader fails?

  • Followers elect new leader
  • System resumes

βœ… Common Algorithms

  • Raft
  • Paxos

πŸ”₯ FAANG Question

Q: What is leader election? A: Process of selecting a new leader after failure


🧠 Script

"When the leader fails, followers elect a new leader to maintain system availability."


πŸ”· 7. Advantages

βœ… Benefits

  • Strong consistency (single writer)
  • Simpler design
  • Easier conflict resolution

πŸ”₯ FAANG Question

Q: Why is leader-based replication simpler? A: Because only one node handles writes β†’ no conflicts


🧠 Script

"Single-writer design simplifies consistency and conflict handling."


πŸ”· 8. Challenges

❌ Issues

  • Leader = single point of failure (until failover)
  • Write bottleneck
  • Replication lag

πŸ”₯ FAANG Question

Q: What is the biggest drawback? A: Leader bottleneck + failover complexity


🧠 Script

"Leader can become a bottleneck and must be handled carefully for failures."


πŸ”· 9. Real-World Systems

βœ… Examples

  • Databases β†’ PostgreSQL
  • Distributed DB β†’ Apache Cassandra (hybrid)
  • Coordination β†’ ZooKeeper

πŸ”₯ FAANG Question

Q: Where is leader-follower used? A: Databases, distributed systems, consensus protocols


🧠 Script

"Leader-follower is widely used in databases and distributed coordination systems."


πŸ”· 10. Interview Gold Points (Often Missed)

⭐ Important

  • Works well with quorum (W, R tuning)
  • Used in strong consistency systems
  • Combine with read replicas for scaling
  • Write throughput limited by leader
  • Failover requires consensus

πŸ”₯ FAANG Question

Q: How do you scale reads in leader-based systems? A: By using follower replicas for read traffic


🧠 Script

"Reads are scaled using followers while writes go through the leader."


πŸš€ Final 20-sec Interview Answer

"Leader-follower replication uses a single leader to handle all writes and replicate data to followers. This ensures strong consistency by avoiding write conflicts. Followers can serve read requests for scalability but may return stale data due to replication lag. In case of leader failure, a new leader is elected using consensus algorithms like Raft. This model is widely used in distributed databases for simplicity and consistency."