The Circuit Breaker design pattern

Use Case

  • in case of failure, make sure that the failed service doesn’t affect the entire system
  • that can happen if the volume of calls to the failing service is high, and for each call we would need to wait for a timeout to occur before moving on
  • making the call to the failed service and waiting would use resources that would eventually make the overall system unstable

The circuit breaker pattern

  • behaves just like a circuit breaker in your home electrical system – it trips to protect you
  • calls to a microservice are wrapped in a circuit breaker object
  • when a service fails, the circuit breaker object allows subsequent calls to the service until a particular threshold of failed attempts is reached
  • at that point, the circuit breaker for that service trips, and any further calls will be short-circuited and will not result in calls to the failed service
  • this setup saves valuable resources and maintains the overall stability of the system

When the circuit breaker trips and the circuit is open, a fallback logic can be started instead. The fallback logic typically does little or no processing, and returns a value. Fallback logic must have little chance of failing, because it is running as a result of a failure to begin with.

Circut_breaker

More info: http://martinfowler.com/bliki/CircuitBreaker.html

[Source]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s