Quick revision
The short answer
I would first audit every service for cluster-incompatible usage, database numbers, KEYS and SCAN in request paths, MULTI/EXEC, cross-slot multi-key commands and Lua scripts, and pub/sub assumptions, and prove each one with an integration test against a real multi-node cluster and a shared client configuration. Then I would classify the data: caches start empty on the cluster with controlled warm-up, while sessions and other state are copied by dual writes or a replication-based migration tool and verified by counts and sampling. Services switch one by one behind a configuration flag, least risky first, with a rollback path to Sentinel, and progress is tracked in one place with a review rule that stops new incompatible code.
What to remember
In this answer, we planned the migration as small, proven steps. Each service is audited for cluster-incompatible usage and proven with an integration test on a real multi-node cluster and a shared client configuration. Caches start empty with controlled warm-up, while sessions and state are copied by dual writes or a replication-based tool and verified by counts and sampling. Services switch one by one behind a flag, least risky first, with a rollback path while Sentinel stays current, and one tracking page plus a review rule keep the quarter on schedule.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would first audit every service for cluster-incompatible usage, database numbers, KEYS and SCAN in request paths, MULTI/EXEC, cross-slot multi-key commands and Lua scripts, and pub/sub assumptions, and prove each one with an integration test against a real multi-node cluster and a shared client configuration. Then I would classify the data: caches start empty on the cluster with controlled warm-up, while sessions and other state are copied by dual writes or a replication-based migration tool and verified by counts and sampling. Services switch one by one behind a configuration flag, least risky first, with a rollback path to Sentinel, and progress is tracked in one place with a review rule that stops new incompatible code.
Why this question is asked
A migration of 40 services in one quarter fails in two typical ways: services switch and break in production because of a hidden cluster incompatibility, or the migration stalls because nobody can tell which services are safe. The deadline is real, too, because the single primary is at its memory and CPU limits. Interviewers ask this to see whether we can turn a risky big-bang change into a sequence of small, proven steps. In this answer, we will audit the services, prove compatibility with tests, decide how each kind of data moves, plan the switch with a rollback, and keep the migration on track.
1A Quick Recap of What Breaks on a Cluster
Redis Cluster spreads keys over nodes by hash slot, and a single command, transaction or script may only touch keys in one slot. From that rule come the incompatibilities: databases other than 0 do not exist, multi-key commands across slots fail or are split by the client, MULTI/EXEC is not supported on Spring Data Redis cluster connections, Lua scripts must receive keys that share a slot, KEYS and SCAN only see one node and are fanned out to all primaries by Spring, and classic pub/sub broadcasts every message to every node.
The services in this platform use RedisTemplate, Spring Cache, Spring Session and Lua scripts, so we should expect each of these to appear somewhere.
2Auditing Each Service
The audit combines a code search with what the current Sentinel-managed Redis already tells us. In code, we search for spring.data.redis.database, keys( and scan(, multi() and SessionCallback, execute with RedisScript, multi-key operations such as opsForValue().multiGet and delete with collections, and message listeners. On the server, INFO commandstats shows whether KEYS, MULTI, EVALSHA or PUBLISH are used at all, and the client name in CLIENT LIST helps tie them to services.
Each service then gets a short audit record: what it uses, what must change, and who owns the change. Many services will turn out to be clean, using only single-key operations and @Cacheable. Those become the first to move.
3Proving Compatibility Before the Switch
An audit finds most problems; a test finds the rest. Every service gets an integration test that runs against a real multi-node cluster in a container, for example six nodes with Testcontainers, so that keys really land on different nodes. A single-node "cluster" hides cross-slot problems because every slot is on one node. The tests run the service's Redis-using code paths, including cache eviction, session handling and the Lua scripts, and fail on any CROSSSLOT error or exception.
At the same time, all services move to a shared client configuration, ideally a company starter, with cluster topology refresh, TCP keepalive and user timeout, and sensible command timeouts. That removes a whole class of migration-day problems, such as clients that keep hitting old nodes after a reshard.
4Moving the Live Data
How data moves depends on what it is. Caches can start empty on the cluster: they fill from the databases as requests arrive. The risk is the load a cold cache sends to the databases, so cache-heavy services switch outside peak hours, perhaps with a small warm-up job for the hottest keys, and with limits on database connections so a cold start degrades gracefully.
Sessions and other state cannot be lost, or users are logged out and in-flight work disappears. There are two ways to copy them. Dual writes have the service write to both Sentinel and Cluster during a transition window as long as the longest TTL, reading from the old store until the new one has everything. A replication-based migration tool, such as RedisShake or a managed service's migration feature, reads the source's replication stream and applies it to the cluster continuously, so the cluster stays current until the switch. Either way, we verify before switching: key counts per prefix on both sides, and sampling a few thousand keys to compare values and TTLs.
| Data | Method | Verification |
|---|---|---|
| Spring Cache entries | start empty, warm hottest keys | hit ratio recovers; DB load within limits |
| Spring Session | dual write for one session TTL, or sync tool | key counts; sampled sessions readable |
| Counters, queues, other state | replication-based sync tool, then switch | counts and sampled values match |
| Lua-script keys | rename with hash tags during copy | script tests pass on cluster |
5Switching Service by Service
Each service switches behind a configuration flag that chooses the Sentinel or Cluster connection, so the switch is a configuration change and the rollback is the same change in reverse. We start with the least risky services, such as pure caches, to gain confidence and find platform issues early, and leave the riskiest, those with sessions, scripts or queues, for last, when the process is proven.
Rollback is only safe while Sentinel still holds current data. For caches that is always true enough. For state, it means continuing dual writes or the replication stream for a period after the switch, a few days for most services, before the old copy is dropped. Only when every service has moved and the rollback window has passed do we retire the Sentinel deployment.
- Auditcode search + command stats; record what must change
- Fix and testintegration test on a 6-node cluster passes
- Copy datacaches: none; state: dual write or sync tool
- Verifykey counts and sampled values match
- Flip the flagoff-peak; watch errors, latency, DB load
- Healthy for the rollback window?YesStop copying; mark doneNoFlip back to Sentinel, fix, retry
6 steps in order. Play them, or step through them one at a time.
6Keeping the Migration on Track
With 40 services and one quarter, visibility matters. One tracking page lists every service with its audit status, test status, data method, switch date and owner, and is reviewed weekly. Risks, such as a service whose Lua scripts need a redesign, are raised early so they do not surprise us in the last month.
Finally, the migration must not be undone by new code. A design review checklist item and a pull request template question ask whether a change uses KEYS, MULTI/EXEC, multi-key operations or new scripts, and the cluster integration test in each service's build catches what reviews miss.
7Follow-up questions
Which service would you move first, and why?
A low-risk service that still exercises the platform: one that uses RedisTemplate and @Cacheable with single-key operations, has moderate traffic, an engaged team and no sessions or scripts. Its switch tests the shared client configuration, the cluster's operation, monitoring and the flag mechanism with little to lose, because its data is a cache that refills. Moving a trivial service first proves less, and moving a critical one first risks the whole programme's credibility.
Why not move the data once with a dump and restore?
Because it requires stopping writes for the duration of the copy to avoid losing changes, which means downtime for every service, and the dataset is large. A replication-based tool or dual writes keep the cluster current while the old system keeps serving, so the switch takes seconds and can be reversed.
How would you handle a service whose Lua script touches unrelated keys?
Redesign the keys so the script's keys share a hash tag, if they belong to one entity; otherwise split the script into steps that are each single-slot and make the overall operation idempotent. That service then moves late, after its tests pass on the cluster.
8Conclusion
In this answer, we planned the migration as small, proven steps. Each service is audited for cluster-incompatible usage and proven with an integration test on a real multi-node cluster and a shared client configuration. Caches start empty with controlled warm-up, while sessions and state are copied by dual writes or a replication-based tool and verified by counts and sampling. Services switch one by one behind a flag, least risky first, with a rollback path while Sentinel stays current, and one tracking page plus a review rule keep the quarter on schedule.
Open with
I would run it as a pipeline that every service goes through. First an audit: code search for database numbers other than 0, KEYS and SCAN in request paths, MULTI/EXEC, multi-key commands and Lua scripts across slots, and pub/sub assumptions, plus INFO commandstats on the current Redis to see what is actually used.
Then, if they want more
Second, proof: each service gets an integration test against a real multi-node cluster in a container, because a single node hides cross-slot problems, and every service moves to a shared client configuration with topology refresh, keepalive and timeouts. Third, data. Caches can start empty on the cluster, with warm-up of the hottest keys and limits on database load.
Sessions and other state must be copied, either by dual writes for a window as long as the longest TTL, or with a replication-based migration tool, and I would verify by key counts per prefix and by sampling values and TTLs.
Fourth, the switch: service by service behind a configuration flag, low-risk caches first and the riskiest last, with a rollback path to Sentinel while it still holds current data.
I would track every service's status and risks on one page reviewed weekly, and add a review checklist item and the cluster test to builds so new incompatible code is not written during the migration.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Redis documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How do you plan the migration so each service is proven compatible before it switches...": https://scrivio-interview-library.netlify.app/databases/redis-scaling/a45e9eeb97/