Architectural Breakdown & AnalysisFAANG Aligned
When cache memory is exhausted, an eviction policy decides which keys to remove to free space for new entries.
1. Least Recently Used (LRU)
Evicts keys that haven't been read or written to for the longest time.
- Pros: Simple, effective for temporal access patterns.
- Cons: A one-time sequential scan can evict hot keys from cache memory.
2. Least Frequently Used (LFU)
Evicts keys with the lowest total access frequency counter.
- Pros: Keeps frequently accessed keys cached regardless of recent access gaps.
- Cons: Historical hot keys remain cached even after their popularity fades.
3. Adaptive Replacement Cache (ARC)
Dynamically tunes balance between LRU and LFU using ghost lists.
- Pros: Outperforms LRU and LFU across mixed workloads.
- Cons: Higher memory overhead and patent licensing constraints.
TIP — Redis Default
Use allkeys-lru or allkeys-lfu in Redis based on whether key recency or frequency drives your workload.
Key Architectural Comparison
| Eviction Policy | Eviction Criteria | Memory Overhead | Cache Hit Ratio Pattern | Ideal Workload |
|---|---|---|---|---|
| LRU (Least Recently Used) | Evicts key with oldest access timestamp. | Doubly linked list pointers. | High for recency-skewed traffic. | General-purpose web caches. |
| LFU (Least Frequently Used) | Evicts key with lowest access counter. | Frequency bucket counters. | High for stable popular items. | E-commerce product catalogs. |
| ARC (Adaptive Replacement) | Dynamically balances between LRU and LFU. | High (tracks ghost lists of evicted keys). | Consistently superior hit rates. | ZFS storage, high-end database caches. |