Search code examples
redisdatabase-connectionconnection-poolingspring-data-redislettuce

Lettuce behavior when redis db is down


We are using lettuce in our redis based api (spring boot). Do we need to implement circuit breaker in our api in case redis database goes down OR lettuce connection pool (using the default connection pool) handles database down scenario itself? The idea is, we should not be consuming connections from the connection pool if database is down. tnx


Solution

  • Lettuce does not have Circuit Breaker capability built in. A circuit breaker is usually an application concern or at best a capability to be slapped on top via a wrapper library like Resilience4j

    If you do not have a wrapper library around Lettuce and if you do not want to litter your codebase with circuit breaker composition APIs, you could let Lettuce connection exceptions bubble up and handle these centrally to open the circuit breaker. A simple exception handler that verifies StatefulConnection.isOpen() before opening the circuit breaker may be all that is required.