ML
Redis

Redis Cluster: Hash Slots, Resharding, and the CROSSSLOT Trap

Cluster scales horizontally, but multi-key commands come with new rules. Hash tags are the escape hatch.

October 15, 20257 min readRedisScaling

Redis Cluster shards the keyspace into 16,384 hash slots. Every key hashes (CRC16 mod 16384) to exactly one slot, and every slot lives on exactly one master. Scaling out is mechanical: move slots between masters.

What clients have to do

A key's owner can change. When it does, the old owner returns MOVED 7000 10.0.0.3:6379. A proper client caches the slot → node map and refreshes on MOVED. The smart client pattern (Lettuce, ioredis cluster) does this for you.

The CROSSSLOT error

Any multi-key command whose keys live in different slots fails:

MSET user:1 a user:2 b
# (error) CROSSSLOT Keys in request don't hash to the same slot

Same rule applies to transactions (MULTI), Lua scripts, and SINTERSTORE. Keys touched in a single command must share a slot.

Hash tags

Put a brace-wrapped piece into the key; Redis hashes only that part. All keys with the same tag land on the same slot.

user:{42}:profile
user:{42}:sessions
MGET user:{42}:profile user:{42}:sessions   # OK, same slot

Design your tags to reflect real co-locations (usually "tenant id" or "user id") — overdoing it recreates hot partitions.

Resharding live

CLUSTER RESHARD or redis-cli --cluster reshard moves slots online. During migration, keys in the moving slot may be in either node — clients handle this via ASK redirects, which are a one-shot version of MOVED. Don't panic if you see a spike of ASK in logs during a reshard — that's the protocol working.

When Cluster is the wrong answer

If you rely heavily on multi-key transactions, SUNION across arbitrary sets, or scripts over global state — sharding breaks those patterns. Sometimes the right move is a bigger single instance, not a cluster.

SharePostLinkedIn

Reader Discussion

8 replies// weighed in

TopNewestAuthor
Add to the thread
Disagree, agree harder, or share your own experience…
Email instead →markdown okbe kind
  1. Highlighted by author
    Elena Ricci· Platform Eng · Booking infraFrom experience

    XFetch quietly killed our daily cache stampede. 6h TTL on a product catalog, three-instance API, used to brown-out for 90 seconds every refresh. Shipped XFetch on a Friday afternoon and forgot it existed. That's the highest praise I can give a fix.

    Oct 17, 2025·2 days later
  2. Amir Shah· InfraAsks

    Q: pre-warm hot keys — internal cron inside the app vs external scheduler (k8s cronjob etc)? We've shipped both. Internal is simpler but you fight clock skew across replicas; external is reliable but adds a moving piece.

    Oct 19, 2025·4 days later
    • ML
      Minh LeAuthor

      External, every time. The number of "why is the warmup not running" tickets I've seen with internal crons is not funny anymore. Make it boring infra.

      Oct 20, 2025
    • Carla Pérez· Backend

      we do external + a redis lock so only one instance actually runs the warmup. simple and observable.

      Oct 21, 2025
  3. Mark Vandermeer· Infra EngineerPushback

    RDB + AOF on the same instance is not a 'belt and suspenders' move btw — fsync-on-rewrite collisions can make latency vibrate. Pick one and tune it.

    Oct 23, 2025·1 week later
  4. Yuki Tanaka· Senior EngineerAgrees

    pipelining is so cheap and so under-used. converted a hot ticker loop from 30k cmd/sec to 30k cmd/sec but in 800 round-trips/sec instead of 30k. p99 dropped 4x. should be the first optimisation people reach for.

    Oct 18, 2025·3 days later
  5. Anya Sokolova· BackendAsks

    any thoughts on Lua vs MULTI/EXEC for the deduct-and-check pattern? been using Lua for 2 years and the script-cache cliff bites us when we redeploy. but MULTI feels chattier

    Oct 21, 2025·6 days later
  6. Rachel Gold· Staff SREAgrees

    the on-call framing throughout this piece is what makes it land. too many infra articles assume you never get paged. those are written by people who never got paged.

    Oct 18, 2025·3 days later

Worked on something similar? Email ducminhldm@gmail.com — I read every one. The good ones become future posts.

Comments seeded · live discussion via email