Concept Simulators / Keeping a service up
Retries and circuit breakers
Why retries fix blips and worsen outages, and how a breaker helps recovery.
On the roadmap:Intermediate 路 step 6: Protecting services
Settings
A failed request is just an error. Nothing extra is sent.
Requests that failed
1,630
Peak load on the service
1.0x normal
Back to normal
29 s after
Breaker open
no breaker
The service was down for 10 seconds and users saw errors until it recovered, 29 seconds after it came back. Try retrying, and then a circuit breaker.
One minute, second by second
requests per second
In plain words
When a call to another service fails, the easy fix is to try again. That fixes the odd blip, but when the other service is really down or overloaded, every retry is extra load on something already struggling. A circuit breaker stops calling for a while so it can recover.
Why it matters
Many large outages are made worse by well-meant retries. Here users send steady traffic to a service that goes down for a while and comes back cold, answering a little more each second. You can see what each policy does to the load, to the users, and to how soon it all returns to normal.
How real systems do it
The simulation is a simplified model. Here is what production systems add or do.
- Backoff with jitter, which spreads retries over time with some randomness, is the standard advice from AWS for clients that retry against a shared service.
- Netflix popularised the circuit breaker with Hystrix, which is now in maintenance mode. Resilience4j is a common successor on the JVM, and service meshes such as Envoy can break circuits too.
- A breaker has three states: closed (normal), open (calls fail at once), and half open (a few probes test whether the service is back).
- Some libraries cap retries with a retry budget, a limit on how large a share of calls may be retries, so that retrying cannot multiply the load. Only retry operations that are safe to repeat, such as those with an idempotency key.
Study: Retries and circuit breakers
Once you have played with it, learn the same idea from people who build these systems. Watch first for the picture, then read for the detail.
18 minHow to avoid cascading failures in a distributed system 馃挘馃挜馃敟
Gaurav Sen 路 127K views
Then
12 minIntroduction to circuit breaker in microservices (for beginners)sudoCODE 路 84K views
10 minCircuit Breaker Pattern in MicroservicesByteMonk 路 73K views
8 minDistributed Systems 2.4: Fault toleranceMartin Kleppmann: Distributed Systems Lectures 路 56K views
24 minHow to safely and gracefully handle timeouts in a microservicesArpit Bhayani 路 39K views