Lesson 7 / 32

Replication & Sharding

Copying data for reads; splitting data for writes.

Replication

Keep copies of the same data on multiple nodes. A primary takes writes and streams them to replicas that serve reads and stand by for failover.

Sharding (partitioning)

Split one dataset across nodes by a shard key (e.g. user_id hash or range). Each shard holds a slice, so writes and storage scale out.

Pick the shard key carefully

A bad key creates hotspots (e.g. sharding by date puts all of today's writes on one node). Aim for even distribution and queries that hit one shard.

Quick check: Your database is bottlenecked on write throughput. What helps most?

  • Add read replicas
  • Shard the data
  • Add a bigger cache
Answer

Shard the data — Replicas and caches scale reads. Sharding spreads writes across nodes.