Devii · Backend · 2026-04-30 · 8 min read
Redis Caching Patterns: TTLs, Eviction, And Stampede Control
In-memory data structures as a cache layer: what Redis guarantees, what it does not, and how to avoid thundering herds.
**Redis** is an in-memory data structure server (strings, hashes, lists, sets, sorted sets, streams, and more). Used as a **cache**, it trades durability for speed. Official docs at `redis.io` document persistence options (RDB snapshots, AOF) if you need recovery, but many cache tiers treat Redis as rebuildable.
Set **TTL** (expire) on keys to bound staleness. Choose eviction policies (`maxmemory-policy`) before production traffic: `allkeys-lru` is common for pure caches. Monitor memory usage and hit rate.
A **cache stampede** happens when many requests miss together and hammer the origin. Mitigations: probabilistic early expiration, request coalescing (single-flight), and stale-while-revalidate semantics at the application layer.
Redis is not a relational database. Do not store authoritative financial balances solely in Redis without a durable system of record. Use it where speed and explicit TTL semantics help.