0% found this document useful (0 votes)
2 views6 pages

Redis Cache

The document outlines various caching problems and solutions related to Redis, including cache penetration, stampede, consistency, serialization issues, and hot key problems. It provides expected answers and follow-up questions for each scenario, emphasizing best practices in caching architecture and troubleshooting in production environments. The content is aimed at distinguishing candidates with practical experience in designing and operating Redis-based caching systems from those with only basic usage knowledge.

Uploaded by

ammulu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Redis Cache

The document outlines various caching problems and solutions related to Redis, including cache penetration, stampede, consistency, serialization issues, and hot key problems. It provides expected answers and follow-up questions for each scenario, emphasizing best practices in caching architecture and troubleshooting in production environments. The content is aimed at distinguishing candidates with practical experience in designing and operating Redis-based caching systems from those with only basic usage knowledge.

Uploaded by

ammulu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Cache Penetration
Question
Your application receives millions of requests for invalid product IDs that do not exist in the
database.
How would you prevent these requests from continuously hitting the database despite Redis
caching?
Follow-up
How would you implement it in Spring Boot?
Expected Answer
 Cache null values with shorter TTL
 Use Bloom Filters
 Redis lookup before DB hit
 Prevent repeated DB calls for non-existing records
Killer Follow-up
What happens if you cache null values for too long?

2. Cache Stampede
Question
A cache entry expires at midnight.
Suddenly 100,000 requests arrive.
All requests miss cache and hit database.
How do you solve this?
Expected Answer
 Distributed locking
 Cache warming
 Randomized TTL
 Request coalescing
Follow-up
How would you implement distributed lock using Redis?
Expected:
 SETNX
 Redisson Lock
 Lock expiration handling

3. Cache Consistency
Question
User updates profile.
Profile data exists in Redis cache.
How do you keep cache and database consistent?
Expected Answer
Patterns:
 Cache Aside
 Write Through
 Write Behind
 Write Around
Killer Follow-up
Suppose DB update succeeds but Redis eviction fails.
What happens?
How would you recover?

4. Spring Cache Internals


Question
You are using:
@Cacheable("users")
public User getUser(Long id)
Explain step-by-step what happens internally.
Expected Answer
 Spring AOP intercepts method
 Cache key generation
 Redis lookup
 Cache miss invokes method
 Result stored in Redis
 Subsequent requests served from cache
Follow-up
Will @Cacheable work if method calls another method in same class?
Expected:
No.
Self-invocation bypasses proxy.

5. Serialization Problem
Question
Application version V1 stores User object.
Version V2 introduces new fields.
Now Redis contains older serialized objects.
What issues can occur?
Expected Answer
 Deserialization failures
 Class version mismatch
 Missing fields
 Backward compatibility concerns
Follow-up
How would you handle rolling deployments?

6. Distributed System Cache Problem


Question
You have:
 10 application pods
 Shared Redis Cluster
One pod updates cache.
How do other pods become aware?
Expected Answer
Since Redis is centralized, all pods see updated data.
Killer Follow-up
What if pods maintain local in-memory cache (Caffeine) in front of Redis?
Expected:
Need cache invalidation events.
 Redis Pub/Sub
 Message queues
 Event-driven invalidation

7. Hot Key Problem


Question
One product receives 500K requests/minute.
Single Redis key becomes hotspot.
How would you solve it?
Expected Answer
 Key sharding
 Local cache
 Replicas
 CDN
 Request throttling
Follow-up
How would you identify hot keys in production?

8. Redis Cluster Design


Question
Why did you choose Redis Cluster instead of standalone Redis?
Expected Answer
 Horizontal scaling
 High availability
 Automatic sharding
 Failover
Follow-up
How many hash slots exist in Redis Cluster?
Expected:
16,384 slots.

9. Memory Leak Investigation


Scenario
Redis memory keeps increasing.
No increase in traffic.
Question
How would you investigate?
Expected Answer
 Check TTLs
 Identify non-expiring keys
 Analyze key patterns
 MEMORY USAGE
 INFO memory
 Big key analysis
Architect Follow-up
What monitoring dashboards would you build?

10. Redis Failover Scenario


Question
Redis becomes unavailable for 10 minutes.
What happens to your application?
Weak Answer
Application fails.
Strong Answer
 Graceful degradation
 Fallback to database
 Circuit breaker
 Retry policies
 Rate limiting
 Alerting
Killer Follow-up
How do you prevent database collapse when Redis is down?

11. Multi-Level Cache Design


Question
Design a caching architecture for:
 50 million users
 <50 ms response time
 Global traffic
Expected Discussion
 Browser Cache
 CDN
 API Gateway Cache
 Caffeine Local Cache
 Redis Distributed Cache
 Database
Architect Signal
Candidate should discuss cache hierarchy and invalidation strategy, not just Redis.

12. Real Production Issue


Question
You deployed a new version.
Suddenly response time increased from 50 ms to 2 seconds.
Database CPU jumped to 95%.
Redis CPU is normal.
What could have happened?
Expected Investigation
 Cache disabled accidentally
 Cache key changed
 Serialization issue
 Wrong TTL
 Cache miss storm
 Cache eviction issue
Strong Architect Answer
Would discuss:
 Metrics
 Hit ratio
 Cache miss trends
 Distributed tracing
 Rollback strategy
 Production debugging approach
These questions are excellent for distinguishing someone who has merely used Redis from
someone who has designed, operated, and troubleshot Redis-based caching systems in
production.

You might also like