Caching Strategies & In-Memory Optimization Questions
Designing cache layers to cut redundant work and speed up reads, and the correctness costs that come with them. Covers cache placement (client/CDN/application/in-memory store), eviction policies, TTLs, write-through vs write-back, warming, and invalidation. Emphasizes hit-rate reasoning and the staleness/consistency trade-offs caching introduces.
Design a write-behind queue system for caching writes to the persistent database. Include architecture for batching, backpressure, idempotence, retry semantics, failure handling, and guarantees (at-least-once vs exactly-once). Explain how you ensure durability of queued writes and how to drain the queue safely during maintenance or failure.
In JavaScript, write a concise Service Worker fetch handler that implements a 'stale-while-revalidate' strategy for images: return cached image if present, kick off a background fetch to update the cache, and on cache miss fetch from network and store in cache. Use async/await, Cache API, and include a cache name constant and a TTL comment.
Given a workload where object access frequencies follow a Zipf distribution (skew), explain how LRU and TTL-based eviction policies will affect steady-state cache hit ratio. Given: 1M unique objects, cache capacity 100k items, Zipf parameter s=0.8. Describe how to approximate hit ratio, and discuss how increasing skew changes tuning decisions.
Design an approach to cache SQL query results for paginated category listings in Redis. Explain key composition (include category, page, sort), how to invalidate entries when product data changes, how to handle partial cache hits for pagination, and trade-offs between query-level caching vs row-level caching or materialized views.
You are building a comment system where new comments must be visible immediately to the author and followers and durability is important. Compare write-through and write-behind caching strategies for this use case and recommend one. Explain trade-offs around latency, durability, complexity, and how to guarantee immediate visibility to readers.
Unlock Full Question Bank
Get access to all 35 Caching Strategies & In-Memory Optimization interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.