Skip to content

Resilience patterns · 5 of 9

Step 1 · The pattern

Every call borrows a thread

The API server answers each request by calling another service. While it waits for the reply, that request keeps one thread busy. Replies are quick, so only one or two of the twelve threads are in use at a time.

  • request / call
  • answered

In short

Circuit breakers & fallbacks: how it works and how it breaks

A server that calls other services keeps a thread busy for every call until the reply arrives. When one of those services turns slow, its calls stop finishing. A timeout puts a ceiling on each wait, but at high volume new calls arrive faster than old ones time out, so every thread ends up waiting on the same sick dependency. Requests that never needed it are then rejected as well, and one slow service has taken the whole server down. A circuit breaker watches the error rate of calls to each dependency. Past a threshold it opens and stops calling. Requests fail fast or receive a fallback instead, such as a cached copy, a default value or an empty list. Threads stay free and the struggling service gets room to recover. After a pause the breaker lets a single trial call through, and closes again only when one succeeds.

In Spring Boot

A circuit breaker and fallback with Resilience4j

application.yml + PricingClient.java
resilience4j.circuitbreaker:
  instances:
    pricing:
      slidingWindowType: COUNT_BASED
      slidingWindowSize: 20
      minimumNumberOfCalls: 10
      failureRateThreshold: 50
      waitDurationInOpenState: 10s
      permittedNumberOfCallsInHalfOpenState: 3

// PricingClient.java
@CircuitBreaker(name = "pricing", fallbackMethod = "lastKnownPrice")
public Price priceFor(String sku) {
  return http.getPrice(sku);
}

private Price lastKnownPrice(String sku, Throwable cause) {
  return priceCache.get(sku);
}

Once at least 10 of the last 20 calls are recorded and half of them failed, the breaker opens and calls go straight to the fallback. After 10 seconds it lets 3 trial calls through to decide whether to close again.

Gotcha: The defaults are a window of 100 calls and a minimum of 100, so a quiet service may never record enough calls to open. The fallback must be in the same class and take the same parameters plus one exception parameter, or it is not found.

Names checked against the official docs on 15 Nov 2026:

How this comes up in interviews

"One downstream service turns slow and your whole API server stops answering, even though every call has a timeout. Why, and how do you contain it?"

Then they ask

  1. What counts as a failure for the breaker, and what makes it open?
  2. The cool-down ends. How does the breaker find out whether the dependency has recovered?
  3. What do you return while the breaker is open, and which calls should fail instead of getting a fallback?

A strong answer covers

  • Each call holds a thread until the reply arrives. At high volume calls arrive faster than they time out, so every thread ends up waiting.
  • A circuit breaker watches the error rate of calls to each dependency and, past a threshold, opens and stops calling.
  • While it is open, requests fail fast or receive a fallback such as a cached copy, a default value or an empty list.
  • Threads stay free for requests that never needed the dependency, and the struggling service gets room to recover.
  • After a pause the breaker lets a single trial call through, and closes again only when one succeeds.

Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.

On one page: the track cheat sheet.

Last updated: Official documentation

Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.