# Circuit Breaker
Is a computer science pattern for dealing with remote services that may fail originally described by Michael T. Nygard in his book *Release It! Design and Deploy Production-Ready Software*.
Say you're dealing with a remote server with expensive calls (both for you and for the server) such that if the server is overloaded, and timeouts occur, you still incur costs for invoking it. If that's the case, you can direct your calls through an object (called the circuit breaker) whose job, aside from redirecting the calls, is to monitor the server's health. If it detects that the server is overloaded (timeouts, actual errors, etc), it can 'trip' and return to the caller right away. From then on, the circuit breaker stays 'tripped' and any future calls are not redirected to the server (but return with an error right away) until a certain cool-down period elapses. During that time you don't incur any client costs for calling the server (memory, threads) and you reduce server load too.
While the circuit breaker is in its 'tripped' state you can either respond with stale data or errors, depending on what is suitable for your specific solution.
The circuit breaker is an excellent place for service monitoring and logging.
For C# implementation see [[Circuit Breaker in csharp|Circuit Breaker in C#]].
## Sources
- Martin Fowler. [Circuit Breaker](https://www.martinfowler.com/bliki/CircuitBreaker.html).