- Published on
Leader and Follower Pattern - FAANG System Design Interview Guide
Table of Contents
- π· 1. Why LeaderβFollower?
- β Problem with Quorum Alone
- β Solution
- π₯ FAANG Question
- π§ Script
- π· 2. Core Idea (LeaderβFollower Model)
- β Roles
- π₯ FAANG Question
- π§ Script
- π· 3. How It Works
- β Flow
- π₯ FAANG Question
- π§ Script
- π· 4. Replication Types
- β Synchronous Replication
- β Asynchronous Replication
- π₯ FAANG Question
- π§ Script
- π· 5. Read Strategy
- β Options
- π₯ FAANG Question
- π§ Script
- π· 6. Leader Election (Failure Handling)
- β What happens if Leader fails?
- β Common Algorithms
- π₯ FAANG Question
- π§ Script
- π· 7. Advantages
- β Benefits
- π₯ FAANG Question
- π§ Script
- π· 8. Challenges
- β Issues
- π₯ FAANG Question
- π§ Script
- π· 9. Real-World Systems
- β Examples
- π₯ FAANG Question
- π§ Script
- π· 10. Interview Gold Points (Often Missed)
- β Important
- π₯ FAANG Question
- π§ Script
- π Final 20-sec Interview Answer
π· 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
- Client β Leader (write)
- Leader β Followers (replicate)
- Followers β ACK
- 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."