All jobs / Full-stack developer / System Design Basics
Full-stack developer interview question · 5+ years
Someone enabled the CDN in front of the API and `/api/me` started looking very fast.
How do you cache a page that depends on the user?
The strongest answer
`Cache-Control: private` (or no-store) for personalised HTML/JSON, and if you cache at the edge, key on a signed cache identity — never cache `Authorization` or cookie-varying responses as `public` without Vary you actually honour
Why it works
Exactly. Caching personalised JSON at the edge is how Alice sees Bob's invoice. Private/no-store is the default; shared cache needs an explicit, tested key.
What a good answer covers
- Personalised → private or no-store.
- Shared cache only with a proven vary key.
- Never public-cache cookie responses by accident.
- `Vary: *` is not a strategy.
Answers that fall short
- Close, but not the strongest: `public, max-age=86400` on `/api/me` so it is fast
A day-long public `/me` is a cross-user leak with great TTFB. - Weak: One cached HTML for everyone; the client will swap the name
One HTML plus client swap is the logged-out flicker and a cache of the wrong CTA. - Red flag: Vary: * so the CDN will 'do the right thing'
`Vary: *` usually means 'please do not cache'. It is not a clever key.