Scrivio Interview library
ScenarioIntermediate6 min read · updated 13 November 2026

A release changed the cache key format of a product service from product:<id> to product:<id>:<locale> and switched to a new JSON serializer. All 30 pods were deployed within five minutes, the database CPU went to 100 percent, and the service was slow for 40 minutes.

Why did a code change act like a cache outage, and how do you roll out key or format changes safely in future?

After the deploy, every lookup used a key the cache did not contain, and values in the old format could not be read anyway, so the effective hit ratio dropped to near zero for the whole service at once: an avalanche caused by a deploy. We roll such changes out gradually behind canary pods, make them compatible by reading the new key and falling back to the old one with conversion, keep the reader able to parse the old format for at least one TTL, warm the new keys before switching traffic, and protect the database with concurrency limits regardless.

Why this question is asked

We rarely think of a cache key as an interface, but it is one: every running version of the service must agree on how keys are built and how values are encoded. Change either, and the new code finds an empty cache. Interviewers ask this because it is an easy mistake to make in a small pull request and an expensive one in production. In this answer, we will explain why the change acted like a cache outage, why it lasted 40 minutes, and then go through gradual rollout, compatible reads, warming, protecting the database and catching such changes in review.

1Why a Code Change Emptied the Cache

The old code stored products under product:<id>. The new code looks for product:<id>:<locale>, a key that no running code had ever written. So from the first request, every lookup on a new pod missed. Even if the key had stayed the same, the new JSON serializer would have failed to read values written by the old one, which is also a miss in practice, or worse, an error.

With all 30 pods replaced in five minutes, the effective hit ratio of the whole service fell to near zero within those minutes. The cache cluster was healthy and full; it was simply full of keys nobody asked for anymore. To the database this looks exactly like losing the cache: a cache avalanche, triggered by a deploy.

2Why It Lasted 40 Minutes

Refilling a cache takes as long as it takes to load every popular key once. Normally that would be minutes. But the database was receiving many times its usual load, so each load was slow, so keys filled slowly, so the misses continued for longer. A database at 100 percent CPU serves every query more slowly, and request threads waiting on it pile up. The system recovered only as the most popular keys were gradually filled. This feedback loop, where an overloaded backend slows its own recovery, is why cold-cache incidents last much longer than the arithmetic suggests.

3Rolling Out Gradually

The simplest protection is to let only a small fraction of traffic run on the new key format at first. With a canary of 2 pods out of 30, about 7 percent of requests miss while the new keys fill, which the database absorbs easily. Once the canary's hit ratio has recovered and database load is back to normal, we continue in steps, say to 25 percent and then 100 percent.

This only works if someone watches the right numbers during the rollout: hit ratio on the new pods, database CPU and query latency. The rollout should pause automatically if database load passes a threshold, rather than relying on a person noticing.

4Making the Change Compatible

Better still is a change that does not depend on how fast we roll out. The new code reads the new key first; on a miss it reads the old key, converts the value and writes it under the new key. The reader also understands both serialization formats, recognising which one a value uses by a format marker, for example a version prefix in the stored value.

Java
Product get(long id, String locale) {
String v = redis.opsForValue().get("product:" + id + ":" + locale); // new key
if (v != null) return codec.decode(v); // handles format v1 and v2
String old = redis.opsForValue().get("product:" + id); // fallback to the old key
if (old != null) {
Product p = codec.decode(old).localized(locale); // convert old format
redis.opsForValue().set("product:" + id + ":" + locale, codec.encodeV2(p), ttl());
return p; // a hit, no database query
}
return loadAndCache(id, locale); // a real miss
}
Step throughReading during a key format change
  1. New key present?product:<id>:<locale>
    YesDecode, either formatNoTry the old key
  2. Old key present?product:<id>
    YesConvert, write new key, returnNoLoad from the database
  3. Remove fallback after one TTLA later release drops old reads

3 steps in order. Play them, or step through them one at a time.

During the transition, old pods may still be writing old keys, so the fallback finds fresh data. After one full TTL, every old key has expired, the fallback no longer finds anything, and a later release removes it along with the old format reader. If the transition needs old pods to read data written by new ones, the new code can write both keys for that period; it costs memory but keeps both versions warm.

5Warming the New Keys

Even with a fallback, values that exist only in the database must be loaded. If the change is large, a warming job can prepare the new keys before traffic arrives: take the most requested product ids and locales from the last day's access logs, load them at a controlled rate, and write them in the new format. Warming the top 50,000 keys usually covers the large majority of requests, because access is heavily skewed toward popular products.

6Protecting the Database Regardless

Every one of these measures can be forgotten in some future release, so the database needs its own protection. A concurrency limit on database calls, for example a bulkhead that allows 50 concurrent queries per pod and rejects or queues the rest, means a sudden miss storm produces some slow or failed requests rather than a database at 100 percent CPU that slows everything. Combined with serving stale data where available, it turns the next mistake into a brief degradation.

Finally, the process. The release checklist should include a line for any change to cache keys, serializers, cache names or TTLs: how will the cache refill, and how is the database protected while it does?

7Follow-up questions

How would you detect such a change in code review?

By making it visible in the code. Keep key construction in one place, such as a CacheKeys class, and serializer configuration in one configuration class, and mark both with code owners so changes get the right reviewer. Add a test that pins the key format and a stored sample value in the old format, which must still decode; a change that breaks either test forces a conscious decision about migration rather than an accidental outage.

Is adding a version to the cache name a good idea?

Yes, a version such as product:v2:<id> makes a format change explicit and avoids old code reading new values it cannot parse. But it is exactly what happened here, a new key space starting empty, so it still needs a gradual rollout, a fallback or warming.

Why did the serializer change matter if the keys changed anyway?

Because during a mixed rollout, or after a rollback, old and new pods may read each other's values. A new serializer that cannot read the old format, or an old one that cannot read the new, turns those reads into errors or misses. Readers should accept both formats for at least one TTL.

8Conclusion

In this answer, we saw that changing the key format and serializer emptied the cache for the new code, giving a near-zero hit ratio across the service: an avalanche caused by a deploy, prolonged because an overloaded database slows the refill. Safe rollouts use canaries with automatic pauses, compatible reads that fall back to the old key and convert, readers that parse both formats for at least one TTL, warming of the most-requested keys, concurrency limits that protect the database regardless, and a checklist and tests that make such changes visible.

What to say in the interviewAbout 80 seconds aloud

Open with

The cache key and the value format are a contract between versions of the service. The release changed both: new code looked for product, id, locale keys that nobody had written, and could not read the old serialized values anyway.

Then, if they want more

So every lookup on new pods missed, and with all 30 pods replaced in five minutes the hit ratio fell to near zero. That is a cache avalanche caused by a deploy, and it lasted 40 minutes because the overloaded database made each refill slow, which kept the misses going. Next time I would do four things.

Roll out with a canary of a couple of pods and only continue when their hit ratio recovers and database load is normal, with an automatic pause.

Make the change compatible: read the new key, and on a miss read the old key, convert it and write the new one, and keep the reader able to decode the old format for at least one TTL. Warm the most requested keys in the new format from access logs before switching traffic.

And protect the database regardless with a concurrency limit on database calls. I would also add a release checklist item and a test that pins the key format, so such changes are reviewed deliberately.

About this answer

Last updated
13 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 official documentation for the version you use. 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 "Why did a code change act like a cache outage, and how do you roll out key or format...": https://scrivio-interview-library.netlify.app/architecture/caching-strategies/316c0e2b1a/