Backend Developer interview question

When would you add a cache?

Cache data that is expensive to compute and tolerates bounded staleness. Define the source of truth, key, TTL, invalidation path, and behaviour when the cache is empty or unavailable.

Direct answer

What a strong answer covers

How it works

A cache pays off when the same result is read far more often than it changes and a slightly stale answer is acceptable. Before adding one, name the source of truth, the key that identifies a result, how long staleness is tolerable, how invalidation happens on write, and what the service does on a miss or when the cache is down. Without those answers a cache turns a slow system into a wrong one. Often the better first step is fixing the query or adding an index.

Example

Cache a product catalogue with a TTL and invalidate on publication; do not cache a balance without an explicit consistency rule. A catalogue page cached for five minutes in Redis and refreshed on the publish event cut database load by 90 percent, while account balances stayed on the primary because a customer seeing a stale balance is a support ticket.

Common mistakes

  • Caching before profiling and hiding a missing index behind a Redis dependency.
  • Using a TTL as the only invalidation and accepting silently wrong data after writes.
  • Letting a cache outage take the service down instead of degrading to the source of truth.

A useful answer structure

Answer from your own work.

Do not memorise a script: use only examples you can explain honestly in follow-up questions.

Practise this answer with MiraHint

Open the desktop workspace and rehearse a clear answer in your own words.

Download MiraHint
Backend Developer interview questions