categories.system-design Intermediate
Distributed Cache Design: Redis's Role in System Architecture
Distributed Cache Design
Cache Layer Positions
- CDN: Static assets (images, JS/CSS)
- Application-level cache: In-process LRU cache; fastest but not shared
- Distributed cache: Redis / Memcached; shared across services
- Database query cache: Result-set cache at the DB layer
Redis Data Structures and Use Cases
| Structure | Use Cases |
|---|---|
| String | Session storage, counters, distributed locks |
| Hash | User profiles, product details |
| List | Message queues (LPUSH/BRPOP), activity feeds |
| Set | Tags, deduplication, mutual friends |
| Sorted Set | Leaderboards, delayed queues |
Three Cache Problems
Cache Penetration Querying non-existent keys always hits the DB Fix: Bloom filter to pre-filter / cache null values
Cache Breakdown A hot key expires; massive requests hit DB simultaneously Fix: Mutex lock / logical expiration (no TTL; async refresh)
Cache Avalanche Many keys expire at the same time Fix: Add random TTL jitter / multi-level caching
Interview bonus: Redis Pub/Sub vs Streams—Streams are persistent, support consumer groups and message replay, making them a lightweight Kafka alternative.
✦ AI Mock Interview
Type your answer and get instant AI feedback
Sign in to use AI scoring
