Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 71
Circuit Breaker
When a downstream service is failing, hammering it makes everything worse.
Course progress0%
Focus
2 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
When a downstream service is failing, hammering it makes everything worse. A circuit breaker trips after N failures, fails fast for a cool-down period, then probes — protecting your service and the dependency.
Informative example
Resilience4j with Spring Boot:
ts
# pom.xml<dependency><groupId>io.github.resilience4j</groupId><artifactId>resilience4j-spring-boot3</artifactId></dependency># application.ymlresilience4j.circuitbreaker:instances:pricing:slidingWindowSize: 20failureRateThreshold: 50waitDurationInOpenState: 30spermittedNumberOfCallsInHalfOpenState: 5@Service @RequiredArgsConstructorpublic class PricingFacade {private final PricingClient client;@CircuitBreaker(name = "pricing", fallbackMethod = "fallback")@Retry(name = "pricing")@TimeLimiter(name = "pricing")public CompletableFuture<Quote> quote(List<LineItem> items) { return client.quote(items); }CompletableFuture<Quote> fallback(List<LineItem> items, Throwable t) {return CompletableFuture.completedFuture(Quote.cached(items));}}
Ready to mark this lesson complete?Track your journey across the entire course.