System design›Databases at scale: replicas, sharding and the trade-offs
Tutorial 4 of 8 · System design · Data and work at scale · Intermediate
Databases at scale: replicas, sharding and the trade-offs
Copy the database to share the reading, split it to share the storing, and see what each costs.
6 lessons, the last is a challenge · about 1 h · Diagrams, with Python and Java
Before you start
You finished "Scaling out: load balancers and stateless servers": you know that a load balancer hands requests to servers in turn.
You have used SQL from the Databases and SQL path: you can read a SELECT, an INSERT and an UPDATE, and you know what an index on a column is for ("Indexes: why queries are fast or slow").
1Add replicas to share the reading: count how many a load needs, and say why they do not share the writing.
2Explain replication lag and the stale reads it causes, and fix the case a user notices most by sending their own reads to the primary for a short time.
3Split a table across shards by a key, say which shard holds a row, and name the costs: queries that ask every shard, busy shards, and the rows that move when a shard is added.
4State the CAP trade-off without overclaiming: while the network between copies is broken, a system must either answer with what it has or refuse.