Technology

Redis

An in-memory store for cache, queues, sessions and counters: low latency and well-thought-out invalidation.

About the technology

I have used Redis for eight years as a universal tool for everything that requires sub-millisecond latency: caching, queues, sessions, counters, request-rate limiting and distributed locks. The main value of Redis is storing data in RAM with a rich set of structures: strings, hashes, lists, sets, sorted sets, bitmaps, HyperLogLog and streams. Choosing the right structure for the task determines both performance and code convenience. For caching I build a thought-out invalidation strategy: I use meaningful keys and namespaces, tags for group invalidation, reasonable TTLs and protection against the cache stampede through locks and early refresh. I clearly understand the difference between the cache-aside, write-through and write-behind patterns and choose the approach based on data-consistency requirements. I use sorted sets for leaderboards, deferred tasks and time windows, and Redis streams for reliable event processing with consumer groups and delivery acknowledgment. For rate limiting I implement sliding-window and token-bucket algorithms with atomicity via Lua scripts, which eliminates races under high concurrency. I build distributed locks carefully, accounting for time-to-live and ownership tokens, understanding the limitations and risks of the approach. On reliability, I distinguish the RDB and AOF persistence modes, tune them to the acceptable data-loss window, use replication and Redis Sentinel for fault tolerance, and Redis Cluster for horizontal sharding at large volumes. Separately I watch operational metrics: memory consumption, eviction policy, fragmentation, slow commands via SLOWLOG. An important principle: Redis is an accelerator, not the single source of truth, so I design the system so that its correctness is not broken when the cache is flushed. Paired with Laravel and Go, Redis handles queues, cache and sessions, dramatically reducing the load on the main database and keeping the system response stable under peak traffic.

Experience

8 years in production

Projects using this technology

Articles