Quick revision
The short answer
I would make every cache a documented copy of data with a named owner and a stated maximum staleness, set by classifying the data by how much staleness it can tolerate. Security-sensitive decisions such as permissions may only be cached with very short TTLs or event-driven invalidation. Owning services publish standard change events so consumers do not invent their own invalidation, every cache needs invalidation tests and a metric showing the age of the data it serves, and caches are reviewed in design reviews like any other copy of data.
What to remember
In this answer, we built a policy against stale-cache bugs by treating every cache as a copy of data with an owner. Data is classified by staleness tolerance and each cache documents its maximum staleness. Security decisions such as permissions may only be cached for seconds with revocation events. Owning services publish standard change events so consumers stop inventing their own invalidation. Every cache has invalidation tests and an age-of-data metric, and caches go through design review with a named owner, so incidents can be traced to a broken rule or a rule that needs changing.
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 make every cache a documented copy of data with a named owner and a stated maximum staleness, set by classifying the data by how much staleness it can tolerate. Security-sensitive decisions such as permissions may only be cached with very short TTLs or event-driven invalidation. Owning services publish standard change events so consumers do not invent their own invalidation, every cache needs invalidation tests and a metric showing the age of the data it serves, and caches are reviewed in design reviews like any other copy of data.
Why this question is asked
When incident reviews keep finding the same class of bug, the fix is no longer in any single service. Old addresses, old prices and revoked permissions that still work are all the same failure: a copy of data that nobody was responsible for keeping honest. The revoked permission is the most serious, because it is a security failure rather than an annoyance. Interviewers ask this question to see whether a senior leader can turn repeated incidents into a policy that changes how teams build, without banning caching or drowning teams in process. In this answer, we will see why stale-cache bugs repeat, classify data by staleness tolerance, set special rules for security decisions, standardise change events, require tests and metrics, and put caches into design review.
1Why the Same Bugs Keep Coming Back
Each team adds a cache to solve a performance problem, and the decision of how stale the data may be is made implicitly, by whatever TTL looked reasonable. The team that owns the data does not know the copy exists, so when it changes the data, nobody evicts. And the consumer team invents its own invalidation, often listening to a database table or polling, which breaks the next time the owner changes its schema. Nothing in this chain is malicious; it is simply that a cache is treated as a performance tweak when it is really a copy of someone else's data.
2Classifying Data by Staleness Tolerance
The first rule is that every cache must state its maximum staleness, and that number must come from the data's classification, not from the developer's guess. A small set of classes is enough, and the class decides the allowed caching.
| Class | Examples | Allowed caching |
|---|---|---|
| Static | country lists, product descriptions | long TTL (hours), evict on change |
| Business-tolerant | display prices, addresses on a profile page | TTL in minutes plus change events |
| Must be fresh | balances, stock reservations, checkout price | no cache, read from the owner |
| Security-sensitive | permissions, sessions, API keys, blocks | seconds only, plus revocation events |
3Special Rules for Security Decisions
A cached permission check means a revoked user keeps access until the entry expires. If the cache holds "user 17 may approve payments" for an hour, firing that employee does not stop them for an hour. So the policy forbids caching security decisions with ordinary TTLs. They may be cached for a few seconds to absorb bursts, and revocation must publish an event that evicts the entry everywhere immediately. Where even seconds are too much, for example blocking a compromised account, the check goes to the source.
Notice that the rule is about decisions, not just data. Caching a user's role list for an hour is the same risk as caching the yes or no answer, so both fall under the security class.
4Standard Change Events From the Owning Service
Consumers invent their own invalidation because the owner does not tell them when data changes. The policy fixes that from the owner's side: every service that owns data others may cache publishes change events, address-changed or permission-revoked, after commit, in a standard format with the entity id and a version or timestamp. Consumers evict on those events. The owner does not need to know who caches, and consumers do not need to read the owner's database.
- Customer service commits a new addressthe owner of the data
- Publishes customer-address-changedafter commit, standard format, with version
- Each consumer with a cache evicts the keyorders, shipping, support tools
- Next read loads the new addressfrom the owner
- TTL bounds staleness if an event is missedthe documented maximum
5 steps in order. Play them, or step through them one at a time.
5Invalidation Tests and Age Metrics
A cache's invalidation path is code, and code without tests breaks. So the policy requires a test for each cache that changes the data at the source, waits for the event path, and asserts that the next read returns the new value within the stated bound. These tests are what would have caught the old-address bug before production.
In production we need to see staleness, not just hit ratios. A simple and effective metric is the age of served data: when a value is cached, we store the time it was loaded, and on each hit we record now minus load time in a histogram. If the policy says addresses are at most five minutes stale and the p99 age is 40 minutes, something is broken, and we know before a customer complains.
6Caches in Design Review, With an Owner
Finally, the policy changes how we think about a cache: it is a copy of data, and copies are reviewed like any other data store. A design review that adds a cache answers four questions: which data and which staleness class, who owns the cache, how it learns about changes, and what is the maximum staleness. The answers are recorded in the service catalogue next to the cache name. That record is also what an incident review uses to check whether a stale-data bug broke the policy or the policy itself needs to change.
7Follow-up questions
How do you roll this out without stopping all teams?
Start with the highest-risk class. In the first quarter, every cache of security-sensitive data is found and fixed, because those are actual vulnerabilities. Then the shared starter adds the age metric and requires a declared staleness for new caches, and existing caches are documented as teams touch them. The policy is enforced in design review for new work, and the incident reviews keep pointing at the remaining gaps.
Does this not discourage caching entirely?
It should discourage careless caching, and it should make good caching easier. With standard change events and a starter that handles eviction and metrics, adding a correct cache is less work than inventing one. The classification also tells teams where caching is safe and encouraged, not only where it is forbidden.
8Conclusion
In this answer, we built a policy against stale-cache bugs by treating every cache as a copy of data with an owner. Data is classified by staleness tolerance and each cache documents its maximum staleness. Security decisions such as permissions may only be cached for seconds with revocation events. Owning services publish standard change events so consumers stop inventing their own invalidation. Every cache has invalidation tests and an age-of-data metric, and caches go through design review with a named owner, so incidents can be traced to a broken rule or a rule that needs changing.
Open with
I would start from the pattern: every one of these incidents is a copy of data nobody was responsible for keeping honest, and the staleness was decided implicitly by whatever TTL looked reasonable.
Then, if they want more
So the policy treats a cache as a copy of data with an owner. First, classify data by staleness tolerance, something like static, business-tolerant, must-be-fresh and security-sensitive, and require every cache to document its class and maximum staleness. Must-be-fresh data like balances or the checkout price is not cached.
Second, security decisions such as permissions are special: they may only be cached for a few seconds, and revocation must publish an event that evicts immediately, because a cached permission means a revoked user still has access.
Third, the owning service publishes standard change events after commit, with an id and version, so consuming teams evict on those instead of inventing their own invalidation by polling or reading another team's tables.
Fourth, every cache needs an invalidation test, change the source and assert the next read is fresh within the bound, and a metric for the age of served data, so we see staleness before customers do. Finally, caches go through design review like any data store, with a named owner recorded in the service catalogue.
I would roll it out starting with security-sensitive caches, since those are real vulnerabilities.
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 "Incident reviews in your organisation keep finding stale-cache bugs: customers see old...": https://scrivio-interview-library.netlify.app/databases/caching/cacd700d1e/