All jobs / Backend developer / Performance
Backend developer interview question · 1–3 years
The interviewer asks: “You add Cache-Control to a JSON API. What do you watch for?” Strongest answer?
The strongest answer
Authenticated or user-specific responses get private (or no-store). public + a CDN will leak another user's body. I set a max-age I can live with, and I use ETags when I need revalidation.
Why it works
Exactly. Shared caches are the danger. private / no-store for personal data; public only for truly public, versioned representations.
What a good answer covers
- User-specific → private or no-store.
- public only for truly public data.
- ETag/max-age with a plan to invalidate.
- Never CDN-cache another user's JSON.
Answers that fall short
- Close, but not the strongest: Cache-Control: public, max-age=31536000 on everything for speed.
A year of public cache on /me is a privacy incident. Aggressive caching is for immutable assets, not user JSON. - Weak: I don't set headers — browsers shouldn't cache APIs.
Intermediaries cache anyway. Explicit headers are how you stop them. “Shouldn't” is not a header. - Red flag: I cache Authorization-bearing responses at the CDN to save origin.
Caching by URL while the cookie/token differs is the classic cross-user leak. Vary and private exist for this.
Who gets asked this
More Performance questions
- The interviewer asks: “Why is OFFSET 100000 slow even with a LIMIT 20?” Strongest answer?
- The interviewer asks: “Where do you enforce rate limits?” Strongest answer?
- The interviewer asks: “This query is slow in production but fine on your laptop. What do you do first?”…
- An endpoint takes 1.5 seconds at p95. The container’s CPU sits at 8% and the CPU profiler shows almost…
- The interviewer asks: “The cache expires and 2,000 requests hit the database at once. How do you prevent…
- Under load, someone raises the connection pool from 20 to 200 per instance. Throughput drops and p95 gets…
- The interviewer asks: “How do you know we can take 3× traffic on Monday?” Strongest answer?
- The interviewer asks: “The bill doubled but QPS didn't. Where do you look?” Strongest answer?