Adding Circuit Breaker to the service calls.
Circuit Breaker provides a mechanism to fail fast in case there is any failure in one of our micro-services to prevent cascading failure.
Implemented using Istio.
ARCHITECTURE:
As circuit breaking applies to “real” mesh destinations in a load balancing pool, we configure circuit breaker thresholds in destination rules, with the settings applying to each individual host in the service. Hosts that continually return 5xx errors(or defined error) for API calls are ejected from the pool for a pre-defined period of time.
CODE SNIPPET: This configures upstream hosts to be scanned every 20 secs so that any host that fails 1 consecutive times with a 5xx (502, 503, etc) error code will be ejected for 2 minutes.
Refer here for more errors that can be customized for circuit breaking : https://istio.io/latest/docs/reference/config/networking/destination-rule/
CB conditions can be applied at :
- consecutiveLocalOriginFailures
- consecutiveGatewayErrors
- consecutive5xxErrors
- Ensure circuit breaks only for that service which is down.
- Ensure Retries are handled well with circuit breakers.