Where caches live: from the browser to the database
A request passes several places that can keep a copy of the answer. Interviewers expect more than "add a cache": which layer, for which data, and how stale it may get.
A timetable in five places
A railway keeps its timetable at head office. Each station's information desk has a printed copy, and each ticket clerk keeps a note of the next few departures. The platform has a poster, and you have a photo of it on your phone. The closer a copy is to you, the quicker it is to read and the harder it is for the railway to correct. Head office can phone every desk within minutes, but a clerk's note gets fixed only if someone tells that clerk. The posters wait for next week's reprint, and the photo on your phone is never corrected at all.
- your photo → the browser or app cache, on the user's device
- the platform poster → the CDN edge, near the user
- each clerk's note → an in-process cache in each app server's memory
- the information desk → a shared cache such as Redis, next to your servers
- head office → the database, which keeps hot pages in its own memory too