Caching Interview Questions

4 questions developers actually get asked about caching — with clear, practical answers you can use to prepare.

Q1. What is caching and why is it used?

Caching is the technique of storing the result of an expensive operation (a database query, an API call, a rendered page) in fast-access storage so future requests can reuse it instead of redoing the work. It is used to reduce latency, cut load on backend systems, and save money on bandwidth or compute. The tradeoff is that cached data can go stale, so every caching decision is really a freshness-versus-speed decision.

Q2. What is cache invalidation and why is it considered hard?

Cache invalidation is the process of removing or refreshing cached data when the underlying source of truth changes, so users do not see stale values. It is hard because the cache and the database are two separate systems that can drift apart: a write might succeed in the database but the cache update might fail, or the cache might be invalidated correctly on one server but not on another. Most bugs in caching systems trace back to invalidation edge cases, not to the caching logic itself.

Q3. What is the difference between TTL-based and event-based cache invalidation?

TTL-based (time-to-live) invalidation sets an expiry on each cached entry (say 5 minutes) and the cache clears itself when the timer runs out. Event-based invalidation explicitly deletes or updates the cache entry the moment the underlying data changes, usually by hooking into a write handler or a message queue. TTL is simpler but accepts some staleness; event-based is more accurate but adds coupling between your write path and your cache. Many systems combine both: event-based as the main strategy, with a short TTL as a safety net.

Q4. What are the main types of caches (in-memory, Redis, CDN) and when do you use each?

In-memory caching stores data inside the application process itself (e.g. a Python dict or Node Map). It is the fastest option but lives and dies with the process, and does not share across servers. Redis (or Memcached) is a standalone in-memory store that multiple app servers can share, which is what you reach for once you have more than one instance. A CDN (Content Delivery Network) caches responses at edge locations geographically close to the user and is used for static assets and public HTML. A typical stack uses all three: in-memory for hot per-process lookups, Redis for shared application data, CDN for public pages and assets.

Want the full concept, analogies, and AI prompts for caching?

Read the full Caching block →