What is Circuit breakers, Explain with example?
What is Circuit breakers, Explain with example?
Student
The Anubhav portal was launched in March 2015 at the behest of the Hon'ble Prime Minister for retiring government officials to leave a record of their experiences while in Govt service .
Circuit breakers are a resilience pattern used in software systems to prevent repeated failures from cascading and taking down your whole app.
Think of it like the electrical circuit breaker in your house.
The simple idea
If a remote service (API, database, SMTP server, payment gateway, etc.) keeps failing:
Instead:
That’s a circuit breaker.
Why circuit breakers exist
Without a circuit breaker:
With a circuit breaker:
Circuit breaker states
A circuit breaker has three states:
Closed (normal state)
Open (tripped)
Half-Open (testing mode)
Real-world example
Imagine your Newsletter Worker Service sending emails:
With a circuit breaker:
Circuit breaker vs Retry
These two work together, not against each other:
Best practice:
Circuit breakers in .NET (Polly)
In .NET, circuit breakers are usually implemented using Polly.
Conceptually:
This means:
When should you use circuit breakers?
Use them when calling:
Avoid them for:
Key takeaway