Skip to main content
PreparationZone Logo
PrepZone

Circuit Breakers and Retries

Resilience4j circuit breakers, retries, rate limiters and bulkheads.

Pass checkpoint below

Why this matters

  • When the payment service takes 30 seconds to respond, every checkout thread blocks — thread pools exhaust and the catalog API goes down too, even though catalog itself is healthy.
  • Circuit breakers trip after repeated failures, returning a fallback immediately instead of waiting for timeouts on every request.
  • Retries with exponential backoff recover from transient blips; rate limiters protect your own services from being overwhelmed by retries from callers.

Circuit breaker

L1 · Fresher

Stop calling a failing payment service after thresholds — fail fast and protect BookStore threads.

Resilience4j

L2 · Intermediate

Configure circuit breaker, retry, rate limiter, and bulkhead via annotations or functional APIs.

Retry with backoff

L3 · Advanced

Retry only idempotent operations with jittered backoff — never retry POST without idempotency keys.

Bulkhead isolation

L4 · Expert

Separate thread pools for catalog vs checkout so one slow dependency cannot exhaust all workers.

ClosedNormal traffic
OpenFail fast
Half-openProbe request
Open circuit fails fast; half-open probes recovery.

Resilience4j patterns in Spring Boot

  • Circuit Breaker — opens after failure threshold; short-circuits calls while upstream recovers.
  • Retry — re-attempts failed calls with configurable backoff and max attempts.
  • Rate Limiter — caps requests per time window to protect downstream services.
  • Bulkhead — isolates thread pools so one slow dependency cannot starve others.
  • Time Limiter — enforces a maximum duration on any call, including async ones.

Dependencies and configuration

Java
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
</dependency>

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 3 sections

  • Circuit breaker with fallback
  • Declarative resilience with annotations
  • Bulkhead isolation

Test yourself

Answer these before moving on — recall is what makes it stick.