Scrivio Interview library
ScenarioAdvanced7 min read · updated 12 November 2026

After a regional failover, several services served stale account limits from their caches for 30 minutes, leading to over-limit transactions. You are leading the follow-up across teams. What would you change?

I would first separate data that is only displayed from data that drives decisions: account limits and balances must be read from the owning service at decision time, never from a cache. For everything else I would set a maximum staleness per data class and enforce it with TTLs from shared configuration, make cache flushing part of the failover runbook, put a region epoch in cache keys that is bumped on failover so old entries are simply never read, and prove the whole thing in game days that measure staleness after a failover.

Why this question is asked

Caches are usually discussed as a performance tool, but this incident shows their other side: a cache is a copy of someone else's data, and after a failover that copy can describe a world that no longer exists. Thirty minutes of stale limits meant real customers spent money they did not have, which is a financial and regulatory problem, not just a bug. Interviewers ask this at a senior level because the fix crosses team boundaries and needs both technical changes and agreed rules. In this answer, we will recap why a failover makes caches stale, look at what went wrong here, and then go through the changes: decision reads from the owner, staleness classes, runbook steps, epoch keys, and testing it in game days.

1Why a Regional Failover Leaves Caches Stale

A regional failover moves traffic from a failed region to another one, where a replica of the database is promoted to become the new primary. Replication between regions is usually asynchronous, which means the replica may be a few seconds or minutes behind. During the failover itself, some writes may be lost or replayed, and limits may be changed by an operator to deal with the incident.

Every cache that was filled before the failover still holds values read from the old primary. Nothing in the failover tells those caches that the source of truth changed. If their TTLs are long, here clearly 30 minutes or more, they keep answering confidently with the old numbers. Invalidation events do not help either, because the event pipeline is often the very thing that was disrupted, and changes made on the new primary during recovery may never have produced events.

Step throughHow a stale limit approved a payment
Payment serviceLocal cacheLimits serviceNew primary DB
failover: replica promoted, limit lowered
get limit for account 991
limit 5,000 (cached 20 min ago)
approve 3,000: within cached limit
real limit 1,000, never asked

5 messages in order. Play them, or step through them one at a time.

2Decide Which Data May Never Come From a Cache

The first change is a rule, not a technology. For a decision that moves money or grants access, the service must read the current value from the owner of that data, here the limits or ledger service, at the moment of the decision. Caches can still be used for showing a balance on a screen, but the check that approves a transaction goes to the owner, ideally in the same call that reserves the amount so the read and the update cannot drift apart.

This sounds expensive, but it is usually a small fraction of traffic. Most reads are page views; the number of approvals per second is far lower. If the owner cannot handle that load, the answer is to scale the owner, not to cache the decision. We write this down as a list of decision-critical data classes so every team knows which fields fall under it.

3Set Maximum Staleness per Data Class

For the remaining data, the question is how stale it may be. Rather than letting each team pick a TTL by feel, we define a few staleness classes and put the TTLs in shared configuration that services load at startup, so a central change applies everywhere and a service cannot silently use 30 minutes for something that should be 30 seconds.

Staleness classes agreed across teams
ClassExamplesMax stalenessRule
Decisionlimits, balances, holdsnoneread from owner at decision time
Near real timeaccount status, flags30 sshort TTL plus invalidation events
Displaynames, preferences10 minTTL from shared config
Referencecurrency list, branch data24 hTTL, refreshed on deploy

Notice that every class has a hard number. That number is what we test against later, and it is what we report in the incident review: the system must never show account status older than 30 seconds, including after a failover.

4Make Caches Part of the Failover Runbook

A runbook is the written procedure operators follow during an event. Today the failover runbook almost certainly covers databases, DNS and traffic, but not caches. We add explicit steps: after the new primary is promoted, flush or invalidate the caches that hold data from the old region, and warm critical caches from the new primary before sending full traffic, so the flush does not turn into a stampede on the database. Each step names the owner team and the command, and the failover is not declared complete until the cache step is checked off.

Flushing by hand across dozens of services is slow and easy to miss, though, so we want a mechanism that makes old entries unusable automatically. That is the epoch.

5Bump an Epoch in Cache Keys on Failover

An epoch, or generation number, is a counter that changes whenever the source of truth changes in a way caches cannot follow. We store it in a highly available place, such as the configuration service, and every cache key includes it. When failover promotes the new primary, the runbook bumps the epoch. From that moment every service builds keys with the new number, so all old entries are simply never read again and expire on their own.

Java
String key(long accountId) {
long epoch = config.currentEpoch(); // 7 before failover, 8 after
return "acct:e" + epoch + ":" + accountId; // acct:e8:991
}
// before failover: acct:e7:991 -> status ACTIVE (old region)
// after the bump: acct:e8:991 -> miss, loaded from the new primary

The reason this works so well is that it needs no message to reach every cache and no list of keys to delete. The cost is a burst of misses right after the bump, which is why the warmup step and rate-limited loading matter. Services should also watch the epoch value and clear their local caches when it changes, so in-process caches follow the same rule as Redis.

6Prove It in Game Days

A game day is a planned exercise where we deliberately cause a failure, here a regional failover, in a test or production-like environment and watch what happens. We add a specific check: before the failover we change a test account's limit only on the region that will take over, then measure how long each service takes to see the new value. The result is compared with the staleness classes, and any service that exceeds its bound is a finding with an owner and a date.

Running this every quarter matters because caches are added quietly over time. A new service with a one-hour TTL on account data would break the rule without anyone noticing, and the game day is where we catch it before a real failover does.

7Follow-up questions

Is it not too slow to read limits from the owner on every transaction?

Usually it is not, because approvals are a small part of the traffic and the owner can be scaled for them. A limits service backed by a well-indexed database answers in a few milliseconds. The real choice is between a few milliseconds of latency and approving money that does not exist. Where latency truly matters, the owner can hold the hot data in its own memory, because it is the only writer and therefore always knows the current value.

Why not just shorten every TTL to a few seconds?

Short TTLs everywhere raise database load sharply and still do not guarantee freshness for decisions, since a few seconds of stale limits can still approve over-limit payments during a burst. Classes let us be strict where it matters and keep long TTLs where data rarely changes. The epoch then covers the failover case for all classes at once.

How do you get 20 teams to adopt these rules?

We write them as a short standard with the incident as the reason, provide a shared cache library that reads TTLs from configuration and includes the epoch in keys, and make the game day the measure. Teams adopt a library more readily than a document, and a failing game-day result with their service named gives the work a clear priority.

8Conclusion

In this answer, we saw why a regional failover leaves caches describing the old region, and how a long TTL turned that into 30 minutes of over-limit transactions. The fix starts with a rule that decision data such as limits and balances is read from the owner, continues with staleness classes enforced by shared TTL configuration, makes cache flushing and warmup a runbook step, uses an epoch in cache keys so old entries become unreachable on failover, and proves the bounds in regular game days.

What to say in the interviewAbout 80 seconds aloud

Open with

I would start by separating data that is shown from data that decides. Limits and balances drive money movement, so the approval check must read from the owning service at decision time, never from a cache; caches can still serve the balance shown on a page.

Then, if they want more

For everything else I would agree maximum staleness per data class, for example 30 seconds for account status and ten minutes for display data, and enforce it through TTLs in shared configuration so no team picks 30 minutes by accident.

Then I would make caches part of failover: the runbook gets an explicit step to invalidate and warm caches after the new primary is promoted. To make that reliable, I would put an epoch number in cache keys and bump it on failover, so every old entry is simply never read again, without relying on messages or key lists.

Finally, I would test it. In each game day we change a test account on the target region, fail over, and measure how long every service takes to see the change against its class. Any service over its bound gets a finding and an owner.

That turns this incident into rules that are checked, rather than a one-off fix in the services that happened to be involved.

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 "After a regional failover, several services served stale account limits from their...": https://scrivio-interview-library.netlify.app/spring-boot/distributed-data/4b14a27c49/