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:
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 ...]]
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:
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
This is what makes resharding zero-downtime: every key is always accessible, just the route changes depending on whether the specific key has been migrated yet.
Using redis-cli for Resharding
The redis-cli tool automates the multi-step migration protocol:
Add a Node and Rebalance
rebalance automatically calculates how many slots to move from each existing node to the new one and runs the migration.
Manual Resharding
reshard handles the full SETSLOT MIGRATING/IMPORTING protocol, GETKEYSINSLOT, MIGRATE, and SETSLOT NODE sequence automatically.
Adding a Node as a Replica
Remove a Node
You must first migrate all its slots away, then remove it:
Resharding Performance and Impact
Migration speed is limited by:
- Key size: larger values take longer to serialize and transmit
- Key count: more keys in the migrating slot = longer migration
- Network bandwidth between source and destination
- MIGRATE timeout: keys that cannot be migrated within the timeout are left in place and retried
During migration:
- Read and write commands continue to work (via MOVED/ASK redirections)
- Latency may increase slightly due to extra redirections
- The source node's CPU and I/O load increases during active migration
To minimise impact:
- Migrate during off-peak hours for large datasets
- Use
--cluster-pipelineoption to batch MIGRATE commands - Monitor source node CPU and network during migration
Verifying Migration
Any value > 0 for cluster_slots_pfail or cluster_slots_fail indicates nodes in a degraded state.
When Resharding Time Is Proportional to Key Count
The most common surprise with resharding: it is slow for large datasets. Each key must be serialized, sent over the network, restored on the destination, and deleted from the source. A slot with 1 million keys takes much longer than a slot with 1,000 keys.
For very large datasets:
- Estimate migration time before starting: measure MIGRATE speed (keys/second) on a test slot, extrapolate
- Plan for migrations to take hours on multi-billion-key clusters
- Consider creating the new node as a replica first, letting it sync fully, then resharding — the replica sync is faster than MIGRATE for bulk data transfer
Summary
- Resharding moves hash slots between nodes while traffic continues — zero downtime via MOVING/IMPORTING slot states and ASKING redirections
- MIGRATING on source + IMPORTING on destination: keys not yet moved served from source; keys moved served from destination via ASK
- ASK redirection: temporary — send
ASKINGthen the command; do not update slot map untilCLUSTER SETSLOT NODEfinalises MIGRATEmoves individual keys atomically — key exists on exactly one node at any moment during migrationredis-cli --cluster reshardautomates the full migration protocol;--cluster rebalancedistributes slots evenly after adding nodes- Migration speed = keys/second × key-count; large datasets require hours and should be planned for off-peak
- After migration:
redis-cli --cluster checkto verify all 16,384 slots are covered and healthy
Next: A-11 — Gossip Protocol and Network Partition Handling — how cluster nodes discover each other, propagate topology changes, and handle split scenarios where portions of the cluster become unreachable.
During a live resharding operation, a Redis Cluster client requests a key that belongs to a hash slot currently migrating from Node A to Node B. The specific key has *already* been migrated to Node B. What sequence of events occurs?
When migrating a massive dataset (e.g., 50 million keys) from one Redis Cluster node to another using redis-cli --cluster reshard, what is the most significant performance bottleneck you should anticipate?
You want to gracefully remove a primary node (Node C) from a running Redis Cluster. What is the correct sequence of operations?
Test your knowledge with more question sets
Sign in to access a wider variety of questions and get notified when new practice sets are added to this module.
Sign in & RegisterDiscussion
0Join the discussion