Hystrix – circuit breaker

Another important pattern in Hystrix is that of a circuit breaker. The key idea is for a service to fail fast if a dependent resource is not available, as opposed to waiting for a timeout/error for each service invocation during the period in which the dependent resource is down. The name comes from the familiar pattern of a circuit opening under a high load to protect internal resources. When requests start to fail for a dependent service, the hystrix library keeps count of the number of failures within a time window. If the failures are greater than a threshold (n number of failed requests within a given time or requests taking too long), the circuit for that dependency is moved to the Open state. In this state, all requests are failed. Periodically, after some configured amount of time, a single request is let through (Half-Open state). If the request fails, the circuit breaker returns to Open. If the request succeeds, the circuit breaker transitions to Closed and operations continue normally. To summarize, the states of the circuit can be in the following states:

  • Closed: Operations that involve the dependency can happen normally.
  • Open: Whenever a failure has been detected, the circuit opens, making sure that the service short-circuits requests involving the dependency and responds immediately.
  • Half-open: Periodically, the circuit breaker lets a request pass through to gauge the health of the dependent service.

The circuit breaker workflow and fallback interactions are depicted here:

(Reference: Netflix blog)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset