Lesson 1 · Unit 03
Shards
Range or hash, and which key to split on
What you practise
- Range vs hash partitioning, hot keys and skew, choosing a partition key, why cross-shard queries and transactions hurt
Try a question from this lesson
Pick one
A users table has 2 billion rows, and one machine holds 500 million comfortably. You already replicate to 3 machines. Does that solve the size problem?
Correct answer
No: every replica still has to hold all 2 billion rows
Why
Replication copies the whole dataset: it adds safety and read capacity, not room. To hold more data than one machine can, the data itself must be split, so that each machine stores only a part.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Shards
Partitioning, or sharding, splits the data so each machine holds only a part: a shard. A key's shard is decided by a rule everyone can compute.
Range partitioning cuts the sorted keys into intervals. Hash partitioning hashes the key and takes the remainder by the number of shards.
Each shard is then replicated, as in the last unit.
range: [a-f] [g-m] [n-s] [t-z]
hash: hash(key) % 4 -> shard 0..310 more exercises in the app
- 3× type the answer
- 4× multiple choice
- 1× fill the blanks
- 1× true or false
- 1× match the pairs
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.