Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Your API platform serves 2 billion GET requests per day, mostly for data that changes rarely, and the database and egress costs are a top-five infrastructure cost. How would you lead a company-wide HTTP caching strategy?

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.

Example: the endpoints that dominate cost
EndpointRequests per dayData changesCurrent hit ratio
GET /catalog/products/{id}620 milliona few times per day per product8 percent
GET /config/app410 millionweekly0 percent
GET /stores180 millionmonthly35 percent
GET /prices/{id}260 millionhourly0 percent
GET /me/profile150 millionrarely, per user0 percent (private)
Five endpoints carry about 80 percent of the traffic; the long tail can wait.

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.

Caching classes in the API guidelines
ClassExampleHeaders
Public, slow-changingconfig, storespublic, max-age=300, stale-while-revalidate, ETag
Public, event-drivencatalog, pricespublic, s-maxage=3600 at CDN, purge on change, ETag
Privateprofile, ordersprivate, no-cache, ETag for 304s
Never cachedpayments, tokensno-store
Each class has one rule set, implemented once in the shared libraries.

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.

Step throughRolling out the caching programme
  1. Measure cost per endpointhit ratio, change rate, egress, database
  2. Pick the top endpointsabout 80 percent of the cost
  3. Assign a cache classpublic, event-driven, private, no-store
  4. Ship headers via shared librariesprivate by default
  5. Add CDN rules and purge eventswith request coalescing
  6. 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.

What to say in the interviewAbout 90 seconds aloud

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/