QA
Intermediate LevelSystem Design & Architecture

Compare Cache Eviction Policies: Least Recently Used (LRU) vs Least Frequently Used (LFU) vs ARC.

❓ Interview Prompt: Compare Cache Eviction Policies: LRU (Least Recently Used), LFU (Least Frequently Used), and Adaptive Replacement Cache (ARC).

Evaluating cache memory eviction algorithms:

β€’
LRU (Least Recently Used): Evicts the key that has not been accessed for the longest duration. Implemented via HashMap + Doubly LinkedList in $O(1)$ time.
β€’
LFU (Least Frequently Used): Evicts the key with the lowest total hit frequency count. Useful for long-term hot key caching.
β€’
ARC (Adaptive Replacement Cache): Dynamically tunes balance between LRU and LFU based on recent workload patterns.

Code Implementation Example

typescript
// Doubly LinkedList Node for LRU Cache
class LRUNode {
  constructor(public key: string, public val: any, public prev: LRUNode | null = null, public next: LRUNode | null = null) {}
}
// LRU Cache maintains HashMap for O(1) lookups and Doubly LinkedList for O(1) eviction
πŸ’‘LRU Cache data structure node definition.
🎯 Interview Key Takeaway

Use LRU for general-purpose cache eviction, and LFU when historical frequency indicates long-term item utility.

#System Design#LRU#LFU#Cache Eviction#Intermediate
Back to all System Design & Architecture Questions→

More System Design & Architecture Interview Questions

Beginner LevelSystem Design & Architecture

Explain the CAP Theorem and PACELC Theorem with real-world database examples.

Beginner LevelSystem Design & Architecture

What is Vertical Scaling (Scale Up) vs Horizontal Scaling (Scale Out)?

Beginner LevelSystem Design & Architecture

How do Load Balancers distribute traffic (Round Robin, Least Connections, IP Hash)?