Interview › Databases & Caching
What happens when Redis reaches maxmemory?
Databases & Caching · Advanced level
Answer
When Redis reaches maxmemory, it either evicts eligible keys based on policy or rejects memory-growing writes if no key can be evicted. Reads may still work, but latency and miss rate can degrade quickly.
Technical explanation
LRU approximates least recently used; LFU approximates least frequently used; volatile policies protect non-TTL keys but can fail writes if no TTL keys are eligible.
TTL jitter prevents synchronized expiry and thundering herds.
Memory alerts must fire before maxmemory to avoid eviction storms or write failures.
Hands-on example
Policy example for pure cache:
maxmemory-policy allkeys-lfu
SETEX product:v2:123 642 <json>
642 seconds = 600 base + random jitter.
Incident checks:
INFO memory
INFO stats
CONFIG GET maxmemory-policyWatch evicted_keys, keyspace_hits, keyspace_misses, app cache errors, and RDS fallback load.
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More Databases & Caching interview questions
- What is the difference between Redis persistence options RDB and AOF?
- What is Redis replication, and how does a replica stay in sync?
- What is Redis Cluster, and how does sharding with hash slots work?
- What is the difference between Redis Sentinel and Redis Cluster?
- How does ElastiCache provide high availability and automatic failover?
- What is a cache hit ratio, and how do you improve it?
- Why are some Redis commands (KEYS, FLUSHALL) dangerous in production?
- What is the difference between Redis as a cache and Redis as a primary datastore?