Archprimer
ConceptIntermediate 7 min read

Replication

Copying data across multiple nodes for read scaling and high availability, using leader-follower or multi-leader topologies with synchronous or asynchronous propagation.

availabilityconsistencyscalingdurabilitydistributed-data

By Ratish Jain · Updated

Diagram with 4 components: Client, Leader, Follower 1, Follower 2. Connections: Client → Leader (1 · write); Leader → Follower 1 (2 · replicate); Leader → Follower 2 (replicate); Follower 1 → Client (3 · read).
ClientDatabase
Writes hit the leader; changes stream to followers that serve reads.

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

Diagram with 5 components: Client, Leader, Follower 1, Follower 2, Reader. Connections: Client → Leader (1 · write); Leader → Follower 1 (2 · stream); Leader → Follower 2 (2 · lag); Reader → Follower 2 (read).
ClientDatabase
The leader takes writes and streams to followers that serve reads (with lag).

Tradeoffs

Pros
  • Read scaling by spreading queries across replicas
  • High availability and durability via redundancy
  • Lower read latency close to users
  • Enables online failover and maintenance
Cons
  • 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

What is the tradeoff between synchronous and asynchronous replication?

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.

How does replication differ from sharding?

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.

60-Second Revision
  • →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.