Interview Q&A · questions with model answers
Caching Interview Questions
Part of the study plan for: Backend Engineer · Full Stack Engineer
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked Explain the difference between cache penetration, cache breakdown and cache avalanche.
Penetration: requests for data that doesn't exist bypass the cache every time. Breakdown (stampede): one hot key expires and many requests rebuild it at once. Avalanche: many keys (or the whole…
-
Most asked Should you invalidate the cache before or after the database commit?
After. Deleting before commit lets other readers re-cache the old row (they still see it until the commit). Use on-commit hooks or transactional events.
-
Redis vs Memcached: when would you choose each?
Memcached is a simple, multi-threaded, in-memory key-value cache that's great for plain object caching. Redis adds rich data structures (hashes, sets, sorted sets, streams), persistence,…
-
When should you use an in-process (local) cache vs a distributed cache?
In-process caches (LRU maps, Caffeine, functools.lru_cache, APCu) are fastest and need no network, but each instance has its own copy (inconsistent, duplicated memory). Distributed caches (Redis)…
-
When would you use materialized views or denormalization instead of a cache?
When a result is expensive to compute and needs to be queryable (filters, sorting, joins) or durable, precomputing it in the database (materialized views, summary tables, denormalized columns) can…
-
Which metrics show whether a cache is working well?
Hit ratio (overall and per keyspace), latency of cache operations, evictions, memory usage, key count, connection errors and timeouts, and the database load reduction attributable to the cache.
-
What's the difference between memoization and caching?
Memoization caches a pure function's results by its arguments within a process (often a decorator), while caching more broadly stores any expensive data with explicit keys, TTLs and invalidation,…
-
How do you cache GraphQL or highly dynamic API responses?
Cache at the data/resolver level (DataLoader per request, entity caches by ID) rather than whole responses, use persisted queries to make responses cacheable at the CDN for public data, and…
-
Is it OK to store sessions in Redis?
Yes, it's a common pattern: Redis gives fast shared session storage across app instances with TTL-based expiry. Configure persistence/replication appropriately (losing Redis logs users out), secure…
-
Which Redis maxmemory-policy should a pure cache use, and what if sessions share the instance?
A pure cache should use allkeys-lru or allkeys-lfu so cold keys are evicted. If sessions share the instance, allkeys-* can evict sessions; separate them or use volatile-* with TTLs only on cache…