BlogValkey

Valkey 9 Atomic Slot Migration: What Changes for Resharding

Scott Sternloff

By Scott Sternloff, Senior Enterprise Architect

LinkedIn · Updated · 5 min read

Valkey 9 Atomic Slot Migration: What Changes for Resharding
On this page

Short answer

Valkey 9.0 added atomic slot migration: one CLUSTER MIGRATESLOTS command copies a snapshot of whole slots to the target, streams the changes made meanwhile, then hands over ownership in a single step. The old method moved keys one at a time with MIGRATE and left slots half-moved if it failed. Check job state with CLUSTER GETSLOTMIGRATIONS before and after every reshard.

Valkey 9.0 added atomic slot migration: CLUSTER MIGRATESLOTS copies whole slots to the target as one job, streams the writes made during the copy, then moves ownership in a single step. The older method moved keys one by one with MIGRATE and could leave a slot half-moved if it failed. This post covers the differences, a pre-flight list and what a stuck job looks like. It is written from the Valkey documentation, read 3 December 2026.

Resharding is how you scale a cluster in or out and rebalance a hot shard. Live resharding means clients keep reading and writing while slots move, so the cost of the migration process shows up as redirection, latency and throughput during the move. If you run a sharded cluster and want a second pair of eyes on a reshard, our valkey consulting team works from the same checks.

How does the old per-key slot migration work, and where does it fail?

The legacy method is a manual loop. You mark the slot IMPORTING on the target and MIGRATING on the source, then repeat CLUSTER GETKEYSINSLOT and MIGRATE until the slot is empty, and finish with CLUSTER SETSLOT slot NODE target. While it runs, the source answers -ASK for keys it no longer holds, and the target serves only queries preceded by ASKING.

Valkey's own write-up lists the costs: ASK redirects for clients, multi-key commands failing mid-migration, trouble with very large keys, and rollback that is not well supported. If the loop dies halfway, the slot stays in migrating and importing state until someone clears it. The CLUSTER SETSLOT page says STABLE is mainly used to fix a cluster stuck in a wrong state, and the cluster specification points to valkey-cli --cluster fix for resuming an interrupted migration.

How does atomic slot migration move a slot range from the source node to the target node?

Atomic slot migration moves the data as a unit, in a replication-style flow. The source node connects to the target node and sends CLUSTER SYNCSLOTS. A forked child process sends a snapshot of the slot range, while the parent process streams the changes made during the snapshot to the target. When the remaining changes drop below a threshold, writes pause briefly, the target takes ownership of the slots and broadcasts it, and the source deletes its copy and unpauses writes. This handover is the one step clients can notice: they then get -MOVED instead of a mix of -ASK replies.

CLUSTER MIGRATESLOTS takes the target's node ID and one or more slot ranges. It runs asynchronously, so a script does not need to babysit a long copy. Valkey's write-up lists large keys and multi-key commands among the legacy method's problems, and the new flow does not move key by key.

Until the handover, the incoming slots sit in a staging area that the cluster is not told about, and they are hidden from KEYS, SCAN and DBSIZE on the target. Valkey's blog says many failures, such as out-of-memory, a failover or a network partition, can be handled by the engine, and a cancelled job cleans up the staging area.

Legacy MIGRATE loopAtomic slot migration (9.0+)
Unit of workOne key at a timeWhole slots, one job
Client impact-ASK redirects, multi-key errorsBrief write pause, then -MOVED
FailureSlot left migrating or importingStaged data discarded, slots stay on the source
CleanupSETSLOT STABLE or --cluster fixCLUSTER CANCELSLOTMIGRATIONS
ProgressCount keys yourselfCLUSTER GETSLOTMIGRATIONS

The Valkey docs call atomic migration the recommended method over the legacy one.

What should you check before you start a migration?

  1. Version. Confirm the cluster runs a release that has the 9.0 commands.
  2. Authentication. If you omit AUTH, the source uses its primaryuser and primaryauth. That user needs rights such as +cluster|syncslots and +psync, or the target logs -NOPERM errors. The topic page gives the full ACL rule.
  3. Replica buffers. The replica client-output-buffer-limit must be large enough to hold changes made during the snapshot.
  4. Memory and fork. The source forks a child for the snapshot, so check free memory the way you would before a BGSAVE.
  5. Do not flush. Running FLUSHDB or FLUSHALL on both source and target fails the migration.

Test it under a realistic workload first and watch write throughput and latency around the handover. Then start it: CLUSTER MIGRATESLOTS SLOTSRANGE 0 1000 NODE node-id. The command is asynchronous and returns OK only if every job starts. Cancel with CLUSTER CANCELSLOTMIGRATIONS on the source node.

What does a stuck or failed migration look like?

Run CLUSTER GETSLOTMIGRATIONS on the source and the target. Each entry has an operation, slot_ranges, state, last_update_time, last_ack_time and a message. The states success, failed and cancelled are final. Any other state means the job is active, so a job whose last_update_time stops moving needs a look at the source's memory, the child process and the link to the target. The log lives in memory only and is capped by cluster-slot-migration-log-max-len, which defaults to 1000.

On the legacy method, the signs are slots that CLUSTER NODES shows as migrating or importing long after the tool exited, and keys split across two shards. If you want help reading a stuck cluster, see our Valkey slot migration support use case and Valkey support page.

Sources

Frequently Asked Questions

What is atomic slot migration in Valkey 9?

It is a second way to move hash slots between shards, introduced in Valkey 9.0. A single CLUSTER MIGRATESLOTS command moves whole slots as one job: a snapshot, then the changes made during it, then a handover of ownership. If the job fails, the slots stay with the source.

How do I check a Valkey slot migration?

Run CLUSTER GETSLOTMIGRATIONS on the source and target nodes. Each entry shows an operation (EXPORT or IMPORT), the slot ranges, a state and a message. The states success, failed and cancelled are final; anything else means the job is still running.

How do I clear a stuck migration from the old method?

Find the slot with CLUSTER NODES, then run CLUSTER SETSLOT slot STABLE to clear its migrating or importing state, or run valkey-cli --cluster fix against any node. Check key counts on both shards before and after.

Scott Sternloff

Author

Scott SternloffSenior Enterprise Architect

Senior Enterprise Architect at AceMQ. Writes the technical coverage here: RabbitMQ, Kafka and Redis architecture, clustering and migrations.

Talk to an engineer

Need a hand with Valkey?

Senior engineers who run it in production. Get a quote or a free consultation, no sales pitch.

Free Consultation

Get Expert Eyes on Your Valkey Environment

Whether you're troubleshooting a production incident, planning a migration, or want a second opinion on your architecture — our team is ready. No pitch, just answers.

Email Us