Full-stack Developer interview question
Where do you cache in a full-stack application?
Cache at the layer that owns freshness: HTTP/CDN for public responses, client caches for server state, and backend caches for expensive shared reads. Define keys, TTL, invalidation, stampede protection, and stale-data tolerance first.
Direct answer
What a strong answer covers
How it works
Each layer caches what it owns the freshness rules for. A CDN or HTTP cache serves public, identical responses such as assets, product pages, and unauthenticated API reads keyed by URL and Vary headers. The browser or a client library caches server state per user with stale-while-revalidate semantics so navigation feels instant. The backend caches expensive shared computations in Redis or in process, with request coalescing so a cache miss under load does not stampede the database. Personal or transactional data is cached only with an explicit invalidation path, and every key includes what makes the result differ.
Example
The product page is cached at the CDN for 60 seconds and purged on publish; the client keeps the cart in a query cache that refetches on focus; the backend caches the computed shipping matrix for ten minutes with a lock so only one worker recomputes it. Account balance is never cached because a stale value creates support tickets.
Common mistakes
- Caching a personalised response at the CDN and serving one user’s data to another.
- Setting a TTL without any invalidation and accepting wrong data after writes.
- Caching in three layers with three different TTLs so nobody can predict when a change appears.
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.
Open the desktop workspace and rehearse a clear answer in your own words.