Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Availability Patterns  ›  Lesson

Replication

Replication 15 minReplication keeps copies of the same data on several database servers, either with one leader taking writes and followers serving reads, or with several leaders that all accept writes.

Replication

Hop's database now handles 4,000 lookups a second and its CPU sits at 95%. Almost all of that work is reading. What if several machines each held a full copy of the links and shared the reading? That is replication: the same data, kept on more than one server.

The rule

One leader writes, followers copy and serve reads — or many leaders, and conflicts.

Leader-follower (master-slave): one leader accepts all writes. Each change is streamed to followers (replicas), which apply it and serve reads.

new link ──▶ leader ──copies──▶ follower 1, follower 2, follower 3
redirects ───────────────────▶ any follower
  • Great for read-heavy systems: add followers to add read capacity.
  • If the leader dies, a follower is promoted (fail-over from the last lesson).
  • Followers can lag behind, so a fresh write may not be readable from them yet.

Multi-leader (master-master): several leaders accept writes and copy to each other.

  • Writes survive the loss of any one leader and can be local to each region.
  • Two leaders can change the same row at the same moment. Something must decide who wins — a conflict. That logic is hard to get right.

Replication also protects data: a copy on another machine survives a dead disk. But it is not a backup — a mistaken DELETE is faithfully copied to every replica within seconds.

The shortcut

Ask: "Where are the writes?" Writes in one place and reads everywhere → leader-follower. Writes must be accepted in several places at once → multi-leader, and plan for conflicts.

Replicating HopStep 1 of 4
  1. Measure the mix

    40 writes and 4,000 reads per second. Writes are few; reads are the problem.

The trap is expecting followers to add write capacity. Every follower must apply every write, so writes do not spread out — only reads do.

Drills

Answer fast — trust the rule.

quick drill

In leader-follower replication, where do writes go?

quick drill

Hop adds two more read replicas. What mainly increases?

quick drill

What problem is unique to multi-leader replication?

quick drill

Someone runs a mistaken DELETE on the leader. What happens to the followers?

quick drill

A user creates a link and a follower answers "not found" one second later. Why?

Remember

  • One leader writes, followers copy and serve reads — or many leaders, and conflicts.
  • Shortcut: "where are the writes?" One place → leader-follower.
  • Trap: followers add read capacity, not write capacity — and replication is not a backup.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainReplicate Hop's database

Hop's single database handles 40 writes and 4,000 reads per second and is running out of CPU. Propose a replication layout, explain which requests go to which server, and describe one problem the layout introduces and how Hop can live with it.