Redis Interview Questions

Valkey Migration and Compatibility

questions
Scroll to track progress

Your Redis 7.0 infrastructure has custom Lua scripts that use redis.call() extensively. Valkey (Redis fork) claims compatibility but also introduces new Lua features. During migration from Redis to Valkey, some scripts behave differently. You need to understand compatibility and prevent breakage. What's your migration strategy?

Valkey aims backward-compatibility with Redis but is a fork with diverging features. Potential incompatibilities: (1) Lua script behavior: Valkey might optimize redis.call() differently, causing different results or error handling. (2) command differences: some commands might behave slightly differently (e.g., return values, error messages). (3) data persistence: Valkey RDB format might differ, causing restore issues. (4) replication protocol: if mixing Redis and Valkey instances, replication might fail. Migration strategy: (1) test compatibility: (a) run your existing Lua scripts on Valkey in staging. Compare output with Redis. (b) use redis-cli --eval script.lua to run scripts on both versions. Diff results. (2) code audit: review all Lua scripts for redis.call() usage. Identify potential incompatibilities. Valkey docs list breaking changes. (3) gradual migration: don't switch all at once. (a) Deploy Valkey replica alongside Redis. (b) Redirect read-only traffic to Valkey replica. Monitor for discrepancies. (c) Gradually migrate workloads. (4) version your scripts: add version suffix to script names. Old scripts use Redis version, new scripts use Valkey version. Support both during transition. (5) point-in-time testing: periodically export data from Redis, import to Valkey, run workload, compare results. For your scenario: (1) audit Lua scripts: grep -r "redis.call" . to find all usages. (2) test each script on both Redis and Valkey: write integration test that runs script on both and compares output. (3) identify breaking changes: check Valkey release notes for Lua changes. (4) refactor if needed: if script is incompatible, rewrite or use CONFIG on Valkey to enable compatibility mode (if available). (5) migrate gradually: deploy Valkey alongside Redis. Use LB to route traffic. Switch percentage by percentage. Prevention: (1) implement CI/CD testing: test scripts on both Redis and Valkey before merging. (2) maintain compatibility layer: if breaking change, wrap in compatibility shim. (3) monitor divergence: periodically run same workload on both, compare results. Alert if divergence.

Follow-up: If a Lua script is incompatible with Valkey, is there a way to maintain compatibility without rewriting?

You plan to migrate from Redis Cluster (7 nodes) to Valkey Cluster (7 nodes) in the same data center. You want zero-downtime migration. Your app connects to Redis Cluster via redis-py with cluster support. After switching to Valkey, would the same client library work?

Redis and Valkey use the same cluster protocol and commands, so redis-py cluster client should work with Valkey Cluster with minimal changes. However, there might be subtle differences. Zero-downtime migration strategy: (1) parallel deployment: deploy Valkey Cluster alongside Redis Cluster. (2) dual-write: app writes to both clusters simultaneously for N hours. (3) verify consistency: compare DBSIZE, KEYS patterns on both. (4) gradual cutover: slowly shift read traffic to Valkey (10%, then 50%, then 100%). Monitor for errors. (5) full switchover: once reads are 100% on Valkey and consistent, switch writes. (6) decommission Redis: after stabilization, shut down Redis Cluster. Implementation: (1) deploy Valkey Cluster: CLUSTER NODES to verify topology matches Redis. (2) sync data: use redis-cli --rdb to snapshot Redis, restore to Valkey. Alternatively, use SCAN + RESTORE. (3) dual-write middleware: in app, add logic: for each command, execute on both clusters. Log divergence if any. (4) test client compatibility: redis-py CLUSTER SLOTS should work with Valkey. If not, use compatibility wrapper. (5) verify cluster health: CLUSTER INFO on both. Should show cluster_state:ok. (6) gradual switchover: use feature flag or LB to route percentage. Monitor error rates on Valkey cluster. If >0.1% errors, investigate before proceeding. For testing: (1) create staging environment with 1 node of each (Redis, Valkey). (2) run redis-benchmark against both. Compare throughput/latency. (3) stress test: run real production workload on Valkey cluster for 24 hours, monitor stability. (4) verify client library: redis-py version compatibility with Valkey. Check community reports.

Follow-up: If Valkey cluster has different slot assignment than Redis cluster, what happens during migration?

Your Redis deployment uses Redis Enterprise modules (e.g., RedisJSON, RedisSearch). You want to migrate to open-source Valkey, but Valkey doesn't have the same module ecosystem. Some critical features (search, JSON manipulation) won't be available. How do you handle this gap?

Redis Enterprise modules provide extended functionality. Valkey doesn't include them (Valkey is open-source). This is a significant gap if your workload depends on modules. Options: (1) stay with Redis Enterprise: if modules are critical, migration to Valkey might not be feasible. Evaluate cost vs benefit. (2) implement module functionality in application: move JSON parsing and search logic to app layer (Python, Go). Slower than Redis modules but feasible. (3) use Valkey-compatible third-party modules: Valkey community might port Redis modules. Check GitHub/Valkey community. (4) use separate search system: for search functionality, don't rely on RedisSearch. Use Elasticsearch alongside Redis/Valkey. For JSON, parse in app. (5) evaluate Valkey premium modules: if available, Valkey might offer commercial modules similar to Redis Enterprise. (6) use Redis Modules that are open-source compatible: some modules (RediGraph, RedisBloom) are open-source. Valkey might support them. For critical features relying on modules: (1) audit which modules you depend on: grep .lua scripts for module commands (e.g., JSON.GET, FT.SEARCH). (2) evaluate alternative implementations: for search, could you use Elasticsearch? For JSON, could you parse in Python? (3) performance comparison: measure performance of app-side parsing vs. module-side. If delta < 2x, app-side is acceptable. (4) cost-benefit analysis: is migrating worth the functionality loss? Valkey license might save costs, but module loss might add operational complexity. (5) hybrid approach: keep Redis for modules (search, JSON), use Valkey for cache/queues. Split data based on use case. Prevention: (1) avoid vendor lock-in: use modules sparingly. If possible, implement module functionality in app layer (more portable). (2) monitor Valkey ecosystem: Valkey community might develop module equivalents. Check periodically. (3) contribute: if module is needed, consider contributing to Valkey community (add module support).

Follow-up: If you migrate from Redis to Valkey and later need to migrate back to Redis, how would you minimize effort?

Your Redis persistent setup uses CONFIG GET save to checkpoint every 1 hour (BGSAVE). You migrate to Valkey with same config. After migration, you notice RDB files from Valkey are 20% larger than Redis RDB files for same dataset. Compression might be different, or Valkey encodes data differently. Does this affect backup/restore compatibility?

RDB format differences between Redis and Valkey could cause restore issues. 20% size difference suggests: (1) different compression algorithms: Redis uses zlib, Valkey might use different. (2) different data encoding: Valkey might encode integers, strings differently, affecting size. (3) metadata differences: Valkey might include additional metadata, increasing size. Compatibility concerns: (1) Redis RDB restore on Valkey: might work if Valkey's RDB parser is compatible. But 20% larger Valkey RDB might not restore on Redis. (2) cross-migration: if you need to restore Valkey RDB on Redis, test it first. To verify compatibility: (1) create RDB on Redis, restore on Valkey. Check DBSIZE and sample keys match. (2) create RDB on Valkey, restore on Redis. Check compatibility. (3) test with real dataset: export prod Redis RDB, restore on Valkey, verify data integrity. Prevention: (1) don't assume RDB compatibility: always test cross-version restore before using in production. (2) use AOF if portability is critical: AOF format is command-based (human-readable), more portable than RDB. Both Redis and Valkey should support AOF. (3) standard Redis vs Valkey: clarify in deployment docs which version you're using. Don't mix RDB files without testing. (4) version RDB files: add metadata (version, source system) to RDB naming: redis-7-0-dump.rdb vs valkey-1-0-dump.rdb. Prevention: For your scenario: (1) test RDB compatibility: take Redis RDB, restore on Valkey cluster. Verify DBSIZE and data. (2) if incompatible, use logical backup: SCAN all keys from Redis, dump values, import to Valkey using RESTORE. Slower but reliable. (3) test restore procedure: document steps, test in staging with production-like data. (4) monitor file size: if Valkey RDB is consistently larger, ensure backup storage has capacity.

Follow-up: If you need to migrate data from Redis to Valkey without downtime, what's the best method?

Want to go deeper?