Video in progress

You need to move a production Redis to another cluster without downtime (say, from standalone to Redis Cluster, or to a different provider). What plan do you make?

First I split the data by type: a cache can start empty in the new place, but sessions, queues and locks can't. Then I prepare the code for the new topology (CROSSSLOT, SELECT, KEYS), move the cache in stages, and move stateful data with replication or dual-write, always with a way back.

📖 Answer

  1. Inventory: use SCAN to get statistics by key prefix: which service, which type, how much memory, whether there's a TTL. Usually 70-90% is cache, which doesn't need to be migrated.

  2. Preparing the code (if moving to Cluster).

  • are the keys in one command or Lua in the same slot: hash tags like {user:42};
  • places that use SELECT, KEYS, FLUSHDB;
  • is cluster topology refresh enabled in Lettuce. I check this first on a staging cluster with a full regression run.
  1. Cache: I start the new cluster empty and shift traffic by percentage with a feature flag: 5%, 25%, 100%. At each step I watch the DB load. If I went to 100% at once, a cold cache would take the DB down.

  2. Stateful data.

  • If the topology is the same, make the new instance a replica of the old one (REPLICAOF), pause writes briefly once it has synced, and promote it. A window of a minute is enough.
  • If the topology or provider is different, use tools like RIOT or redis-shake for an initial copy plus continuous sync, or dual-write at the application level: write to both, read from the new one, and if a key isn't found, read it from the old one and move it over. After the session TTL (say, 30 minutes) passes, nothing touches the old cluster anymore.
  • Queues and streams: I switch the producers to the new one, and the consumers drain the old queue to the end.
  • Locks: two different locks in two clusters means two pods doing the same job. During the switch I pause the jobs that work with locks for a short time.
  1. Rollback: during the dual-write period the old cluster stays current, and flipping the flag back takes a minute. I don't shut down the old cluster right away; it stays "read-only" for a week or two.

Before each stage I write down the success criteria: Redis latency p99, error count, DB CPU. If a criterion is violated, we roll back.