Adding a node to a running cluster, assigning slots, CLUSTER SETSLOT MIGRATING/IMPORTING, the MIGRATE command, zero-downtime resharding with ASKING redirections, and why resharding time scales with key count.
A-10 — Resharding, Node Addition, and Live Slot Migration
Who this module is for: Your Redis Cluster is under capacity and you need to add nodes, or you need to rebalance slot distribution after node failures and recoveries. Resharding moves hash slots between nodes while serving live traffic. This module covers the mechanics of slot migration, the ASKING redirection that enables zero-downtime resharding, and how to use the redis-cli cluster tooling.
Why Resharding?
After initial cluster creation, hash slots are distributed evenly. But over time, the distribution may become uneven:
- Capacity scaling: adding a new node requires migrating slots to it from existing nodes
- Data imbalance: some slots hold more data than others due to access patterns
- Node removal: removing a node requires migrating its slots elsewhere first
- Hotspot correction: if one node handles most traffic, rebalancing moves some slots to less-loaded nodes
Resharding is live — traffic continues flowing during migration. Keys in migrating slots are briefly accessible from both the source and destination during the transition.
Slot Migration: The States
A slot can be in one of three states during migration:
Normal: Slot 7638 is on Node A — all reads/writes go to Node A
MIGRATING: Slot 7638 is migrating FROM Node A to Node B
- Keys still in Node A answer requests
- Keys already moved to Node B → Node A issues ASK redirection
IMPORTING: Slot 7638 is being imported TO Node B
- Node B accepts keys for this slot only if the ASKING command was sent
- Normal requests for slot 7638 still go to Node A
The MIGRATE Command
The low-level operation that moves a single key from one node to another:
MIGRATE host port key destination-db timeout [COPY] [REPLACE] [KEYS key [key ...]]
# Move key "user:1001" from Node A to Node B
MIGRATE 10.0.1.52 6379 user:1001 0 5000
MIGRATE:
- Dumps the key's value (serializes to RDB format)
- Sends it to the destination node with
RESTOREsemantics - If the destination acknowledges: deletes the key from the source
- Atomic from the perspective of each node (the key exists on exactly one node at any moment)
Bulk migration with KEYS option:
MIGRATE 10.0.1.52 6379 "" 0 5000 KEYS user:1001 user:1002 user:1003
Slot Migration Protocol
The full protocol for migrating slot 7638 from Node A to Node B:
# Step 1: Prepare the destination (Node B) to accept the slot
CLUSTER SETSLOT 7638 IMPORTING <node-A-id>
# Step 2: Prepare the source (Node A) to migrate the slot
CLUSTER SETSLOT 7638 MIGRATING <node-B-id>
# Step 3: Get all keys in slot 7638 on Node A, in batches
CLUSTER GETKEYSINSLOT 7638 100 → returns up to 100 keys in this slot
# Step 4: For each batch of keys, MIGRATE to Node B
MIGRATE 10.0.1.52 6379 "" 0 5000 KEYS user:1001 session:abc123
# Repeat steps 3-4 until CLUSTER GETKEYSINSLOT returns empty
# Step 5: Finalize: tell all nodes the slot now belongs to Node B
CLUSTER SETSLOT 7638 NODE <node-B-id>
# This must be sent to ALL nodes in the cluster, not just A and B
After CLUSTER SETSLOT 7638 NODE <node-B-id> is propagated to all nodes, the migration is complete. Normal MOVED redirections take over for slot 7638 pointing to Node B.
The ASKING Redirection During Migration
While slot 7638 is in MIGRATING state on Node A:
- Keys that haven't been migrated yet are still on Node A → served normally
- Keys that have been migrated are on Node B → Node A returns
-ASK 7638 10.0.1.52:6379
The client receiving an ASK redirection must:
- Send
ASKINGto Node B (one-time flag — tells Node B "I know you're importing this slot, accept this command") - Resend the original command to Node B
- Not update its slot map — slot 7638 is still officially on Node A until migration completes
Client → Node A: GET user:1001 (user:1001 already migrated)
Node A → -ASK 7638 10.0.1.52:6379
Client → Node B: ASKING
Client → Node B: GET user:1001 → "Jatin"
# Client's slot map: 7638 → Node A (unchanged)
# Next request for a different key in slot 7638:
Client → Node A: GET user:1002 (still on Node A)
→ served normally
Sign in to keep reading
The rest of this module is free — sign in with Google to unlock it and track your progress.
Sign in & RegisterDiscussion
0Join the discussion