Quick revision
The short answer
Every key belongs to one of 16,384 hash slots, computed as CRC16 of the key (or of its hash tag) modulo 16384, and each primary owns a set of slots. Adding a fourth primary means moving about 4,096 slots, and the keys in them, roughly 22 GB here, from the three existing primaries to the new one, slot by slot. Clients keep working throughout: they follow ASK redirects for keys in a slot that is mid-move and MOVED redirects once a slot has a new owner, with somewhat higher latency.
What to remember
In this answer, we saw that keys map to 16,384 hash slots by CRC16 modulo 16384, with hash tags hashing only the part in braces, and that primaries own slots, not keys. Adding a fourth primary means moving about 4,096 slots and about 22 GB of keys to it, one slot at a time through the IMPORTING and MIGRATING states, MIGRATE and CLUSTER SETSLOT, which redis-cli automates. Clients follow ASK redirects during a move and MOVED redirects after it, with some extra latency, and the new primary needs a replica and both sides need memory headroom.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Every key belongs to one of 16,384 hash slots, computed as CRC16 of the key (or of its hash tag) modulo 16384, and each primary owns a set of slots. Adding a fourth primary means moving about 4,096 slots, and the keys in them, roughly 22 GB here, from the three existing primaries to the new one, slot by slot. Clients keep working throughout: they follow ASK redirects for keys in a slot that is mid-move and MOVED redirects once a slot has a new owner, with somewhat higher latency.
Why this question is asked
Redis Cluster is how Redis grows beyond one machine, and resharding is the operation teams fear most because it moves live data under live traffic. Understanding slots makes it much less mysterious: the cluster never decides where an individual key goes, only who owns each slot, and migration is a careful handover of one slot at a time. Interviewers ask this question to check that we know the mapping, the migration states and what clients see. In this answer, we will recap slots, work out what moves to the new node, follow one slot's migration, look at the client side, and finish with practical rules.
1A Quick Recap of Hash Slots
A Redis Cluster splits the key space into exactly 16,384 hash slots. The slot of a key is CRC16 of the key modulo 16384. If the key contains a hash tag, a non-empty part in curly braces, only that part is hashed, which is how related keys are forced into the same slot. Each primary owns a set of slots, and each slot has exactly one owner at any time.
Because ownership is per slot, the cluster never moves single keys between arbitrary nodes. It moves whole slots, and every key in a slot travels with it.
2What Moves When the Fourth Primary Joins
A new primary joins empty. redis-cli --cluster add-node makes it a member, but it owns no slots and receives no traffic. To share the load evenly among four primaries, each should own about 16384 / 4 = 4,096 slots, so about 1,365 slots move from each of A, B and C to the new node D.
The data moves with them. The cluster holds 90 GB, 30 GB per primary. After rebalancing each holds about 22.5 GB, so roughly 7.5 GB leaves each old primary and about 22 GB arrives on D in total.
| Primary | Slots before | Slots after | Data after |
|---|---|---|---|
| A | 5,461 | about 4,096 | about 22.5 GB |
| B | 5,462 | about 4,096 | about 22.5 GB |
| C | 5,461 | about 4,096 | about 22.5 GB |
| D (new) | 0 | about 4,096 | about 22.5 GB |
3Moving One Slot, Step by Step
Each slot moves through the same steps. The target D is marked IMPORTING for the slot and the source A is marked MIGRATING. Then the keys are copied with MIGRATE in batches; MIGRATE serialises each key on the source, restores it on the target and deletes it from the source, atomically for that key. When the slot is empty on the source, CLUSTER SETSLOT slot NODE D-id assigns it to D everywhere, and the new ownership spreads through the cluster.
The redis-cli --cluster commands add-node, reshard and rebalance automate these steps; we rarely type them by hand, but knowing them helps when a migration stops halfway.
4What Clients Notice
Cluster clients such as Lettuce keep a map of which node owns which slot and send each command straight to the owner. During a migration, the source still owns the slot. If a key has already moved, the source answers -ASK 42 10.0.0.14:6379, and the client sends ASKING followed by the command to D, just for that one command, without changing its map. When the slot is reassigned, any command sent to the old owner gets -MOVED 42 10.0.0.14:6379, and the client updates its map so later commands go straight to D.
9 messages in order. Play them, or step through them one at a time.
So applications keep working. They see somewhat higher latency because of extra round trips and the migration load on both nodes. One more effect: MIGRATE blocks both nodes while it handles a key, so a single very large key, such as a hash with millions of fields, can stall both nodes for hundreds of milliseconds.
5Practical Rules
Give the new primary a replica straight away, or it is a single point of failure for a quarter of the data. Reshard before shards are nearly full, because both the source and the target need memory headroom while keys exist in flight and while the target receives data. Run large rebalances in quieter hours, and look for big keys first, since those are what make migrations slow and risky.
6Follow-up questions
Why can you not split a single hot slot across two nodes?
Because a slot is the unit of ownership: each slot has exactly one owner, and all keys in it live there. If a slot is hot because it holds one hot key, splitting is impossible even in principle, since a key cannot be in two places. The fixes are in the data: split the hot key into several keys with different slots, cache it on the client, or serve reads from replicas.
Why exactly 16,384 slots?
It is a compromise. The slot ownership bitmap that nodes exchange in heartbeats is 16,384 bits, 2 KB, which keeps gossip small, while still allowing up to about 1,000 primaries with good balance.
Do keys move while clients write to them?
A key being migrated is handled atomically by MIGRATE, so a write either reaches it on the source before the move or on the target after it, through an ASK redirect. Clients never see half a key.
7Conclusion
In this answer, we saw that keys map to 16,384 hash slots by CRC16 modulo 16384, with hash tags hashing only the part in braces, and that primaries own slots, not keys. Adding a fourth primary means moving about 4,096 slots and about 22 GB of keys to it, one slot at a time through the IMPORTING and MIGRATING states, MIGRATE and CLUSTER SETSLOT, which redis-cli automates. Clients follow ASK redirects during a move and MOVED redirects after it, with some extra latency, and the new primary needs a replica and both sides need memory headroom.
Open with
In Redis Cluster every key maps to one of 16,384 hash slots: CRC16 of the key modulo 16384, or of the hash tag if the key has a non-empty part in braces.
Then, if they want more
Each primary owns a set of slots, and the cluster only ever moves whole slots, never individual keys.
When we add a fourth primary, it joins empty and owns nothing, so to balance four primaries it should get about 4,096 slots, around 1,365 from each of the existing three, and the keys in them come along, roughly 22 gigabytes of our 90.
Slots move one at a time: the target is marked IMPORTING, the source MIGRATING, keys are copied in batches with MIGRATE, which moves each key atomically, and then CLUSTER SETSLOT NODE assigns the slot to the new owner. In practice I would use redis-cli cluster add-node and rebalance with the use-empty-masters option, which do all of this. Clients keep working.
If they ask the old node for a key that already moved, they get an ASK redirect for that one command, and once the slot is reassigned they get MOVED and update their slot map. They notice somewhat higher latency, and a very large key can block both nodes briefly while it migrates.
I would also give the new primary a replica and reshard before shards are nearly full, because migration needs memory headroom on both sides.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Redis documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How are keys assigned to nodes, what exactly moves when the fourth primary is added, and...": https://scrivio-interview-library.netlify.app/databases/redis-scaling/65c9b06739/