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.

  1. Most asked How do you design good cache keys?

    Keys should be deterministic, namespaced, versioned and include every input that changes the result (tenant, locale, user/role when personalized, query parameters), while staying reasonably short.

  2. How do you invalidate caches when many services and scripts write to the same tables?

    Drive invalidation from the database's change stream (CDC such as Debezium, or a transactional outbox/trigger) and let each cache owner consume it — the approach Facebook's mcsqueal daemons used for…

  3. How do you choose a TTL?

    Base it on how quickly the data changes, how much staleness the business tolerates, the cost of recomputation and the hit rate you need. Shorter TTLs are fresher but cause more misses; add jitter to…

  4. What should you consider when serializing objects into a cache?

    Choose a compact, versioned, language-neutral format (JSON, MessagePack, Protobuf) rather than language-specific serialization like pickle or PHP serialize, which can break across deploys and be…

  5. How do you invalidate content on a CDN?

    Use versioned (fingerprinted) URLs for static assets so new deploys don't need invalidation; for dynamic content use short TTLs, stale-while-revalidate, and targeted purges by URL or surrogate…

  6. How would you cache high-frequency counters (views, likes) efficiently?

    Increment counters atomically in Redis (INCR, HINCRBY) and periodically flush aggregated deltas to the database in batches (write-behind), accepting a small risk of losing recent increments if Redis…

  7. How do you implement a distributed lock with Redis, and what are the caveats?

    Acquire with SET lock:key <unique-token> NX PX <ttl> and release only if the token matches (via a Lua script). Caveats: locks can expire while work continues (GC pauses), Redis failover can lose…

  8. What metrics tell you a cache is healthy?

    Hit ratio per keyspace (not just overall), cache latency, errors, evictions and memory, database load from misses, invalidation pipeline lag, and staleness probes for critical data.

Was this page helpful?

Report a mistake