Replication and Sharding

13 min read

One database on one machine can break, and it can become too big or too busy. Replication keeps copies of the same data. Sharding splits the data into parts. This lesson shows the difference.

New words

Replication
Keeping copies of the same data on different machines.
Primary and replica
The primary takes writes. Replicas keep copies and answer reads.
Failover
Making a replica the new primary when the old primary breaks.
Replication lag
The short delay before a copy gets the newest write.
Sharding
Splitting one big database into smaller parts, called shards.
Shard key
The field that decides which shard a record goes to.
Hot shard
A shard that gets much more work than the others.

What you will learn

  1. The problem: one notebook for the whole college
  2. Replication: photocopies of the notebook
  3. Failover and replication lag
  4. Sharding: splitting the register
  5. Uneven shards and cross-shard questions
  6. Try it: copy or split
  7. Trade-offs
  8. In a real system
  9. Interview tip
  10. Key takeaways

10 quiz questions at the end.

Start this lesson

The full lesson, with interactive demos and the quiz, opens after you sign in with Google. It is free.

All lessons · Back to the roadmap