A circuit breaker is a safety feature in an electronic device that, in the event of a short circuit, breaks the electricity flow and protects the device, or prevents any further damage to the surroundings. This exact idea can be applied to software design. When a dependent service is not available or not in a healthy state, a circuit breaker prevents calls from going to that dependent service and redirects the flow to an alternate path for a configured period of time.
In his famous book, Release It! Design and Deploy Production-Ready Software, Michael T. Nygard gives details about the circuit breaker. A typical circuit breaker pattern is shown in the following diagram:
As shown in the diagram, the circuit breaker acts as a state machine with three states.