Hasty Briefsbeta

Bilingual

Why didn't anybody tell me about Redis hash slots?

2 days ago
  • The service matches couriers to deliveries and relies on a routing engine for distance estimates, which is the primary source of latency.
  • Caching is critical because route estimates are repetitive, but raw coordinate caching fails; H3 hexagons are used for deduplication.
  • Redis cluster uses 16,384 hash slots; multi-key commands like MSET/MGET only work if all keys land in the same slot, causing performance issues.
  • The fix uses hash tags (curly braces) to force keys into the same slot, discovered by brute force searching for a suitable tag.
  • Further optimizations included sorting keys before fan-out to avoid overloading nodes, using EVAL scripts for expiry with MSET, and switching from JSON to CSV to save CPU.
  • The author learned to build benchmarking harnesses first, following Rob Pike's rules about measuring and avoiding premature optimization.