Quick revision
The short answer
Entries written by the previous version are still in Redis in the old shape, and the new Customer class cannot read them, so every customer whose entry was cached before the deployment fails while customers cached afterwards work. To recover now, we evict the affected cache or key prefix, or add a CacheErrorHandler that logs read errors and treats them as misses so the method reloads from the database and overwrites the entry. To avoid it, we use versioned key prefixes per schema version, tolerant JSON deserialization and backward-compatible class changes, and remember that during a rolling deployment old and new versions read the same keys.
What to remember
In this answer, we saw that a renamed field made entries written by the old version unreadable, which is why only customers cached before the deployment failed. We recovered by evicting the cache's keys with SCAN rather than KEYS, or through the actuator, and by adding a CacheErrorHandler that turns read errors into misses so entries heal as they are reloaded. To prevent it, we version key prefixes per schema version, read JSON tolerantly with ignored unknown properties and aliases, make class changes backward-compatible, and make sure old and new versions can coexist during rolling deployments and rollbacks.
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.
Entries written by the previous version are still in Redis in the old shape, and the new Customer class cannot read them, so every customer whose entry was cached before the deployment fails while customers cached afterwards work. To recover now, we evict the affected cache or key prefix, or add a CacheErrorHandler that logs read errors and treats them as misses so the method reloads from the database and overwrites the entry. To avoid it, we use versioned key prefixes per schema version, tolerant JSON deserialization and backward-compatible class changes, and remember that during a rolling deployment old and new versions read the same keys.
Why this question is asked
A cache is a database that nobody thinks of as a database. Its contents outlive the code that wrote them, so any change to a cached class is really a schema change. This incident shows the consequence clearly: a harmless field rename turns into errors for a random-looking subset of customers. Interviewers ask this to check that we can explain the pattern of failures, recover quickly without making things worse, and change the design so the next rename is a non-event. In this answer, we will recap how values are stored in Redis, explain why only some customers fail, recover in production, prevent it with versioned prefixes and tolerant reading, and deal with rolling deployments.
1A Quick Recap: What Is Actually Stored in Redis
When @Cacheable stores a Customer in Redis, it cannot store the Java object itself. It serializes it, turns it into bytes, with the configured serializer. With JDK serialization the bytes describe the class, its serialVersionUID and every field by name. With JSON they are a document with field names as keys, often with a type property such as @class. Reading is the reverse: the serializer must turn the old bytes back into the current class.
Nothing in Redis changes when we deploy. The entries written by version 1 stay there until their TTL expires or they are evicted, and version 2 is asked to read them.
2Why Only Some Customers Fail
The release renamed a field, say phone to phoneNumber. Customers whose entries were cached by version 1 have documents containing phone. Customers who were not cached, or whose entries expired after the deployment, are loaded fresh by version 2 and stored in the new shape, so they work. The failures follow the cache contents, not the customers.
9 messages in order. Play them, or step through them one at a time.
Whether a rename breaks reading depends on the serializer and its settings. A Jackson mapper that fails on unknown properties rejects the old field. JDK serialization without an explicit serialVersionUID computes a new one from the class shape, so any change fails. With an explicit serialVersionUID, the old field is ignored and phoneNumber is simply null, which is quieter but just as wrong. The default CacheErrorHandler rethrows, so the request fails.
3Recovering Now
The quickest recovery is to remove the old entries so they are reloaded in the new shape. If the Spring Boot actuator caches endpoint is exposed, DELETE /actuator/caches/customers clears that cache through the CacheManager. Otherwise we delete the keys with the prefix directly, using SCAN rather than KEYS, because KEYS blocks Redis while it walks the whole key space.
The error handler is the more durable fix. When handleCacheGetError does not rethrow, Spring treats the failure as a miss, runs the method against the database and puts the result in the new shape, so the cache heals itself entry by entry. Clearing a whole hot cache at once, in contrast, sends every request to the database, so on a big cache we clear it at a quiet time or rely on the handler.
4Preventing It: Versioned Prefixes and Tolerant Reading
The most reliable prevention is to give each schema version of the cached class its own key prefix, for example customers:v2::42. A new version never reads entries it did not write; it starts with a cold cache for that prefix, and the old keys expire through their TTL. We bump the version only when the change is incompatible, so most releases keep a warm cache.
Alongside that, we make reading tolerant. A Jackson mapper configured not to fail on unknown properties can read documents with extra fields, and a field can accept its old name through an alias, such as @JsonAlias("phone") on phoneNumber, so a rename can be read in both directions for a release. And we prefer backward-compatible changes: add new fields as optional, remove old fields only after the entries that contain them have expired.
5Rolling Deployments: Both Versions at Once
During a rolling deployment, some instances run version 1 and some run version 2, and they share the same Redis keys. Version 2 can fail on entries written by version 1, and version 1 can fail on entries written by version 2, so errors may appear in both directions until the rollout finishes, and again if we roll back.
So the rule is that, during the overlap, either both versions can read each other's entries, which tolerant reading and additive changes give us, or they use different prefixes, which versioned keys give us. A rollback then also works, because version 1 still finds its own v1 keys.
6Follow-up questions
Would switching from JDK serialization to JSON alone have prevented this?
It helps but does not prevent it. JSON makes entries readable and lets us ignore unknown fields, but a rename can still lose data or fail, and a stored @class name breaks when the class moves. The real prevention is treating cached data as a schema: compatible changes, tolerant readers, and a new prefix for incompatible changes.
Is it safe to swallow all cache errors in the error handler?
For get errors, yes, as long as we log and count them, because the method can produce the correct value from the source. For put and evict errors we should think more carefully: a failed eviction leaves a stale entry, so it deserves at least an alert and perhaps a retry. Swallowing errors silently is what we must avoid, because then a broken cache looks healthy.
7Conclusion
In this answer, we saw that a renamed field made entries written by the old version unreadable, which is why only customers cached before the deployment failed. We recovered by evicting the cache's keys with SCAN rather than KEYS, or through the actuator, and by adding a CacheErrorHandler that turns read errors into misses so entries heal as they are reloaded. To prevent it, we version key prefixes per schema version, read JSON tolerantly with ignored unknown properties and aliases, make class changes backward-compatible, and make sure old and new versions can coexist during rolling deployments and rollbacks.
Open with
The cause is that the entries written by the old version are still in Redis in the old shape. The cached Customer is serialized, and after the rename the new class cannot deserialize documents that contain the old field, or with JDK serialization the serialVersionUID no longer matches.
Then, if they want more
Only customers who were cached before the deployment fail; anyone cached afterwards was written in the new shape, so the errors look random but they follow the cache contents. Because the default error handler rethrows, the request fails.
To recover now, I would clear that cache's keys, through the actuator caches endpoint or with redis-cli scan on the customers prefix and unlink, never KEYS.
I would also add a CacheErrorHandler through CachingConfigurer that logs a get error, evicts the key and lets Spring treat it as a miss, so the method reloads from the database and the entry heals.
To avoid it next time, I would version the key prefix by schema, like crm:v2:customers, so a new version never reads entries it did not write, and old keys just expire. I would make JSON reading tolerant, ignore unknown properties, use aliases for renames, and keep changes additive.
And I would point out rolling deployments: old and new versions run at the same time on the same keys, so they must either read each other's format or use separate prefixes, which also keeps rollback safe.
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 "After a deployment that renamed a field in the cached Customer class, a service using...": https://scrivio-interview-library.netlify.app/databases/caching/2dd5390939/