7. Failing and Recovering Quickly with the Circuit Breaker Flashcards
What does the Circuit Breaker policy allow us to do?
It allows us to monitor requests sent to a remote service and stop requests before they are sent if the remote service is struggling or has been returning errors.
How does the Circut Breaker policy help the local apps vs the remote apps?
It helps the local apps by preventing a build-up of requests and helps the remote service by reducing the number of requests it receives.
In what application structure is the Circuit Breaker policy most popular.
It is the most popular in microservices architecture.
Is the Circuit Breaker
a proactive or a reactive policy?
It’s a reactive policy.
What can be said about the Circuit Breaker
policy with regards to stability?
It helps stabilise local and remote apps by cutting the connection between them.
What can be said about the concepts of “open” and “closed” for a Circut Breaker
?
We can think of them as an electrical circuit.
If there is an opening, no electricity (or in our case, no requests) will flow. But if the circuit is closed, electricity (requests) will flow.
What are the two implementations of the Circuit Breaker
policy that Polly offers?
- The
Original
one, introduced in Polly v4.0
2. The Advanced
one, introduced in Polly v4.2
How does the Original Circuit Breaker
work?
It sums the number of consecutive failures and if that number reaches some threshold, the circuit is opened for a specified duration, thus preventing any further requests from being sent by the given policy.
What can be said about the throughput needed to open the circuit for the Original Circuit Breaker
?
No minimum throughput is needed. So, if we reach the specified threshold for errors, it doesn’t matter if we reached it in a second, a minute, or several hours.
How does the Advanced Circuit Breaker
work?
It monitors the number of failures as a percentage of the total number of requests over a rolling time window. And if there are more failures than a specified threshold, the circuit breaks for a specified duration.
What can be said about the throughput needed to open the circuit for the Advanced Circuit Breaker
?
The Advanced Circuit Breaker
allows a minimum throughput threshold. This means that we can specify a time period in which the specified threshold for errors must be reached in order for the circuit to be broken.
What can be said about calling a single vs multiple endpoints using a Circuit Breaker
?
The Circuit Breaker
policy can be used to call a single remote endpoint or multiple remote endpoints.
In the first case, if the circuit breaks, you will be disconnected from just one endpoint. But in the latter case, if the circuit breaks, and and all remote services you are connecting to using that policy will be unavailable.
What are the states that a Circuit Breaker might be in?
- Open
- Closed
- Half-open
What is the half-open Circuit Breaker state?
It’s the state the breaker moves to after open. This can be seen as a trial state.
If the first request sent via the policy fails, the circuit is immediately set back to the open state and no requests will be sent for another period as specified in the duration of the break. But, if the first request succeeds., the circuit is closed and the request flows as normal.
What state does the Circuit Breaker policy start in, and what changes in its state does it go through when a request fails?
It starts in the closed state and can go through the following changes:
- Closed to open when a problem is detected.
- Open to half-open when the duration of the break is reached.
3a. Half-open back to open if the first request at half-open fails.
3b. Half-open to closed if the first request at half-open succeeds.