Skip to content

Resharding a live Redis Cluster without dropping traffic

How to move hash slots between shards on a running Redis Cluster — what the client actually sees, what to watch on the cluster, and the exact runbook we follow.

You’re at 78% memory on the master of shard 1 and shard 2 is sitting at 22%. The app team’s last release added a new prefix that hash-tagged itself onto the wrong slot range and now one shard is doing four times the work of the other two. You don’t want to add a fourth shard yet — you want to rebalance the existing three. The question on every operator’s mind is the same: does moving slots actually drop traffic, and if it doesn’t, what does the client see during the move.

What’s happening

A reshard moves hash slots from one master to another, one slot at a time. For each slot:

  1. The destination master is set to IMPORTING for that slot.
  2. The source master is set to MIGRATING for that slot.
  3. Keys in that slot are copied with MIGRATE calls (the destination receives the serialized key + TTL atomically and the source deletes it once the destination acknowledges).
  4. When the slot is empty on the source, a CLUSTER SETSLOT <slot> NODE <dest> is issued cluster-wide and the slot is now permanently owned by the destination.

During step 3, the source serves reads for keys still on it and returns ASK redirections for keys that have been migrated. The destination returns MOVED for keys it has received and ASK for the ones it’s currently importing. A cluster-aware client follows MOVED and ASK transparently — the application sees a few extra round-trips on hot keys mid-migration but no errors. A client that’s not cluster-aware (looking at you, a Python script using redis-py without RedisCluster) will see the raw redirection error and fail the request. This is the single biggest cause of “we resharded and the app fell over.”

What’s also happening, less visibly:

  • Multi-key operations (MGET, MSET, SUNIONSTORE, transactions, Lua scripts) that touch keys in a slot being migrated will return TRYAGAIN. Either retry, or use hash tags so multi-key ops stay within one slot.
  • Pub/Sub on cluster is global — channel subscriptions don’t change during a reshard.
  • The cluster keeps accepting writes throughout. There is no write freeze. New keys land on whichever shard their slot currently belongs to, including slots in flight.
  • Replicas of the source and destination see the migration as normal replication traffic.

How to verify

Before starting, baseline what you have:

redis-cli --tls ... -h <any-node> -p 6379 --user admin -a "$ADMIN_PASS" \
  cluster nodes | awk '$3 ~ /master/ {print $0}'

Read off the slot ranges per master. The slot count totals 16384. Memory per master:

for ip in 10.20.0.11 10.20.0.12 10.20.0.13; do
  echo "=== ${ip} ==="
  redis-cli --tls ... -h "${ip}" -p 6379 --user admin -a "$ADMIN_PASS" \
    info memory | grep -E 'used_memory_human|used_memory_peak_human|maxmemory_human'
done

Confirm the clients you care about are cluster-aware:

# On an app host, check what's actually connecting to Redis
ss -tnp 'sport = :6379' | awk '{print $5,$6}' | sort -u

Then for each language, verify in the codebase or by spot-test. Python: redis.RedisCluster (not Redis). Node: ioredis.Cluster (not ioredis.Redis). Go: redis.NewClusterClient (not redis.NewClient). Java/lettuce: RedisClusterClient (not RedisClient). If any production code path uses the non-cluster client against a clustered endpoint, fix it before you reshard.

During the reshard, watch the source and destination:

watch -n 2 'redis-cli --tls ... -h <source> -p 6379 \
  --user admin -a "$ADMIN_PASS" cluster countkeysinslot <slot>'

And watch client errors. info stats exposes rejected_connections, total_error_replies, and cluster.cluster_links_count:

redis-cli --tls ... -h <source> -p 6379 --user admin -a "$ADMIN_PASS" \
  info stats | grep -E 'rejected|error|cluster'

If total_error_replies ticks up faster than baseline, you have a non-cluster-aware client somewhere. Pause the reshard (Ctrl-C the --cluster reshard command — in-flight slots will finish, no slot ends up in an inconsistent state).

The fix

The runbook we follow for a planned reshard. None of the steps require taking traffic off Redis.

Pre-flight (the day before)

  • Confirm all production clients are cluster-aware. Grep the codebase for Redis( vs RedisCluster( and equivalent.
  • Confirm cluster-require-full-coverage no is set on all masters — otherwise a momentary slot ownership transition can fail writes if any single master is reporting partial state.
  • Confirm replication is healthy: info replication on every master shows master_link_status:up for its replica.
  • Take a fresh BGSAVE on every master (cheap insurance) and confirm AOF appendfsync is everysec or stricter so a crash doesn’t lose more than a second of writes.
  • Pick a window during normal business hours, not the quietest night. You want operators awake and watching when something subtle goes wrong.

Resharding (the planned window)

Use redis-cli --cluster reshard rather than scripting CLUSTER SETSLOT calls by hand:

redis-cli --tls \
  --cacert /etc/redis/tls/ca.crt \
  --cert /etc/redis/tls/redis.crt \
  --key /etc/redis/tls/redis.key \
  --user admin -a "$ADMIN_PASS" \
  --cluster reshard 10.20.0.11:6379 \
  --cluster-from <source-node-id> \
  --cluster-to <destination-node-id> \
  --cluster-slots 2000 \
  --cluster-yes \
  --cluster-pipeline 10 \
  --cluster-timeout 60000
  • --cluster-slots: move this many slots in this run. Move in batches of 500-2000 so each batch is short enough to observe and pause if needed.
  • --cluster-pipeline: number of keys to MIGRATE per round-trip. 10 is safe for small values; bump to 50 for sub-kB values, drop to 1 for values approaching a megabyte.
  • --cluster-timeout: per-MIGRATE timeout in milliseconds. 60s is generous; raise it for clusters with large hash structures.

For a balance-driven reshard rather than a directed one, use --cluster rebalance:

redis-cli --tls ... --cluster rebalance 10.20.0.11:6379 \
  --cluster-weight <node-id-1>=1.0 \
  --cluster-weight <node-id-2>=1.0 \
  --cluster-weight <node-id-3>=1.0 \
  --cluster-threshold 5 \
  --cluster-pipeline 10

--cluster-threshold is the percentage imbalance tolerated. 5 means “rebalance until no node is more than 5% off its target share.”

During the run

  • Tail redis-server.log on the source and destination. Healthy chatter looks like IMPORTING/MIGRATING transitions and slot-completion messages. Errors look like MIGRATE failed or Connection refused — pause and triage.
  • Memory on the source drops as keys migrate out. Memory on the destination rises. Cumulatively, expect a small transient bump on the destination (it holds a key during the brief overlap before the source deletes its copy).
  • Latency on the source’s RDB/AOF persistence may bump if you migrate keys faster than the source can keep up. If slowlog get 10 starts showing MIGRATE entries above your tolerance, lower --cluster-pipeline.

After the run

  • Confirm slot ranges on the receiving node match what you expected:
    redis-cli --tls ... cluster slots
  • Run --cluster check to confirm every slot is owned by exactly one master and every master has at least one replica:
    redis-cli --tls ... --cluster check 10.20.0.11:6379
  • Trigger a CLUSTER FORGET only if you’re removing a node — never as part of normal resharding.
  • Update any internal documentation that mentions per-shard memory budgets.

Adding a brand-new shard

If you’re adding a 4th master + replica rather than rebalancing the existing three:

  1. Install the new pair using the same installer as the rest of the cluster.
  2. Add the new master with --cluster add-node:
    redis-cli --tls ... --cluster add-node 10.20.0.14:6379 10.20.0.11:6379
  3. Add the new replica targeting the new master:
    redis-cli --tls ... --cluster add-node 10.20.0.24:6379 10.20.0.11:6379 \
      --cluster-slave --cluster-master-id <new-master-node-id>
  4. Reshard slots onto the new master in batches (see above).

If something goes wrong

  • A MIGRATE returning IOERR means the network momentarily dropped. The slot is in MIGRATING/IMPORTING state but no keys are lost. Resume by re-running --cluster reshard for the same slot — it will pick up where it left off.
  • If a slot ends up in a stuck IMPORTING state with no source MIGRATING (rare, only after a manual SETSLOT), use CLUSTER SETSLOT <slot> STABLE on both source and destination then re-issue the migration cleanly.
  • Never run CLUSTER FLUSHSLOTS on a production master. It is exactly what it sounds like.

For Redis Cluster operated under our monitoring plane, reshards are scheduled inside Managed Cloud Ops windows with capacity baselines, replication-lag alerts, and a live runbook — book a scoping call if you’d like that taken off your plate.