Why didn't anybody tell me about Redis hash slots?
An engineer at a delivery app explains how they fixed high Redis cluster latencies by leveraging Redis hash tags, Lua scripts, and CSV serialization.
read it It offers a practical, detailed post-mortem on troubleshooting Redis cluster hash slot constraints and serialization overhead at scale.
summary
A delivery app engineer noticed high read latencies when trying to cache route estimates in a Redis cluster using multi-key commands. Because Redis distributes 16,384 hash slots randomly, keys with distinct coordinates landed across different nodes, breaking batching efficiency. By using Redis hash tags with pre-computed integer suffixes, they forced related keys into the same slots. Additional optimizations included using Lua scripts for atomic expiry handling and swapping JSON for CSV payloads to reduce CPU overhead.
key points
- Multi-key Redis commands like MGET and MSET fail unless all keys map to the exact same hash slot based on CRC16 modulo 16,384.
- Redis hash tags using curly braces allow developers to isolate the hashing key portion, forcing related keys into specific slots for batching.
- Using Lua scripts via EVAL provides an atomic way to set keys with expirations when multi-key batch commands lack native expiry arguments.
- Serializing small payloads as CSV instead of JSON significantly reduced CPU usage under high-throughput workloads.
who should read it
Backend and infrastructure engineers working with distributed Redis clusters.
discussion skeptical
consensus
Commenters are heavily distracted by the stylistic tone, with several arguing that the post sounds AI-generated.
pushback
A few readers express confusion over how the author's custom hashing scheme allows subsequent requests to reliably locate cached data.
Wish this was clarified. One thought would be to choose a stable component to in turn hash, such as the source coordinate hexagon, but then why not just put that in the hashtag
It zeroes in on a missing architectural detail regarding how stable components are chosen to retrieve the hashed keys.
Generated by an LLM from the article and thread. Check the sources before relying on it.