Replication
Copying data across multiple nodes for read scaling and high availability, using leader-follower or multi-leader topologies with synchronous or asynchronous propagation.
By Ratish Jain · Updated
Definition
Replication keeps copies of the same data on multiple nodes. Each replica holds the full dataset (unlike sharding, which splits it), so the system can survive node loss and serve reads from many machines at once.
Why It Exists
A single database is both a bottleneck for reads and a single point of failure. Replication addresses both: extra copies absorb read traffic (read scaling) and stand ready to take over if the primary dies (high availability and durability). It also places data closer to geographically distributed users.
How It Works
In leader-follower (primary-replica), all writes go to one leader, which streams its change log to followers that apply it and serve reads. In multi-leader, several nodes accept writes and replicate to each other — good for multi-region write locality but prone to write conflicts needing resolution. Propagation is synchronous (leader waits for followers to confirm — safer, slower) or asynchronous (leader acks immediately — faster, but a crash can lose recent writes and followers may lag). Replication lag means a read on a follower can return stale data, so systems offer read-your-writes and other consistency knobs. If the leader fails, a failover promotes a follower, often via leader election.
What It's Used For
- Scaling read-heavy workloads with read replicas
- High availability and automatic failover
- Disaster recovery via geographically separate copies
- Serving low-latency reads near users in each region
- Zero-downtime maintenance by draining one replica at a time
Leader & Followers
Tradeoffs
- Read scaling by spreading queries across replicas
- High availability and durability via redundancy
- Lower read latency close to users
- Enables online failover and maintenance
- Replication lag causes stale reads (eventual consistency)
- Async replication risks losing recent writes on failover
- Multi-leader introduces write-conflict resolution
- Doesn't scale writes — the leader is still the bottleneck
When to Use / Avoid
- Use when
- You are read-heavy and need availability/failover, and can tolerate slightly stale follower reads.
- Avoid when
- The bottleneck is write throughput or the dataset is too big for one node — you need sharding instead.
- Real-world
- PostgreSQL streaming replicas, MySQL primary-replica, and MongoDB replica sets power most production databases.
Interview Questions
Synchronous waits for followers to confirm before acking, so no committed write is lost, but writes are slower and a slow follower stalls them. Asynchronous acks immediately (fast) but can lose recent writes if the leader crashes before replicating.
Replication copies the whole dataset to multiple nodes for availability and read scaling. Sharding splits the dataset into disjoint partitions across nodes for write and storage scaling. They're often combined.
- →Full copies of data on multiple nodes for HA and read scaling.
- →Leader-follower: one writer, many read replicas.
- →Multi-leader: several writers, needs conflict resolution.
- →Sync is safe but slow; async is fast but can lose writes.
- →Replication lag means followers can serve stale reads.
Related
Everything on Archprimer is connected — follow the graph.