Describe the different layers where you can cache in a typical full-stack web app, and how you keep cached data correct.
What the interviewer wants to hear
- Browser cache controlled by Cache-Control and ETags
- CDN or edge cache for public pages and static assets
- Framework or server cache, such as Next.js data cache or Redis
- Client-side data cache such as TanStack Query
- Invalidation via TTLs, tags or events on write
- Never share-cache personalized data
Model answer
I think of caching from the outside in. In the browser, Cache-Control and ETags let hashed assets be cached for a year and API responses be revalidated cheaply. A CDN caches static files and public pages close to users, often with stale-while-revalidate so updates appear quickly without slow misses. On the server, Next.js can cache rendered pages and fetched data, and Redis stores expensive query results or sessions using the cache-aside pattern. On the client, a library like TanStack Query caches API data and refetches in the background. To keep data correct, I pick TTLs based on how stale the data may be, and I invalidate on writes using tags, revalidatePath or deleting Redis keys after the database commit. The key rule is that anything personalized is marked private or no-store, so a shared cache never serves one user’s data to another.
Can you answer it under time pressure?
Take a timed medium round and get scored on every answer.
More medium Full Stack Developer questions
- How would you implement login for a web app? Compare server sessions with JWT access tokens and explain what you would choose.
- Users say the orders page is slow. How do you find and fix the problem across frontend, API and database?
- How would you build a feature that lets users upload profile photos and PDF documents up to 100 MB?
- Your API is used by a web app and an older mobile app that users do not update quickly. How do you make a breaking change safely?
- Describe a good CI/CD pipeline for a full stack app. What runs on each pull request and how do you deploy safely?
- You need to build a product search page with text search, filters and sorting. Walk through the design from the UI to the database.
- How would you add role-based access control (admin, editor, viewer) to an existing full-stack app?
- What is your testing strategy for a full-stack feature such as "invite a teammate by email"?
- You need to show in-app notifications in real time. How do you choose between polling, server-sent events and WebSockets, and how would you build it?