concept circuit breaker in category akka

appears as: circuit breakers, circuit breaker, A circuit breaker, The circuit breaker, circuit breaker
Reactive Design Patterns

This is an excerpt from Manning's book Reactive Design Patterns.

The back end so far consists of a multitude of services whose partitioning and relationships resulted from the application of the Simple Component pattern. By itself, this pattern does not provide the checks and balances that keep the architecture from devolving into a large mess where every service talks with almost every other service. Such a system would be hard to manage even with perfect individual failure handling, circuit breakers, and flow control; it certainly would not be possible for a human to understand it in its entirety and confidently make changes to it. This scenario has informally been called the big ball of mud.

In order to stop this effect from propagating across the entire chain of user–service relationships, users need to shield themselves from the overwhelmed service during such time periods. The way to do this is well known in electrical engineering: install a circuit breaker, as shown in figure 2.12.

Figure 2.12. A circuit breaker in electrical engineering protects a circuit from being destroyed by a current that is too high. The software equivalent does the same thing for a service that would otherwise be overwhelmed by too many requests.
Listing 12.1. Using a circuit breaker to give a failed component time to recover
private object StorageFailedStorageFailed RuntimeExceptionextends RuntimeException private def sendToStorage(job: Job): Future[StorageStatus] = {   val f: Future[StorageStatus] = . . . #1   f.map { #2     case StorageStatus.Failed => throw StorageFailed #2     case other                => other #2   } } private val breaker = CircuitBreaker(     system.scheduler, #3     5, #4     300.millis, #5     30.seconds, #6   ) def persist(job: Job): Future[StorageStatus] =   breaker     .withCircuitBreaker(sendToStorage(job))     .recover {       case StorageFailed                  => StorageStatus.Failed       case _: TimeoutException            => StorageStatus.Unknown       case _: CircuitBreakerOpenException => StorageStatus.Failed     } #1 - Makes an asynchronous request to the storage subsystem #2 - Maps storage failures to Future failures to alert the breaker #3 - Used for scheduling timeouts #4 - Number of failures in a row #5 - Timeout for each service call #6 - Time before trying to close after tripping
Reactive Web Applications: With Play, Akka, and Reactive Streams

This is an excerpt from Manning's book Reactive Web Applications: With Play, Akka, and Reactive Streams.

Figure 1.9. Different states of a circuit breaker

In an electric circuit, a circuit breaker is an automatic switch that’s meant to protect the circuit from overload or short circuits. On an abstract level, it functions as illustrated in figure 1.9.

Figure 1.9. Different states of a circuit breaker
Figure 6.5. Diagram of a circuit breaker