System Design Academy

Saving…

Lesson 7 of 10 in Module 30 of 54 lessons complete

Replication

Module 3, lesson 7Concept12 min

Definition

Replication

In plain English
Replication means keeping copies of the same data on several machines.
Think of it like
It is like a choir where several singers know the same part, so the song continues if one loses their voice.

Leader and follower

In plain English
In leader-follower replication, one machine (the leader) accepts writes and copies them to followers, which serve reads.
Think of it like
It is like a head chef who decides each recipe change and the line cooks who copy it.

Why it exists

Your podcast catalogue has a fast index, but one database machine still handles every read. It eventually runs out of capacity.

If that machine fails, nobody can read the catalogue. Copies provide another place to serve data.

How it works

Replication lag

In plain English
Replication lag is the delay before a change on the leader appears on a follower.
Think of it like
Like news reaching a distant village a day late.

Synchronous vs asynchronous replication

In plain English
Synchronous replication waits for a follower to confirm before saying "done", while asynchronous replication says "done" first and copies afterwards.
Think of it like
Like waiting for a friend to text "got it" versus sending and walking off.

Read-your-writes

In plain English
Read-your-writes is a guarantee that after you change something, your own next read shows the change.
Think of it like
Like seeing your own post immediately after you publish it.

The app writes to a leader, which copies changes to two followers; the app sends reads to those followers.

Separate write routing from read routing in a leader-follower design.

The app writes to a leader, which copies changes to two followers; the app sends reads to those followers.

QuestionSynchronousAsynchronous
When confirm?After required follower acknowledgementWithout waiting for follower acknowledgement
Leader fails?Durably acknowledged copy can preserve confirmed writesUncopied confirmed writes can be lost
Write delayIncludes required follower delayDoes not wait for followers
Required follower unavailable?Writes may wait or failLeader can continue confirming writes
Other replication shapesMeaningCost
Multi-leaderSeveral leaders accept writes and share changesConflicting writes need resolution
LeaderlessClients contact several copies without a permanent leaderReads and writes need careful coordination

Examples

Spread catalogue reads

Your episode listings receive 200 reads per write. Three followers serve reads while the leader stores episode changes.

One leader copies episode changes to three followers, and catalogue reads spread across all three.

Read-only copies share catalogue traffic.

One leader copies episode changes to three followers, and catalogue reads spread across all three.

For 10 writes per second, the ratio gives 2,000 reads per second. Each follower still processes the copied changes.

The insight

Followers add read capacity, subject to replication and routing costs.

Trade-offs

Pros

  • Surviving copies can support recovery.
  • Followers can share reads.
  • Copies can be nearer readers.

Cons

  • Followers may return stale data.
  • Leader replacement needs coordination.
  • One leader still handles all writes.

Use when

  • Reads outgrow one machine.
  • The service needs a surviving data copy.

Avoid when

  • Adding read copies is meant to fix write capacity.
  • You expect replication to replace backups.

Quick check

A user saves a change, refreshes, and sees the old value. Most likely cause?
Main benefit of synchronous replication?

Takeaways

  • Replication keeps copies for safety and read capacity.
  • A leader accepts writes while followers copy changes.
  • Account for replication lag and the exact acknowledgement guarantee.

Try the quick check above whenever you feel ready.

Previous: Indexing