7 When bad things happen: Resiliency patterns with Spring Cloud and Resilience4j

 

This chapter covers

  • Implementing circuit breakers, fallbacks, and bulkheads
  • Using the circuit breaker pattern to conserve client resources
  • Using Resilience4j when a remote service fails
  • Implementing Resilience4j’s bulkhead pattern to segregate remote resource calls
  • Tuning Resilience4j circuit breaker and bulkhead implementations
  • Customizing Resilience4j’s concurrency strategy

All systems, especially distributed systems, experience failure. How we build our applications to respond to that failure is a critical part of every software developer’s job. However, when it comes to building resilient systems, most software engineers only take into account the complete failure of a piece of infrastructure or critical service. They focus on building redundancy into each layer of their application using techniques such as clustering key servers, load balancing between services, and segregating infrastructure into multiple locations.

While these approaches take into account the complete (and often spectacular) loss of a system component, they address only one small part of building resilient systems. When a service crashes, it’s easy to detect that it’s no longer there, and the application can route around it. However, when a service is running slow, detecting that poor performance and routing around it is extremely difficult. Let’s look at some reasons why:

7.1 What are client-side resiliency patterns?

7.1.1 Client-side load balancing

7.1.2 Circuit breaker

7.1.3 Fallback processing

7.1.4 Bulkheads

7.2 Why client resiliency matters

7.3 Implementing Resilience4j

7.4 Setting up the licensing service to use Spring Cloud and Resilience4j

7.5 Implementing a circuit breaker

7.5.1 Adding the circuit breaker to the organization service

7.5.2 Customizing the circuit breaker

7.6 Fallback processing

7.7 Implementing the bulkhead pattern

7.8 Implementing the retry pattern

7.9 Implementing the rate limiter pattern

7.10 ThreadLocal and Resilience4j