Quick revision
The short answer
Redis Cluster splits the key space into 16,384 hash slots, computes slot = CRC16(key) mod 16384 for each key, and gives each primary a range of slots, with replicas that take over when a primary fails. MOVED tells a client that a slot now lives permanently on another node, so it should update its slot map; ASK is a one-off redirect while a slot is being migrated. CROSSSLOT appears when a multi-key command, transaction or script touches keys in different slots, and hash tags such as {user:42} fix it by forcing related keys into one slot.
What to remember
In this answer, we saw that Redis Cluster maps every key to one of 16,384 slots with CRC16 and assigns slot ranges to primaries. MOVED means a slot changed owner and the client must refresh its map, while ASK is a temporary redirect for one command during migration. Multi-key commands, transactions and scripts must stay in one slot, which hash tags make possible. Failover uses gossip and a majority vote, and Lettuce needs topology refresh turned on to follow it quickly.
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.
Redis Cluster splits the key space into 16,384 hash slots, computes slot = CRC16(key) mod 16384 for each key, and gives each primary a range of slots, with replicas that take over when a primary fails. MOVED tells a client that a slot now lives permanently on another node, so it should update its slot map; ASK is a one-off redirect while a slot is being migrated. CROSSSLOT appears when a multi-key command, transaction or script touches keys in different slots, and hash tags such as {user:42} fix it by forcing related keys into one slot.
Why this question is asked
Redis Cluster is how teams grow Redis past the memory and CPU of one machine, and most cloud Redis offerings use it under the hood. It changes the rules a Spring developer can rely on: a command that worked on a single node suddenly fails with CROSSSLOT, or the client logs redirects during a resize. Interviewers ask this to see whether we understand the routing model well enough to design keys for it and configure the client correctly. In this answer, we will see how keys map to slots, follow a request through MOVED and ASK, understand the CROSSSLOT rule and hash tags, and then look at failover and what the Java client must do about it.
1How Keys Map to Hash Slots
A Redis Cluster is a set of primaries, each with one or more replicas. Instead of mapping keys to nodes directly, which would make adding a node painful, Redis maps every key to one of 16,384 hash slots and then assigns slots to primaries. The slot is CRC16(key) mod 16384, where CRC16 is a fast checksum of the key's bytes.
Because slots, not keys, are the unit of ownership, adding a fourth primary means moving some slots to it, and only the keys in those slots move. A cluster-aware client such as Lettuce keeps a copy of the slot map, computes the slot for each command locally and sends the command straight to the right primary, so in the normal case there is no extra hop.
2MOVED and ASK: Two Kinds of Redirect
Sometimes the client's slot map is out of date. If it sends a command to a node that does not own the slot, that node answers with a redirect instead of a result. There are two kinds, and the difference is permanence.
MOVED 8921 10.0.0.12:6379 means slot 8921 is now owned by that node, permanently. The client should retry the command there and update its map, usually by refreshing the whole topology, since one change often means others. This happens after a failover or a completed reshard.
ASK 8921 10.0.0.13:6379 means the slot is in the middle of being migrated. Some of its keys have already moved and some have not. The client should send only this one command to the target node, preceded by the ASKING command, and must not update its map, because the slot still officially belongs to the old node until migration finishes.
5 messages in order. Play them, or step through them one at a time.
ASK is a one-command detour; the slot map is updated only on MOVED.
So MOVED says update your map, and ASK says try over there just this once. A client that treated ASK like MOVED would send later commands for keys not yet migrated to the wrong node.
3Why Multi-Key Commands Fail With CROSSSLOT
A command such as MGET, a MULTI/EXEC transaction or a Lua script runs on one node. If its keys belong to slots on different nodes, no single node could run it atomically, so Redis refuses it. It even refuses keys in different slots on the same node, because those slots could be separated by the next reshard.
The fix is a hash tag. When a key contains a {...} section, Redis hashes only the text inside the first pair of braces. So {user:42}:profile and {user:42}:cart both hash user:42 and land in the same slot. We design the key naming up front so that keys we need to read or change together share a tag, typically the id of the entity they belong to.
In Spring Data Redis we therefore build keys with the tag included, for example "{user:" + userId + "}:cart", and pass every key a script uses in its KEYS argument, so the client can check that they share a slot.
4How Failover Works
Nodes talk to each other constantly over the cluster bus with a gossip protocol, exchanging pings and what they believe about other nodes. When a node stops answering for longer than cluster-node-timeout, others mark it as possibly failing (PFAIL). When a majority of primaries agree, it becomes FAIL. Its replicas then hold an election: a replica asks the primaries for votes, and the one that gets a majority promotes itself and takes over the slots.
Notice the majority requirement. A cluster with three primaries can lose one and keep working, but if a network split leaves a primary on the minority side, that side stops accepting writes after the timeout, which limits split-brain. Writes acknowledged by the old primary but not yet copied to the replica can still be lost, because replication is asynchronous.
5What the Java Client Must Do
After a failover, the slot map in every client is wrong. Lettuce will follow MOVED redirects, but without topology refresh it keeps sending commands to a dead or demoted node first. So we enable both periodic and adaptive refresh, where adaptive means refresh immediately when a MOVED, ASK or reconnect happens.
With this configuration a failover becomes a few seconds of errors and retries rather than minutes of failures. Check the exact property names for your Spring Boot version, since they have moved between releases.
6Follow-up questions
What is the risk of putting too many keys under one hash tag?
Every key with the same tag lands in the same slot, so a tag shared by too many keys creates a hot slot on one node. If we tag everything with {tenant:7} and tenant 7 is our biggest customer, one primary carries its whole load and memory, and we cannot fix it by adding nodes because a slot cannot be split. Tags should group only the keys that genuinely need atomic multi-key operations, usually one entity's keys.
Do SELECT and multiple databases work in Cluster?
No. Redis Cluster supports only database 0, so code that uses SELECT to separate data must use key prefixes instead. This is a common surprise when moving from a single node to Cluster.
Why exactly 16,384 slots?
It is a trade-off: enough slots to spread keys evenly across up to about a thousand primaries, while keeping the slot bitmap that nodes exchange in gossip messages small, about 2 KB.
7Conclusion
In this answer, we saw that Redis Cluster maps every key to one of 16,384 slots with CRC16 and assigns slot ranges to primaries. MOVED means a slot changed owner and the client must refresh its map, while ASK is a temporary redirect for one command during migration. Multi-key commands, transactions and scripts must stay in one slot, which hash tags make possible. Failover uses gossip and a majority vote, and Lettuce needs topology refresh turned on to follow it quickly.
Open with
Redis Cluster divides the key space into 16,384 hash slots. The slot of a key is CRC16 of the key mod 16384, and each primary owns a range of slots, with replicas ready to take over.
Then, if they want more
A cluster-aware client like Lettuce keeps a slot map and sends each command straight to the owner. If its map is stale, the node replies with a redirect. MOVED means the slot now lives permanently on another node, so the client retries there and refreshes its map.
ASK happens during slot migration: the client sends just that one command to the target, preceded by ASKING, and does not change its map. Multi-key commands like MGET, MULTI/EXEC transactions and Lua scripts must touch keys in a single slot, otherwise Redis returns CROSSSLOT.
I solve that with hash tags: only the part in braces is hashed, so {user:42}:cart and {user:42}:profile share a slot, but I keep tags narrow to avoid hot slots. Failover is automatic: nodes gossip, a primary is marked failed when a majority agree, and a replica wins an election and takes its slots.
On the client side I enable periodic and adaptive topology refresh in Lettuce so it reacts to failovers and resharding within seconds.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Redis 7
- 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 "Explain how Redis Cluster distributes keys and handles failover. What do MOVED and ASK...": https://scrivio-interview-library.netlify.app/databases/redis/9013697173/