Replication is the foundation of distributed systems. When your interviewer asks "How do you ensure high availability?" or "What happens if a database server fails?", replication is almost always part of the answer.
Yet many candidates only scratch the surface: "We replicate the data to multiple servers." That is not enough. Interviewers want to know the replication topology, synchronous vs asynchronous trade-offs, how you handle replication lag, what happens during failover, and how you resolve conflicts.
This article provides a deep understanding of replication for system design interviews. We will explore why replication matters, different replication architectures, consistency guarantees, failover mechanisms, and how major databases implement replication.
Here is what we will cover:
If you're enjoying this newsletter and want to get even more value, consider becoming a [paid subscriber](https://blog.algomaster.io/subscribe).
As a paid subscriber, you'll unlock all premium articles and gain full access to all [premium courses](https://algomaster.io/newsletter/paid/resources) on [algomaster.io](https://algomaster.io).
Before diving into implementation details, let us understand why replication is fundamental to distributed systems.
A single database server is a single point of failure.
Problems with a single server:
Replication maintains copies of the same data on multiple machines.
Benefits of replication:
Replication sounds simple, just copy the data. But keeping replicas in sync is hard.
Key questions replication must answer:
Interview insight: "Replication is not just about copying data. It is about defining which node is authoritative, how changes propagate, and what consistency guarantees we provide. The architecture we choose depends on our availability requirements, latency tolerance, and consistency needs."
Single-leader (also called primary-replica or master-slave) is the most common replication architecture.
One node is designated as the leader. All writes go to the leader, which then propagates changes to followers.
Key components:
Statement-based replication:
Log-based (row-based) replication:
Most modern databases use log-based replication for reliability.
Advantages:
Disadvantages:
Single-leader replication excels at scaling reads.
Scaling strategy:
Interview tip: "For our read-heavy workload with a 50:1 read/write ratio, we use a single leader for all writes and 10 read replicas behind a load balancer. This allows us to handle 500,000 reads per second while the leader handles 10,000 writes per second."
Multi-leader (also called active-active or master-master) allows writes on multiple nodes.
Primary use case: Multi-datacenter deployment
The biggest challenge with multi-leader is conflicting writes.
Strategy 1: Last Write Wins (LWW)
Strategy 2: Merge Values
Strategy 3: Custom Application Logic
Strategy 4: Operational Transformation (OT)
Used by collaborative editors like Google Docs.
The best conflict is one that never happens.
Interview insight: "We use multi-leader replication across our three datacenters, but we route each user to their home datacenter for writes. This avoids most conflicts. For the rare case of cross-datacenter conflicts (like a user traveling), we use LWW with logical timestamps."
Leaderless (also called Dynamo-style) replication has no designated leader. Any node can accept writes.
Key concepts:
For consistency, we need: w + r > n
Why w + r > n works:
When nodes are unavailable, strict quorums would reject writes. Sloppy quorums provide higher availability.
How hinted handoff works:
Leaderless systems need mechanisms to fix stale replicas.
Read repair:
Anti-entropy process:
Background process that compares replicas and fixes inconsistencies.
Interview tip: "For our shopping cart service, we use Cassandra with quorum reads and writes (w=2, r=2, n=3). This gives us high availability while ensuring customers see their cart correctly. For less critical data like view counts, we use w=1 for faster writes."
The choice between sync and async replication is one of the most important trade-offs.
Leader waits for followers to confirm before acknowledging the write.
Properties:
Leader acknowledges immediately, replicates in the background.
Properties:
Wait for at least one follower, rest are async.
Benefits:
This is the default in many production setups (MySQL semi-sync, PostgreSQL synchronous_standby_names).
Interview insight: "For our payments service, we use semi-synchronous replication. The leader waits for at least one follower to confirm before acknowledging the write. This gives us strong durability without the latency impact of waiting for all replicas. For our analytics pipeline, we use async replication because occasional data loss is acceptable and we need higher throughput."
Asynchronous replication means followers can fall behind. This creates consistency problems.
Causes of replication lag:
The problem:
Solution: Read-your-writes consistency
Alternative approaches:
The problem:
User reads from different replicas with different lag, sees data "going back in time."
Solution: Monotonic reads
Alternative: Track min LSN seen by user, only read from replicas at or past that LSN.
The problem:
Causally related writes appear in wrong order.
Solution: Consistent prefix reads
Key metrics to monitor:
Interview tip: "We monitor replication lag and route reads appropriately. For user-facing requests requiring fresh data, we read from the leader or wait for a replica with acceptable lag. For analytics queries where staleness is okay, we read from any replica."
Different applications need different consistency levels. Understanding these is crucial for interviews.
Weakest guarantee: If no new writes, all replicas eventually converge.
Strongest guarantee: All operations appear to occur instantly at some point between invocation and response.
Properties:
Cost:
Preserves cause-effect relationships without global ordering.
Rules:
What happens when the leader fails? Failover is critical for availability.
Detection methods:
Challenges:
Failover steps:
Selection criteria:
The most dangerous failover scenario: two nodes both believe they are leader.
Consequences:
Prevention strategies:
Interview insight: "We use Patroni for PostgreSQL failover with a 30-second detection timeout. When the leader fails, the most up-to-date replica is promoted automatically. We use etcd as the consensus store to prevent split-brain, requiring a majority of nodes to agree on the leader."
Let us see how major databases implement replication.
Configuration:
Replication modes:
Replication types:
Write concern options:
Read preference options:
Consistency levels:
Q: How would you set up replication for a global e-commerce platform?
Q: Design replication for a real-time chat application.
Q: Replication lag is growing. How do you debug?
Q: How do you handle failover without data loss?
Replication is fundamental to building reliable distributed systems. Here are the key takeaways:
When discussing replication in interviews, be specific about your choices. Do not just say "we replicate the data." Explain the topology, whether it is synchronous or asynchronous, how you handle lag, what consistency guarantees you provide, and how failover works. This depth demonstrates genuine understanding of distributed systems.
Thank you for reading!
If you found it valuable, hit a like and consider subscribing for more such content every week.
If you have any questions or suggestions, leave a comment.
This post is public so feel free to share it.
P.S. If you're enjoying this newsletter and want to get even more value, consider becoming a [paid subscriber](https://blog.algomaster.io/subscribe).
As a paid subscriber, you'll unlock all premium articles and gain full access to all [premium courses](https://algomaster.io/newsletter/paid/resources) on [algomaster.io](https://algomaster.io).
There are [group discounts](https://blog.algomaster.io/subscribe?group=true), [gift options](https://blog.algomaster.io/subscribe?gift=true), and [referral bonuses](https://blog.algomaster.io/leaderboard) available.
Checkout my [Youtube channel](https://www.youtube.com/@ashishps_1/videos) for more in-depth content.
Follow me on [LinkedIn](https://www.linkedin.com/in/ashishps1/) and [X](https://twitter.com/ashishps_1) to stay updated.
Checkout my [GitHub repositories](https://github.com/ashishps1) for free interview preparation resources.
I hope you have a lovely day!
See you soon,
Ashish