InterviewSolution
| 1. |
What is Circuit Breaker Pattern? |
|
Answer» Microservices often need to make remote network calls to another microservices running in a different process. Network calls can fail due to many reasons, including-
This can lead to cascading failures in the calling service due to threads being blocked in the hung remote calls. A circuit breaker is a piece of software that is used to solve this problem. The basic idea is very simple - wrap a potentially failing remote call in a circuit breaker object that will monitor for failures/timeouts. Once the failures reach a certain threshold, the circuit breaker trips, and all further calls to the circuit breaker return with an error, without the PROTECTED call being made at all. This mechanism can protect the cascading effects of a single component failure in the system and provide the option to gracefully downgrade the functionality. A typical use of circuit breaker in microservices architecture LOOKS like the following diagram- Typical Circuit Breaker Implementation Here a REST client calls the Recommendation Service which further communicates with Books Service using a circuit breaker call wrapper. As soon as the books-service API calls starts to fail, circuit breaker will trip (open) the circuit and will not make any further call to book-service until the circuit is CLOSED again. Martin Fowler has beautifully explained this phenomenon in detail on his blog. Martin Fowler on Circuit Breaker Pattern : https://martinfowler.com/bliki/CircuitBreaker.html |
|