Lesson 10 of 15
15. Sharding

Memory card and where the analogy breaks

3 min read+10 XP

The memory card (tear this page out)

#QuestionMemory code
15.1Why shard?Split the halls only when one hall can't fit the students
15.2Choosing the shard key?Pick the key your busiest questions already contain, with many values and even traffic
15.3Range, hash, directory?Ranges keep neighbours together, hashes scatter them, a list puts anyone anywhere
15.4Hot shards?If the key follows the clock, everyone crowds the newest hall
15.5Resharding?Cut the data into many small groups on day one; later, move groups, not students
15.6Cross-shard queries?One hall for one student; every hall for the topper, so keep topper questions rare
15.7IDs and uniqueness?Every hall numbers its own sheets, so stamp the hall on the number, and check uniqueness in one shared register.
15.8With replication?Split for size, copy for safety: every hall has its own photocopies

The whole chapter in one line: Pick the roll number wisely, cut into many small groups from day one, keep most questions inside one hall, and photocopy every hall.

Where the analogy breaks

  • Students sit still for the exam. Data keeps growing and moving, so resharding is a normal part of life, not a one-off.
  • Halls don't need to agree with each other. Shards sometimes do: a transfer between two users on different shards needs both to commit or neither (Chapter 17).
  • A hall's size is fixed. A shard's load isn't: one viral product or giant customer can make a shard hot overnight.

Quick check

Five questions on this chapter. Pick an answer, then check it.

quiz