In this chapter, we will learn how to use Resilience4j to make our microservices more resilient, that is, how to mitigate and recover from errors. As we already discussed in Chapter 1, Introduction to Microservices, in the Circuit breaker section, and Chapter 8, Introduction to Spring Cloud, the Resilience4j for improved resilience section, a circuit breaker can be used to minimize the damage that a slow or not-responding downstream microservice can cause in a large-scale system landscape of synchronously communicating microservices. We will see how the circuit breaker in Resilience4j can be used together with a timeout and retry mechanism to prevent two—in my experience—of the most common error situations:
- Microservices that start to respond slowly or not at all
- Requests that randomly fail from time to time...