Quick revision
The short answer
I would set a few non-negotiable rules: no unbounded in-memory caches in production, an explicit TTL and size limit for every cache, JSON serialization with versioned, service-prefixed keys instead of JDK serialization, a standard error-handling policy, and Micrometer metrics for every cache. I would deliver them through a shared Spring Boot starter that makes the safe choice the default, roll it out with an opt-in period and a compatibility mode for existing keys, track adoption on a dashboard, and document when not to cache so the standard does not encourage caching everything.
What to remember
In this answer, we set a small number of caching standards, each tied to an incident it prevents: bounded caches with explicit TTLs, no ConcurrentMapCacheManager in production, JSON values with versioned service prefixes instead of JDK serialization, a standard CacheErrorHandler and metrics for every cache. We delivered them through a shared starter that makes the safe choice the default, rolled them out with an opt-in compatibility phase, per-service migration and an adoption dashboard, and documented when not to cache so the standard does not push teams to cache everything.
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 set a few non-negotiable rules: no unbounded in-memory caches in production, an explicit TTL and size limit for every cache, JSON serialization with versioned, service-prefixed keys instead of JDK serialization, a standard error-handling policy, and Micrometer metrics for every cache. I would deliver them through a shared Spring Boot starter that makes the safe choice the default, roll it out with an opt-in period and a compatibility mode for existing keys, track adoption on a dashboard, and document when not to cache so the standard does not encourage caching everything.
Why this question is asked
When thirty teams each solve caching their own way, the organisation pays for it in incidents: an out-of-memory error from an unbounded map, a deployment that breaks because cached Java objects cannot be read after a class change, a Redis outage nobody saw coming because there were no metrics. A senior engineer is expected to turn those lessons into standards that teams actually adopt. Interviewers ask this to see whether we can pick the few rules that matter, explain why each exists, and change thirty codebases without stopping thirty teams. In this answer, we will look at what is wrong with each current practice, set the standards, design the starter that carries them, plan the rollout, and decide what the standard says about not caching.
1What Is Wrong With the Current Practices
An unbounded ConcurrentMapCacheManager is the fallback Spring Boot gives us when no provider is on the classpath. It is a plain map: entries never expire and the map never shrinks. In production, a cache keyed by something with many values, such as a customer id, grows until the heap fills up and the garbage collector spends most of its time trying to free memory. It also never refreshes, so data cached on Monday is still served on Friday.
JDK serialization, the default for Spring Data Redis values, writes Java objects in a binary format tied to the exact class. Rename a field or change the class in an incompatible way and old entries can no longer be read, so a deployment produces SerializationException for every customer whose entry was cached before it. Deserializing untrusted bytes with Java serialization is also a well-known security risk. And without metrics, nobody can tell whether a cache helps, how big it is, or that it started failing.
2The Standards Worth Setting
Good standards are few and each one has a reason that prevents a known incident. The table below is the set I would propose, with the reason next to each rule.
| Standard | Prevents |
|---|---|
| Every cache has a maximum size or weight | heap exhaustion from unbounded maps |
| Every cache has an explicit TTL | data that is never refreshed |
No ConcurrentMapCacheManager in production | both of the above; fine in tests |
| JSON values, keys prefixed service:v1:cache:: | unreadable entries after class changes, key clashes |
| No JDK serialization for cache values | deserialization attacks and version coupling |
CacheErrorHandler: log, count, treat as miss | a cache outage becoming a service outage |
| Micrometer metrics for every cache | caches nobody can measure |
3A Shared Starter That Makes the Safe Choice the Default
Rules in a wiki are forgotten; rules in a dependency are applied. So I would publish an internal starter, a Spring Boot auto-configuration that teams add as one dependency. It configures the RedisCacheManager with a JSON serializer, a key prefix built from spring.application.name and a schema version, a default TTL such as ten minutes, and per-cache overrides read from properties. It registers a CachingConfigurer whose errorHandler() logs and counts cache failures and lets the method run against the source. For Caffeine it requires a size limit and enables recordStats() so Micrometer can bind hit and miss metrics.
Notice that the starter should also refuse unsafe setups loudly. If it finds a ConcurrentMapCacheManager when the production profile is active, it logs a warning in the first phase and fails startup in a later phase. If a cache has no TTL configured, it applies the default and records that fact in a metric, so we can see which caches rely on defaults.
The exact JSON serializer class depends on the Spring Data Redis version, because newer versions move to Jackson 3, so the starter hides that choice from teams and we change it in one place. Check your version for the serializer names.
4Rolling It Out Without Breaking Teams
A big-bang switch would break every team with entries in the old format. Instead I would roll out in phases. In the first phase the starter is opt-in and runs in compatibility mode: a property keeps the old key prefix and the old serializer for an existing service, so adopting the starter changes nothing except adding metrics and the error handler. Teams get value immediately, which is the best argument for adopting it.
In the second phase, teams switch to the new format one service at a time. Because the new keys have a new prefix, old and new entries never mix; the new version simply starts with a cold cache, and the old keys expire through their TTL. In the third phase, the starter becomes the default in the service template and warnings become failures. Throughout, a dashboard built from the starter's own metrics shows which services still use compatibility mode, JDK serialization or unbounded caches, so we can talk to the teams that are left rather than guess.
- Phase 1: opt-in, compatibility modeold keys and serializer, adds metrics and error handler
- Phase 2: migrate per servicenew prefix, JSON, cold cache, old keys expire by TTL
- Service still on old settings?seen on the adoption dashboard
- Phase 3: default in the templatewarnings become startup failures
4 steps in order. Play them, or step through them one at a time.
5Documenting When Not to Cache
A caching standard can accidentally signal that everything should be cached. So the documentation would say clearly what does not belong in a cache: data that must be strongly consistent, such as account balances or stock reservations; per-request or per-user data with almost no reuse, which only fills memory; and security decisions such as permissions unless the TTL is very short and revocation evicts them. It would also say that a cache must show a benefit in its metrics, and that removing a cache with a low hit ratio is a good change, not a loss.
6Follow-up questions
How would you handle a team that depends on the old key format?
First I would find out why. Often another service or a batch job reads the same keys directly, which means the cache is really a shared data contract. For them the compatibility mode stays on while we agree a migration: either the readers learn the new format and we switch both sides together, or the writer writes both formats for one release so readers can move independently. The exemption is recorded with an owner and an end date, and it shows on the dashboard, so it does not quietly become permanent.
Why not let each team choose freely if their caches work?
Because the failures are not local. An unbounded cache that causes a long garbage collection pause slows every caller of that service, and a shared Redis full of JDK-serialized values blocks a later version upgrade for everyone. A standard is cheaper than thirty separate investigations, and a starter makes following it cheaper than not following it.
What metrics would you require from every cache?
Gets split into hits and misses, puts, evictions, the size of the cache, and errors from the error handler, all tagged with the service and cache name. From those we get the hit ratio, the memory trend and the failure rate, which are enough to judge whether a cache helps and to alert when it breaks.
7Conclusion
In this answer, we set a small number of caching standards, each tied to an incident it prevents: bounded caches with explicit TTLs, no ConcurrentMapCacheManager in production, JSON values with versioned service prefixes instead of JDK serialization, a standard CacheErrorHandler and metrics for every cache. We delivered them through a shared starter that makes the safe choice the default, rolled them out with an opt-in compatibility phase, per-service migration and an adoption dashboard, and documented when not to cache so the standard does not push teams to cache everything.
Open with
I would start from the incidents each current practice causes. Unbounded ConcurrentMapCacheManager caches grow until the heap fills and never refresh, JDK serialization breaks when a class changes and is a deserialization risk, and without metrics nobody can tell if a cache helps or is failing.
Then, if they want more
So the standards would be short: every cache needs a maximum size or weight and an explicit TTL, no in-memory map caches in production, JSON values with keys prefixed by service and a schema version, a CacheErrorHandler that logs and treats failures as misses, and Micrometer metrics for every cache.
I would not publish that as a wiki page; I would ship a starter that configures the RedisCacheManager with the prefix, the JSON serializer and default TTLs, enables stats for Caffeine, and registers the error handler. Rollout would be in phases.
First, opt-in with a compatibility mode that keeps a team's old keys and serializer, so they get metrics with zero risk. Then teams migrate one service at a time to the new prefix, which means a cold cache but no mixed formats, and old keys expire by TTL. Finally it becomes the template default and warnings become failures.
A dashboard from the starter's metrics shows who is left. I would also document when not to cache, such as balances, stock reservations and permissions.
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 "Thirty teams in your organisation use Spring caching in different ways: some use Redis...": https://scrivio-interview-library.netlify.app/databases/caching/e9f0386c21/