Boss lesson · Unit 03
Add a node at 3 a.m
Move shards while serving traffic
What you practise
- Moving shards while serving traffic, routing (client, proxy or gossip), a secondary index across shards, what happens to requests mid-move
Try a question from this lesson
Pick one
A shard is being copied to a new node, which takes 20 minutes. Halfway through, a write arrives for a key in the part already copied. What is the danger?
Correct answer
The write misses the new copy and vanishes at switch-over
Why
A copy is a snapshot of a moving target. Writes that land on the old node behind the copy's position must also reach the new node, or they disappear when traffic switches. Moving data safely is mostly about those writes.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Fixed partitions
Many stores avoid moving individual keys. They hash each key into one of many fixed partitions, far more than there are nodes, and keep a small map from partition to node.
A key's partition never changes. Rebalancing means moving whole partitions and editing the map.
key ------ hash % 1024 ---> partition
partition ---- map -------> node
add a node:
move some partitions to it,
update the mapConcept
Secondary indexes
The partition key finds one shard. A query on any other column, such as city, needs an index, and the index is split up too.
A local index covers only its own shard's rows: writes stay cheap, but the query must ask every shard.
A global index is partitioned by the indexed value: the query asks one place, but each write now updates two partitions.
10 more exercises in the app
- 3× type the answer
- 1× order the lines
- 3× multiple choice
- 1× match the pairs
- 1× true or false
- 1× fill the blanks
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.