Quick revision
The short answer
I would lead it as a cost programme driven by data: measure hit ratios, change rates and database and egress cost per endpoint, and target the few endpoints that dominate the bill. Then standardise Cache-Control, ETag and Vary rules per resource class in the API guidelines and shared libraries, use a CDN and shared caches for public data, conditional requests for private data, and event-driven purges where freshness matters, while managing the risks of personalised data leaking through shared caches, stale data and cache stampedes. Savings and correctness incidents are measured and reported, and each part has an owner and funding.
What to remember
In this answer, we led a company-wide HTTP caching strategy as a measured cost programme. We quantified hit ratios, change rates and cost per endpoint to find the few endpoints that dominate, standardised Cache-Control, ETag and Vary rules per resource class in the guidelines and libraries, used CDNs and shared caches for public data, conditional requests for private data and event-driven purges for freshness, and managed the risks of leaking personalised data, stale data and stampedes. Savings and correctness incidents are reported monthly, with owners and funding for each part.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would lead it as a cost programme driven by data: measure hit ratios, change rates and database and egress cost per endpoint, and target the few endpoints that dominate the bill. Then standardise Cache-Control, ETag and Vary rules per resource class in the API guidelines and shared libraries, use a CDN and shared caches for public data, conditional requests for private data, and event-driven purges where freshness matters, while managing the risks of personalised data leaking through shared caches, stale data and cache stampedes. Savings and correctness incidents are measured and reported, and each part has an owner and funding.
Why this question is asked
At 2 billion requests a day, about 23,000 per second on average, small decisions about HTTP headers become millions in infrastructure cost. Most of that traffic asks for data that has not changed since the last time, which means most of the cost is avoidable. Interviewers ask this leadership question to see whether we can turn a technical idea, caching, into a company-wide programme that saves money without causing data leaks or stale prices. In this answer, we will quantify the problem, choose where to start, standardise the rules, pick the right cache layer for each kind of data, manage the risks, and set up measurement and ownership.
1Quantify Before Changing Anything
Leadership starts with numbers, because they decide where effort goes. For every endpoint we gather requests per day, response size, current cache hit ratio (at the CDN and at any application cache), how often the underlying data actually changes, and the cost it drives: database CPU and reads, and egress bytes. Gateway logs and CDN analytics usually provide most of this.
The result is almost always very uneven. A plausible picture: 12 endpoints out of 900 produce 70 percent of the requests and 80 percent of egress, for example product catalogue, prices, store locations, configuration and user profile. That tells us where a few weeks of work saves the most, and it gives a baseline that later savings are measured against.
| Endpoint | Requests per day | Data changes | Current hit ratio |
|---|---|---|---|
| GET /catalog/products/{id} | 620 million | a few times per day per product | 8 percent |
| GET /config/app | 410 million | weekly | 0 percent |
| GET /stores | 180 million | monthly | 35 percent |
| GET /prices/{id} | 260 million | hourly | 0 percent |
| GET /me/profile | 150 million | rarely, per user | 0 percent (private) |
2Standardise the Rules Per Resource Class
If every team chooses its own headers, some will cache nothing and others will cache private data publicly. So the API guidelines define a few resource classes with fixed rules, and the shared libraries for JAX-RS and Spring make them one annotation or one call.
| Class | Example | Headers |
|---|---|---|
| Public, slow-changing | config, stores | public, max-age=300, stale-while-revalidate, ETag |
| Public, event-driven | catalog, prices | public, s-maxage=3600 at CDN, purge on change, ETag |
| Private | profile, orders | private, no-cache, ETag for 304s |
| Never cached | payments, tokens | no-store |
Vary is the header that is easy to forget and dangerous to get wrong. It tells caches which request headers change the response. If a product response depends on Accept-Language, then Vary: Accept-Language makes the cache keep one copy per language; without it, a German user may receive the French copy.
3Choosing the Cache Layer for Each Kind of Data
Public data, the same for everyone, belongs in a CDN and shared caches. A request served at the CDN edge costs no egress from our origin and no database work, so raising the catalogue's hit ratio from 8 to 90 percent removes over 500 million origin requests a day. s-maxage sets the lifetime for shared caches separately from the browser's max-age, so the CDN can keep it longer than browsers do.
Private data cannot go in a shared cache, but it can still be made cheap with conditional requests. The browser or app revalidates with If-None-Match, and the server answers 304 from a version lookup without loading or sending the body, saving most of the egress and much of the database work.
For data that must be fresh when it changes, such as prices, we use long CDN lifetimes plus event-driven purge: when a price changes, the pricing service publishes an event, and a purge worker calls the CDN's API to invalidate that product's URLs or surrogate key. The result is high hit ratios and freshness within seconds, instead of a short TTL that makes everything expire whether it changed or not.
4Managing the Risks
Caching programmes fail through three kinds of incident, and the plan must address each before it rolls out. The first and worst is personalised data leaking through a shared cache: a response that depends on the user is cached publicly and served to someone else. The guard is that the shared libraries default to private, public must be chosen explicitly per resource class, responses to requests carrying Authorization are not cached by shared caches unless explicitly allowed, and a test checks that no endpoint returning user data emits public.
The second is stale data causing wrong decisions, such as an old price at checkout. The rule is that caches serve browsing, and transactional steps such as checkout read from the source of truth. The third is a cache stampede: when a popular entry expires or is purged, thousands of requests miss at once and hit the database together. Request coalescing at the CDN (collapsing simultaneous misses into one origin request), stale-while-revalidate, and staggered TTLs keep the origin safe.
5Measuring Savings and Funding the Work
We report the programme like any cost programme. Every month: origin requests, hit ratio per resource class, egress bytes, database load, and the cost saved against the baseline, alongside correctness incidents, such as stale data reports or any cache-related data exposure, which must be zero. If the catalogue work saves a measured 40 percent of egress, that number funds the next phase.
Ownership is explicit. A platform team owns the guidelines, the shared libraries and the CDN configuration. Each product team owns the cache class of its endpoints and the purge events for its data. The programme has a leader who reports to the infrastructure cost review, and a target, for example cutting database and egress cost for these endpoints by half within two quarters.
- Measure cost per endpointhit ratio, change rate, egress, database
- Pick the top endpointsabout 80 percent of the cost
- Assign a cache classpublic, event-driven, private, no-store
- Ship headers via shared librariesprivate by default
- Add CDN rules and purge eventswith request coalescing
- Measure savings and incidents monthlythen the next set of endpoints
6 steps in order. Play them, or step through them one at a time.
6Follow-up questions
How do you stop a team from accidentally caching private data publicly?
Defaults and tests. The shared library emits private unless the resource is explicitly declared public, the gateway can strip or override public on routes that require authentication, and a contract test calls each authenticated endpoint and fails if the response is cacheable by shared caches.
Why not just add an in-memory cache in each service?
It reduces database load but not egress or request handling, and with many instances each keeps its own copy, so hit ratios are lower and invalidation is harder. HTTP caching at the edge removes the request entirely, so it saves more, and application caches remain useful behind it for data the CDN cannot hold.
How do you handle a purge that fails?
The purge worker retries from a durable queue, and the CDN lifetime acts as an upper bound on staleness. For data where even that bound is too long, we keep the lifetime short enough to be acceptable even if every purge fails.
7Conclusion
In this answer, we led a company-wide HTTP caching strategy as a measured cost programme. We quantified hit ratios, change rates and cost per endpoint to find the few endpoints that dominate, standardised Cache-Control, ETag and Vary rules per resource class in the guidelines and libraries, used CDNs and shared caches for public data, conditional requests for private data and event-driven purges for freshness, and managed the risks of leaking personalised data, stale data and stampedes. Savings and correctness incidents are reported monthly, with owners and funding for each part.
Open with
I would run it as a cost programme, starting with data. First I would measure, per endpoint, requests, response size, hit ratio, how often the data really changes, and the database and egress cost it drives.
Then, if they want more
In my experience a dozen endpoints out of hundreds dominate the bill, things like catalogue, configuration and prices, so that is where we start.
Second, I would standardise: the API guidelines define a few resource classes, public slow-changing, public event-driven, private, and never cached, each with fixed Cache-Control, ETag and Vary rules, and the shared JAX-RS and Spring libraries implement them so teams do not invent headers.
Third, the right layer for each: public data in the CDN with long shared lifetimes, private data with ETags so clients get cheap 304s, and event-driven purges when data like prices changes, so we get high hit ratios and fresh data.
Fourth, risk: the worst failure is personalised data served from a shared cache, so libraries default to private and tests fail any authenticated endpoint that is publicly cacheable; transactional steps like checkout read from the source; and request coalescing and stale-while-revalidate prevent stampedes.
Finally, I report savings against the baseline and correctness incidents every month, with a platform team owning the standards and each product team owning its endpoints.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Jakarta EE specifications
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your API platform serves 2 billion GET requests per day, mostly for data that changes...": https://scrivio-interview-library.netlify.app/java/jax-rs/e2d2b79c51/