QA
Beginner LevelSystem Design & Architecture

Why is Cache Invalidation considered one of the hardest problems in computer science?

❓ Interview Prompt: Explain Cache Invalidation, stale data reads, Event-Driven Cache Eviction, Time-to-Live (TTL), and synchronization challenges.

Phil Karlton famously noted: "There are only two hard things in Computer Science: cache invalidation and naming things."

Why Cache Invalidation is Difficult:

When data mutates in the primary database, all distributed cache copies must be updated or evicted immediately. If invalidation fails or experiences network lag, clients receive stale data.

β€’
Mitigations: Set sensible Time-to-Live (TTL) expirations, and execute event-driven cache purges (via CDC or Pub/Sub) on data mutations.

Code Implementation Example

typescript
// Event-Driven Cache Invalidation on User Profile Update
export async function updateUserProfile(userId: string, data: ProfileData) {
  await db.user.update({ where: { id: userId }, data });
  // Immediately invalidate cached profile key!
  await redis.del('user:\${userId}');
}
πŸ’‘Evicting cached entries immediately upon database updates.
🎯 Interview Key Takeaway

Combine TTL expirations with event-driven cache purges to prevent stale data reads.

#System Design#Cache Invalidation#TTL#Caching#Beginner
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)?