Scrivio Interview library
ConceptFoundations6 min read · updated 13 November 2026

A Redis Cluster with three primaries, each with one replica, holds 90 GB. The team plans to add a fourth primary to get more memory and write capacity.

How are keys assigned to nodes, what exactly moves when the fourth primary is added, and what do clients notice while it happens?

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.

Java
CLUSTER KEYSLOT user:1 -- (integer) 10778
CLUSTER KEYSLOT user:2 -- (integer) 6777
CLUSTER KEYSLOT {cart:42}:items -- (integer) 15749, only cart:42 is hashed
# three primaries today
# A: slots 0-5460 B: slots 5461-10922 C: slots 10923-16383

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.

Slots and data before and after
PrimarySlots beforeSlots afterData after
A5,461about 4,096about 22.5 GB
B5,462about 4,096about 22.5 GB
C5,461about 4,096about 22.5 GB
D (new)0about 4,096about 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.

Shell
redis-cli --cluster add-node 10.0.0.14:6379 10.0.0.11:6379 # D joins, owns 0 slots
redis-cli --cluster rebalance 10.0.0.11:6379 --cluster-use-empty-masters
# Moving 1365 slots from 10.0.0.11:6379 to 10.0.0.14:6379
# Moving 1365 slots from 10.0.0.12:6379 to 10.0.0.14:6379
# Moving 1366 slots from 10.0.0.13:6379 to 10.0.0.14:6379
# under the hood, for each slot (here 42):
CLUSTER SETSLOT 42 IMPORTING <A-id> -- on D
CLUSTER SETSLOT 42 MIGRATING <D-id> -- on A
CLUSTER GETKEYSINSLOT 42 100 -- on A: next batch of keys
MIGRATE 10.0.0.14 6379 "" 0 5000 KEYS k1 k2 ... -- copy and delete
CLUSTER SETSLOT 42 NODE <D-id> -- on D, A and the rest

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.

Step throughReading a key during and after migration
ClientPrimary ANew primary D
GET k1 (slot 42, migrating)
-ASK 42 D
ASKING + GET k1
value
GET k2 (after reassignment)
-MOVED 42 D
update slot map
GET k2
value

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.

What to say in the interviewAbout 90 seconds aloud

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/