Sharding, replication, failover, and how the client tracks topology
| Key | Slot | Shard | Value |
|---|
Redis stores data in RAM, so reads and writes are extremely fast (microseconds). Each Redis instance executes commands on a single thread, which means commands are atomic by default — no locks needed. Newer versions (6+) have I/O threads for network handling, but command logic is still serialized.
Each key is mapped to one of 16384 slots using CRC16(key) mod 16384. Slots are divided across master shards. To force two keys onto the same shard, wrap the common part in {} — Redis will only hash the part inside the braces.
Example: {user:42}:profile and {user:42}:cart hash user:42 only, so both land on the same slot/shard. This lets you use multi-key commands (MGET, transactions, Lua) across them.
Each master can have N replicas. Writes go to the master, then are streamed asynchronously to replicas. This means replicas may lag — on master failure, the promoted replica might miss the most recent writes (data loss window).
Redis supports WAIT numreplicas timeout for stronger guarantees, but it's not synchronous by default for performance reasons.
Cluster nodes constantly gossip with each other via PING/PONG. If a node misses replies for cluster-node-timeout, others mark it as PFAIL (possibly failed). Once a majority of masters agree, it becomes FAIL.
The dead master's replicas request votes from surviving masters. The replica with the most up-to-date replication offset wins, runs REPLICAOF NO ONE, claims the slots, and gossips its new role.
You need a majority of masters alive — that's why production clusters use 3+ masters across failure domains.
ASKING prefix, but does NOT update its permanent slot map.Pair this with enablePeriodicRefresh and enableAllAdaptiveRefreshTriggers for production-grade resilience.
fsync policy (always / everysec / no).noeviction — reject writes (default)allkeys-lru / allkeys-lfu — evict any key by recency / frequencyvolatile-lru / volatile-ttl — only evict keys with TTL setallkeys-random, volatile-random — random evictionRedis supports strings, lists, sets, hashes, sorted sets, streams, bitmaps, hyperloglogs, and geospatial indexes. Atomic ops via MULTI/EXEC, Lua scripts, and FUNCTION.
On the CAP triangle, Redis Cluster favors AP — it stays available during partitions but async replication means writes can be lost on failover. For stronger consistency, consider WAIT or external coordination (e.g., RedLock).