Sharding strategies: range, hash, directory
When the writes or the data outgrow one leader, you split the data into shards, each with its own leader and followers, and each owning a slice of the keys. Every request then has to find the right shard. Interviewers want you to say why you're sharding, which key you shard by and how keys map to shards, and what happens to queries that don't name that key.
The exam hall
A university sits a big exam in several rooms. The office has three ways to tell each student which room to go to:
- By surname: A–F in room 1, G–M in room 2, and so on. Easy to guess, and alphabetical lists stay together. But in some places half the students share a few surnames, so one room overflows while another is half empty.
- By the last digit of the student number: digits spread evenly, so rooms fill evenly. But the students whose surnames start with K are now spread over every room.
- By a printed list at the entrance, saying which room each student is in. Any arrangement you like, and you can move one student without moving anyone else. But everyone queues at the list, and if it's lost, nobody knows where to go.