Quick revision
The short answer
I would start with an inventory of every cache layer, recording its owner, purpose, measured hit ratio, staleness bound and what happens when it is empty, and then remove the layers that duplicate each other or add little measured benefit. To change the approach, I would make capacity plans include the cold-cache case, treat caches as copies of data under the same governance as the source, and fund fixing slow queries instead of hiding them behind another cache.
What to remember
In this answer, we saw that many cache layers multiply invalidation work and failure modes, and that unmeasured hit ratios turn caches into hidden dependencies. We build an inventory with owner, purpose, hit ratio, staleness bound and empty-cache behaviour, remove layers that duplicate each other or add little, require capacity plans to cover the cold-cache case, treat caches as copies of data under the same governance, and fund fixing slow queries so that a new cache becomes a deliberate choice.
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 start with an inventory of every cache layer, recording its owner, purpose, measured hit ratio, staleness bound and what happens when it is empty, and then remove the layers that duplicate each other or add little measured benefit. To change the approach, I would make capacity plans include the cold-cache case, treat caches as copies of data under the same governance as the source, and fund fixing slow queries instead of hiding them behind another cache.
Why this question is asked
Caches are easy to add and hard to remove. Each one is added by a different team for a good local reason, and years later nobody can say which ones the system really depends on. When outages start to involve cache behaviour, such as stale data, stampedes after a flush or a database that falls over when a cache restarts, the caches have stopped being optimisations and become hidden parts of the architecture. Interviewers ask this at a senior level to see whether we can turn a pile of local decisions into an explicit, measured design, and change how the organisation decides. In this answer, we will build the inventory, decide which layers to keep, make the cold-cache case part of capacity planning, bring caches under data governance, and change the incentives that keep adding caches.
1Why Many Cache Layers Become a Problem
A cache is a copy of data kept closer to the reader so that reads are cheaper. Every copy brings three costs. It must be invalidated when the source changes, it can be stale for some time, and it can fail or be empty. With five layers (CDN, API gateway, service cache, Hibernate second-level cache and the database's own buffers or query cache), one write may need to reach four copies, and a reader may see any mix of old and new values.
The second problem is hidden load. Suppose the service cache has a 95 percent hit ratio. The database then only sees 5 percent of reads, and over the years it gets sized for that. If the cache is flushed during a deploy, the database suddenly sees 20 times its usual read load. The capacity plan assumed a hit ratio that nobody measures any more, so nobody knows how close to the edge the system really is.
2Building the Inventory
The first step is to make every layer visible. For each cache we record who owns it, why it exists, what it holds, its measured hit ratio, its staleness bound (the longest time a reader may see old data), how it is invalidated, and what happens if it is empty. That last column is the one that matters most, and it usually needs a test rather than an opinion.
| Layer | Hit ratio | Staleness | If empty |
|---|---|---|---|
| CDN for product images | 97% | 1 day | origin gets 30x traffic, survives |
| API gateway response cache | 12% | 60 s | no visible effect |
| Service Redis cache | 92% | 10 min | database CPU at 100%, outage |
| Hibernate L2 cache | 40% | until evicted | small extra load |
| Database buffer cache | 99% | never stale | slow for minutes after restart |
Notice what such a table usually reveals. One layer, here the gateway cache, has a low hit ratio and a staleness window that confuses users, so it adds risk for almost no benefit. Another layer, the service cache, is load-bearing: without it the database falls over. Both facts were invisible before.
3Deciding Which Layers to Keep
With the numbers in hand, the decision is mostly arithmetic. A layer that duplicates another layer with the same data and similar TTL is a candidate for removal, because it doubles invalidation work and adds a failure mode without saving much. A layer with a low measured hit ratio is a candidate too. A layer that is clearly valuable stays, but gets an owner, metrics, alerts and a written staleness bound.
Removing a cache should be done like any risky change: turn it off for a small share of traffic, watch the latency and the load on the layer below, and keep a way back. In practice teams are often surprised that removing a layer makes incidents rarer without making the service slower.
4Making the Cold-Cache Case Part of Capacity Planning
The rule I would introduce is that a capacity plan must show what happens with every cache empty, or with a stated, tested warm-up. If the database cannot survive a cold service cache, then either the database is sized for it, or the cache is treated as critical infrastructure with replication, gradual warm-up after a flush and protection against stampedes. What we cannot keep is a system that only survives because a cache happens to be warm.
The same plan states the hit ratio it assumes, and a dashboard shows the real one, so a drop from 92 to 70 percent becomes an alert long before it becomes an outage.
- Measured benefit is real?YesKeep and give it an ownerNoPlan its removal
- Does the system survive it empty?YesOptimisation: normal monitoringNoLoad-bearing: size or protect it
- Holds personal or regulated data?YesApply source data rulesNoStandard retention
- Record owner, hit ratio, staleness boundreviewed every year
4 steps in order. Play them, or step through them one at a time.
5Caches Are Copies of Data
A cache that holds customer records is a copy of customer records. It must follow the same rules as the database it copies: who may read it, whether personal data must be encrypted, how long it may be kept, and whether a deletion request must remove it. A CDN that caches a page with someone's address for a day, or a Redis cache that keeps deleted accounts for a week, is a data governance problem as much as a performance one. So the inventory records what kind of data each cache holds, and privacy reviews include caches.
6Changing the Incentives
Teams add caches because a cache can be shipped in a day, while fixing a slow query may need a schema change and another team's time. To change the habit, the organisation has to make the root cause cheaper to fix. That means funding work on slow queries, missing indexes and chatty APIs, and asking for an explanation of why a slow path cannot be fixed before a new cache is approved. A short design note for every new cache, with owner, staleness bound, invalidation and cold-start behaviour, is light enough that people will write it and strong enough to stop accidental layers.
I would also track a few numbers over time: the number of cache layers per request path, incidents involving cache behaviour, and the database load with caches cold. If those improve over a year, the approach has changed.
7Follow-up questions
How do you test what happens when a cache is empty?
In a production-like environment, we flush the cache under realistic load and measure the load and latency of the layer below until it recovers. For a critical cache, a game day in production with a partial flush, for example one region or ten percent of keys, gives the real answer with limited risk.
Should every cache have a staleness bound?
Yes. It is the promise we make to readers about how old the data may be, and it decides the TTL and the invalidation design. A cache without a stated bound is one whose behaviour nobody can explain during an incident.
What do you do if a team insists its cache is necessary but has no metrics?
We ask them to add hit, miss and eviction metrics first and decide after a few weeks of data. It is a small request, it is fair to both sides, and it usually settles the argument.
8Conclusion
In this answer, we saw that many cache layers multiply invalidation work and failure modes, and that unmeasured hit ratios turn caches into hidden dependencies. We build an inventory with owner, purpose, hit ratio, staleness bound and empty-cache behaviour, remove layers that duplicate each other or add little, require capacity plans to cover the cold-cache case, treat caches as copies of data under the same governance, and fund fixing slow queries so that a new cache becomes a deliberate choice.
Open with
First I would make the caches visible. For every layer, from the CDN down to the database, I would record the owner, the purpose, the measured hit ratio, the staleness bound, how it is invalidated, and, most important, what happens if it is empty, ideally tested by flushing it under load in a production-like environment.
Then, if they want more
That inventory usually shows two things: some layers duplicate each other or have low hit ratios, so they add invalidation work and failure modes for little benefit, and one or two layers are silently load-bearing. I would remove the first kind carefully, with a canary and a way back, and give the second kind owners, metrics and alerts.
Then I would change the rules. A capacity plan must show the cold-cache case and state the hit ratio it assumes, which a dashboard then checks. Caches are copies of data, so they follow the same rules for personal data and retention as the source.
And a new cache needs a short design note with its staleness bound and cold-start behaviour, plus an explanation of why the slow query behind it cannot be fixed, because I would rather fund fixing root causes than add another layer. I would judge success by fewer cache-related incidents and a database that survives cold caches.
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
- Spring Framework reference, Cache abstraction
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 "Over several years your platform has added caches at the CDN, API gateway, service...": https://scrivio-interview-library.netlify.app/databases/caching/ae18afddd8/