Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

Your Redis cluster had a 10 minute outage and the product service, which uses @Cacheable with Redis, returned 500 errors for every request even though the database was healthy. How would you change the service so a cache outage degrades performance instead of availability?

By default, Spring's cache interceptor rethrows any exception from the cache, so when Redis is down every @Cacheable call fails even though the database could answer. We change that with a CacheErrorHandler, registered through CachingConfigurer, that logs and counts get, put and evict errors and lets the method run against the database. We also set short Lettuce connect and command timeouts so calls fail fast, make sure the database can survive the uncached load or protect it with rate limiting and load shedding, and alert on the cache error rate so the degraded mode is visible.

Why this question is asked

A cache is supposed to make a service faster, not to become a reason it stops working. Yet many services treat their cache as a hard dependency without anyone deciding that, simply because of a default. A ten minute Redis outage that turns into ten minutes of 500 errors is the moment teams discover it. Interviewers ask this to see whether we know where the default comes from and how to design graceful degradation without simply moving the outage to the database. In this answer, we will recap why the errors happened, add an error handler, make Redis calls fail fast, check what happens to the database, and make the degraded mode visible.

1A Quick Recap: Why a Cache Outage Became an Outage

When a @Cacheable method is called, the CacheInterceptor calls cache.get(key) on the RedisCache. With Redis unreachable, the Redis client, Lettuce in Spring Boot, throws an exception such as RedisConnectionFailureException or a command timeout. The interceptor hands that exception to the configured CacheErrorHandler, and the default one, SimpleCacheErrorHandler, rethrows it. So the method body, which would have queried the healthy database, never runs, and the request fails.

There is a second, quieter problem. Lettuce's default command timeout is long, 60 seconds unless Spring Boot's spring.data.redis.timeout is set, and while disconnected it can queue commands waiting for a reconnect. So during the outage, requests may not even fail quickly; they hang, holding request threads, until the timeout. A thread pool of 200 threads fills up in seconds, and the service stops answering even health checks.

2Treating Cache Errors as Misses

The fix is a CacheErrorHandler that does not rethrow. When handleCacheGetError returns normally, Spring treats the failed lookup as a miss and runs the method. When handleCachePutError returns normally, the result is simply not cached. We register the handler by implementing CachingConfigurer.

Java
@Configuration
@EnableCaching
class ResilientCaching implements CachingConfigurer {
private final MeterRegistry meters;
ResilientCaching(MeterRegistry meters) { this.meters = meters; }
@Override
public CacheErrorHandler errorHandler() {
return new CacheErrorHandler() {
public void handleCacheGetError(RuntimeException e, Cache c, Object key) { record("get", c, e); }
public void handleCachePutError(RuntimeException e, Cache c, Object key, Object v) { record("put", c, e); }
public void handleCacheEvictError(RuntimeException e, Cache c, Object key) { record("evict", c, e); }
public void handleCacheClearError(RuntimeException e, Cache c) { record("clear", c, e); }
};
}
private void record(String op, Cache c, RuntimeException e) {
meters.counter("cache.errors", "cache", c.getName(), "op", op).increment();
log.warn("cache {} failed on {}: {}", op, c.getName(), e.toString()); // no stack trace flood
}
}
// During the outage:
// productService.find(42) -> get fails, counted, method runs, Product 42 from the database
// -> put fails, counted, Product 42 returned to the caller
Step throughOne cached call while Redis is down
  1. Proxy calls cache.get(42)Redis unreachable
  2. Fails within the command timeoutfor example 200 ms, not 60 s
  3. Error handler rethrows?
    YesRequest fails with 500NoCount the error, treat as a miss
  4. Run the methodquery the database
  5. cache.put failscounted and ignored
  6. Return the productslower, but available

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

Spring also ships a LoggingCacheErrorHandler that logs and swallows errors, which is a good starting point; the custom version adds metrics. Notice that we log one line per error rather than a stack trace, because during an outage there will be thousands per second.

3Making Redis Calls Fail Fast

Treating errors as misses only helps if the errors arrive quickly. We set an explicit connect timeout and command timeout, sized from Redis's normal latency: if a GET normally takes 1 millisecond, a 200 millisecond timeout is generous and still bounds the damage. We can also tell Lettuce to reject commands immediately while disconnected instead of queueing them.

Java
spring.data.redis.connect-timeout=500ms
spring.data.redis.timeout=200ms
@Bean
LettuceClientConfigurationBuilderCustomizer rejectWhileDisconnected() {
return b -> b.clientOptions(ClientOptions.builder()
.disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS)
.build());
}

Even with short timeouts, every request still pays up to 200 milliseconds trying Redis twice, once for the get and once for the put. A circuit breaker around cache access, for example with Resilience4j inside a small Cache decorator, can skip Redis entirely for a few seconds after repeated failures and probe it again later. That turns the degraded mode from slow to merely uncached.

4Can the Database Take the Full Load?

There is a catch in all of this: the cache was probably protecting the database. If the hit ratio is 95 percent, an outage multiplies database reads by twenty. A database that comfortably serves 500 queries per second behind the cache may receive 10,000, and then the outage simply moves from Redis to the database, and possibly to every other service that shares it.

So we check the numbers before relying on graceful degradation. A load test with caching disabled tells us whether the database survives. If it does not, we add protection on the cache-miss path: a concurrency limit, such as a bulkhead of 50 concurrent database loads per instance, rate limiting, or load shedding that returns a fast 503 for low-priority traffic so that critical requests still get through. Serving degraded but correct answers for most requests is better than failing all of them.

5Making the Degraded Mode Visible

A service that silently runs without its cache looks healthy while it costs more and runs slower, and the database team sees load with no explanation. So we alert on the cache.errors counter, for example when the error rate is above 1 percent of cache operations for two minutes, and we put the cache hit ratio and database query rate next to each other on the dashboard. We should also decide whether the health endpoint reports Redis: if a Redis failure makes instances report themselves as down, the load balancer may remove every instance, which recreates the outage we just avoided. Readiness should not depend on an optional dependency.

6Follow-up questions

What about failed evictions during the outage?

They are the dangerous part. If an update succeeds in the database but the eviction fails, and Redis comes back with its data intact, for example after a network partition rather than a restart, the old value is still there and will be served until its TTL. We can choose to fail the update when eviction fails, record failed keys and evict them again when Redis recovers, clear the affected caches after any outage, or keep TTLs short enough that the staleness is acceptable. Which one depends on how harmful a stale value is for that data.

Should Redis be part of the health check?

Usually not for liveness or readiness, because the service can still serve requests without it. Spring Boot adds a Redis health indicator automatically, so we may need to exclude it from the readiness group. We still monitor Redis separately, so the dependency is visible without being able to take the service out of the load balancer.

Why not fall back to a local cache during the outage?

We can, with a small Caffeine cache in front of Redis or as a fallback, and it softens the database load. But it brings its own consistency problems, because each instance then serves its own copy, so its TTL must be short and the data must tolerate it.

7Conclusion

In this answer, we saw that a Redis outage failed every request because the default SimpleCacheErrorHandler rethrows cache exceptions, and long Lettuce timeouts made requests hang as well. We fixed it with a CacheErrorHandler registered through CachingConfigurer that logs and counts errors and lets the method run, short connect and command timeouts, rejection of commands while disconnected and optionally a circuit breaker. We then checked that the database can survive the uncached load or protected it with concurrency limits and load shedding, and made the degraded mode visible with an alert on the cache error rate.

What to say in the interviewAbout 90 seconds aloud

Open with

The reason every request failed is that Spring's default cache error handler, SimpleCacheErrorHandler, rethrows exceptions from the cache. So when the RedisCache get failed, the method that would have queried the healthy database never ran.

Then, if they want more

On top of that, Lettuce's default command timeout is long, so requests probably hung and filled the thread pool. I would fix it in a few layers. First, implement CachingConfigurer and return a CacheErrorHandler that logs one line and increments a metric for get, put, evict and clear errors without rethrowing.

Then a failed get is treated as a miss, the method runs against the database, and a failed put is just skipped. Second, set short timeouts, spring.data.redis.connect-timeout and spring.data.redis.timeout of a few hundred milliseconds, and configure Lettuce to reject commands while disconnected, maybe with a circuit breaker so we skip Redis entirely for a while.

Third, check the database: with a 95 percent hit ratio, losing the cache means twenty times the reads, so I would load test without the cache and add concurrency limits or load shedding on the miss path if needed.

Fourth, alert on the cache error rate so the degraded mode is visible, and keep Redis out of readiness so instances are not pulled from the load balancer. Failed evictions during the outage need attention too, because they can leave stale entries.

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 "Your Redis cluster had a 10 minute outage and the product service, which uses @Cacheable...": https://scrivio-interview-library.netlify.app/databases/caching/a80abc9f71/