Scrivio Interview library
LeadershipAdvanced5 min read · updated 12 November 2026

Incident reviews in your organisation keep finding stale-cache bugs: customers see old addresses, old prices and revoked permissions. How would you set a policy for what can be cached and how invalidation must work across teams?

Try it yourself

Cache-aside: one read, three cache states

See what a cache hit saves, what a miss costs, and why a write deletes the cached entry instead of updating it.

Read this example as text

When the entry is in the cache (a hit)

  1. A request arrives. A caller asks the service for product 42. The cache already holds it.
  2. Ask the cache first. The service always asks the cache before the database. It sends GET product:42.
  3. Hit: the value comes back. The entry is there and still fresh, so the cache answers at once. The database is never touched.

1 cache call, 0 database reads.

When it was never cached (a miss)

  1. A request arrives. A caller asks the service for product 42. Nobody has asked for it before, so the cache holds nothing.
  2. Ask the cache first. The service always asks the cache before the database. It sends GET product:42.
  3. Miss: nothing comes back. The key was never stored. The cache answers nil, and the service must find the value itself.
  4. Read the database. The service runs SELECT ... FROM products WHERE id = 42. This is the slow, authoritative read the cache exists to avoid.
  5. The row comes back. The database returns the row. The service now has the value, but the cache is still empty.
  6. Store it for next time. Before answering, the service writes the value into the cache with a time to live: SET product:42 ... EX 300. The next read inside 300 seconds will be a hit.
  7. Answer the caller. The caller gets the value. It cost one database read, which a hit would have saved.

2 cache calls, 1 database read.

When its time to live has run out

  1. A request arrives. A caller asks the service for product 42. The cache held it once, but its time to live ran out 12 seconds ago.
  2. Ask the cache first. The service always asks the cache before the database. It sends GET product:42.
  3. Miss: nothing comes back. An expired key is the same as a missing one: Redis no longer returns it, and removes it. The cache answers nil, and the service must find the value itself.
  4. Read the database. The service runs SELECT ... FROM products WHERE id = 42. This is the slow, authoritative read the cache exists to avoid.
  5. The row comes back. The database returns the row. The service now has the value, but the cache is still empty.
  6. Store it for next time. Before answering, the service writes the value into the cache with a time to live: SET product:42 ... EX 300. The next read inside 300 seconds will be a hit.
  7. Answer the caller. The caller gets the value. It cost one database read, which a hit would have saved.

2 cache calls, 1 database read.

When the price changes afterwards

  1. The price changes. Later, someone updates the price to 25. The service writes the database first: UPDATE products SET price = 25 WHERE id = 42.
  2. Delete the cached entry. Then it deletes the key: DEL product:42. It does not write 25 into the cache. Deleting is simpler and safer: the next read misses and loads whatever the database holds then.
  3. The next read will miss. The cache is empty for this key again, so the next request repeats the miss path and stores 25.

3 cache calls, 1 database read, 1 database write.

What this example leaves out
  • One request at a time. Two requests missing at the same moment (a stampede) are not shown.
  • The write deletes the key. Some systems update the cache instead, which this example does not model.
  • The numbers are counts of round trips, not measured times.

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.

Staleness classes
ClassExamplesAllowed caching
Staticcountry lists, product descriptionslong TTL (hours), evict on change
Business-tolerantdisplay prices, addresses on a profile pageTTL in minutes plus change events
Must be freshbalances, stock reservations, checkout priceno cache, read from the owner
Security-sensitivepermissions, sessions, API keys, blocksseconds only, plus revocation events
The class comes from the data owner; each cache documents its class and its maximum staleness.

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.

Step throughHow an address change reaches every copy
  1. Customer service commits a new addressthe owner of the data
  2. Publishes customer-address-changedafter commit, standard format, with version
  3. Each consumer with a cache evicts the keyorders, shipping, support tools
  4. Next read loads the new addressfrom the owner
  5. 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.

What to say in the interviewAbout 90 seconds aloud

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.
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/