Diagnosing high Redis eviction and cache misses
practical Redis memory debugging.
use INFO memory and stats to confirm pressure, check fragmentation ratio, pick LFU over LRU for skewed access, set sane TTLs.
just raising maxmemory without finding the cause.
What's really being asked
The interviewer wants a measured diagnostic process for Redis under memory pressure, plus real knowledge of eviction policies and the commands that expose the problem.
The full answer
Start with data. Run INFO memory to read used_memory, maxmemory, and mem_fragmentation_ratio, and INFO stats for evicted_keys and keyspace_hits versus keyspace_misses to quantify the eviction and miss rate. Determine the real cause. If used_memory is near maxmemory, you genuinely have too much data for the budget, so look at value sizes, missing TTLs, and whether you are caching things you should not. If mem_fragmentation_ratio is well above one, the OS has given Redis more memory than it can pack, so consider activedefrag or a restart. Then revisit the eviction policy: allkeys-lru evicts least-recently-used keys and suits recency-driven workloads, while allkeys-lfu evicts least-frequently-used keys and is better when a hot subset is accessed repeatedly but not constantly, since LRU can wrongly evict a popular key after a burst of one-off scans. Use volatile policies only if every cacheable key has a TTL.
The mistakes people make
Just raising maxmemory, which delays the problem and costs money. Ignoring fragmentation and concluding you need more RAM. Leaving keys without TTLs so cold data lingers. Assuming LRU is always correct.
What usually comes next
When would noeviction be appropriate? How do big keys or unbounded data structures cause pressure? How does TTL randomization prevent eviction stampedes?
A concrete example
INFO shows evicted_keys climbing and used_memory pinned at maxmemory while a fragmentation ratio of 1.6 wastes space. A nightly analytics scan touches millions of keys once, and under allkeys-lru it evicts the genuinely hot product keys. Switching to allkeys-lfu and enabling active defragmentation restores hit rate without buying more memory.
Interview question
A nightly batch scans millions of rarely-reused keys, after which your hot keys keep getting evicted under allkeys-lru. Which change most directly fixes this?
- a.Increase maxmemory until evictions stop entirely
- b.Switch to allkeys-lfu so frequently-accessed keys survive one-off scan burstsCorrect
- c.Switch to noeviction so Redis refuses new writes
- d.Disable TTLs so keys are never expired
Why? this is the answer
LRU treats a one-time scan as recent activity and evicts truly hot keys; LFU keys on access frequency, protecting the repeatedly-used set. Raising maxmemory only masks the policy mismatch.
Just read this? Test yourself on what you have been reading.
- #redis
- #caching
- #eviction
- #memory
- #performance
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles