Pick the shortest TTL that still moves the needle, then invalidate on write by deleting or overwriting the key in the same path that mutates the row. Key by every input that changes the result, including tenant and a schema version. Add single flight locking so a miss does not stampede the database. Accept explicit staleness where it is harmless, and track hit rate so you know it is working.
Why interviewers ask this
Caching is easy to add and hard to keep correct, so the interviewer wants to see you think about invalidation and key design rather than just naming Redis. They are also checking for the failure modes: stampedes on expiry, keys that leak data across tenants, and caches that silently stop hitting after a deploy. Measuring hit rate shows you would notice when the cache quietly stops helping.
How to structure your answer
- Confirm the endpoint is read heavy and tolerant of some staleness.
- Design the cache key, including tenant and version.
- Explain the invalidation strategy on write.
- Cover stampedes and how you would monitor hit rate.
Example answer
Before adding anything, I check whether the query can just be made fast, because a cache in front of a bad query hides the problem until the cache misses at the worst moment. Assuming it genuinely is read heavy, I go cache aside in Redis. The key includes the tenant id, the actual query parameters, and a version prefix I can bump on deploy so a changed response shape never gets served from old entries. TTL is the safety net rather than the mechanism: I invalidate explicitly on write, in the same code path that updates the row, so the window of staleness is milliseconds in the normal case. The failure mode I plan for is the stampede, where a hot key expires and two hundred requests all miss and hit the database at once, so I use a single flight lock and let the losers wait for the winner. Then I export hit rate as a metric, because a cache that dropped from 95 percent to 10 after a refactor goes unnoticed until the database falls over.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- What would you cache in Redis versus at the CDN?
- How would you handle a cache that goes down entirely?
- When is write through better than cache aside here?
Related full stack developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions