Explain TTL vs TTI.
Time to Live (TTL) and Time to Idle (TTI) are cache expiration policies: TTL evicts data after a fixed duration regardless of access, while TTI evicts data only if it remains unused for a defined idle time.
When to use/Use Cases
Use TTL when data must refresh at predictable intervals (e.g., API responses cached for 10 minutes). Use TTI when you want active or “hot” data to remain available while inactive data is automatically removed (e.g., user sessions idle for 30 minutes).
Example
In session management, TTL may enforce a 24-hour maximum login window, while TTI logs a user out after 30 minutes of inactivity.
Want to sharpen your interview prep?
Explore Grokking System Design Fundamentals, Grokking the System Design Interview, Grokking Database Fundamentals for Tech Interviews, or book Mock Interviews with ex-FAANG engineers.
Why Is It Important
Choosing the right strategy impacts cache hit rates, latency, and freshness. TTL ensures updates, while TTI optimizes memory by evicting idle data.
Interview Tips
Explain TTL vs TTI clearly, then give a real-world example (sessions, tokens, or caching API responses). Highlight trade-offs like freshness vs efficiency.
Trade-offs
TTL ensures freshness but may evict frequently used data too soon. TTI improves efficiency but risks serving stale data if “touched” often. Many systems combine both.
Pitfalls
Don’t assume TTL resets on access—it doesn’t. Don’t rely solely on TTI; stale data can survive if frequently accessed. Balance policies carefully.
GET YOUR FREE
Coding Questions Catalog
$197

$78
$78