๐ซ Redis Cluster: cheat sheet
๐จ The analogyA school office with 16,384 numbered pigeonholes shared out among the staff, picked by a fixed sum on each name.
๐ The regular explanationRedis Cluster (and Valkey cluster) splits the keyspace into 16,384 hash slots spread across several primaries, each with replicas, and smart clients route every command straight to the node that owns its key's slot.
- The school's 16,384 numbered pigeonholes are split into three stretches. Jo, Sam and Priya each look after one.
- The teacher has Ana's homework. The fixed sum on the name gives pigeonhole 2,226, which is in Jo's stretch, so she takes it to Jo.
- Bo's homework sums to 6,404, a different number in Sam's stretch, so it goes to Sam. Nobody else is bothered.
- Fetching Ana's homework later works the same way. Same name, same sum, same pigeonhole, so the teacher goes straight back to Jo.
- A new teacher only knows where Jo sits, so she asks Jo for Ana's things in pigeonhole 14,585.
- Jo doesn't fetch it. She says "that range is Priya's" and points.
- The teacher copies the office's full list of who has which stretch onto her crib sheet.
- Now she goes straight to Priya, who hands over Ana's things.
- From now on the crib sheet sends her to the right person first time, like Sam for Bo's homework.
- The teacher files Bo's homework with Sam. A moment later, Sam's deputy makes a copy of it.
- Sam suddenly goes home ill. When Jo and Priya check in on the walkie-talkies, Sam doesn't answer.
- Jo and Priya compare notes. Most of the staff agree Sam is really gone, so it's official.
- Sam's deputy asks the others for the go-ahead to take over, and both say yes.
- Sam's deputy now looks after Sam's whole stretch. Teachers go to the deputy instead, and Bo's homework is there.
- Jo's pigeonhole 2,226 holds three items, and teachers come to Jo for them as usual.
- Max joins the office. Jo starts handing pigeonhole 2,226 over to him, one item at a time, and the first item goes across.
- A teacher asks Jo for that first item. It has already gone, so Jo says "ask Max, just this once". The teacher does, and leaves her crib sheet alone.
- The other two items go across too. Now pigeonhole 2,226 is Max's for good, and Jo tells the rest of the office.
- The next teacher who asks Jo hears "that pigeonhole is Max's now". This time she fixes her crib sheet and goes to Max from then on.
- The teacher wants to file Ana's name card and lunch card in one go. Their names sum to 3,495 and 15,648, two different pigeonholes, so Jo refuses the job.
- Now she writes the shared part in brackets on both labels. Only what's in the brackets goes into the sum, so both cards land in pigeonhole 14,585 with Priya.
- Because both cards share one pigeonhole, Priya can swap them together, all or nothing, with no one else involved.
- But if every label in the school had the same bracket, everything would pile into one pigeonhole and Priya would do all the work.
- When the app starts, the runner asks one of the staff it was told about for the full list of who has which stretch.
- The teacher just says "file Ana's homework". The runner does the sum, walks straight to Jo, and comes back with "done".
- Pigeonhole 14,585, where Ana's things are, has just moved to Priya, but the runner's list is old, so Sam says "that range is Priya's". The runner goes to Priya without bothering the teacher.
- Every so often the runner checks the list again anyway, so it hears about changes before it walks to the wrong desk.
๐งฉ Key questions
- A teacher asks Jo for an item in a pigeonhole that's on Priya's stretch. What does Jo do?
- She says "that range is Priya's", and the teacher goes to Priya and updates her crib sheet. Staff never fetch for each other. They point, so teachers learn to go to the right person first time.
- Jo is halfway through handing pigeonhole 2,226 to Max and says "ask Max, just this once". What should the teacher do with her crib sheet?
- Leave it alone: go to Max this once, but still try Jo first next time. Other items in that pigeonhole may still be with Jo. Only when Jo says it's Max's for good does the crib sheet change.
- Why does the office refuse to swap Ana's name card and lunch card together when their names sum to different pigeonholes?
- Each staff member can only do an all-or-nothing job inside one pigeonhole, and nobody coordinates between them. Putting the shared part in brackets makes both cards land in one pigeonhole, so the job is allowed.
- Sam files an item, tells the teacher "done", then goes home ill before the deputy copies it. The deputy takes over. What happened to the item?
- It can be lost: the deputy copies a moment after Sam says "done". That small gap is the price for staff answering quickly.
- The school hires a new staff member. What changes?
- Some pigeonholes are handed over to the new person; their numbers stay the same. Items always sum to the same pigeonhole. Only who looks after a pigeonhole changes, and the office chooses which ones move.