Cloud Patterns - Circuit Breaker Pattern

Author: Arun Verma
Category: Cloud
Section: Tech.Architecture
Related Questions: 0 Login to Bookmark
Submitted On: 7/10/2017
Published On: 7/12/2017
ABSTRACT: This article discusses about the basics of cloud patterns in general along with an example of Circuit Breaker Pattern.

We share resources on cloud as we share space on road. Efficient sharing mechanism improves efficiency to a great extent.

As we all know that cloud computing is a type of Internet-based computing that provides shared computer processing resources and data to computers and other devices on demand. It is a model for enabling ubiquitous, on-demand access to a shared pool of configurable computing resources which can be rapidly provisioned and released with minimal management effort.

Cloud computing relies on sharing of resources to achieve coherence and economy of scale, similar to a utility (like the electricity grid) over an electricity network. Widespread adoption of hardware virtualization, service-oriented architecture, and autonomic and utility computing led to a growth in cloud computing.

The entire arrangement enables Information Technology (IT) teams to more rapidly adjust resources to meet fluctuating and unpredictable business demands in terms of increasing load on computing resources. Companies can hence scale up as computing needs increase, and then scale down again as demands decrease.

In order to achieve aforementioned scenario and leverage full power of cloud infrastructure, developers need to implement cloud design patterns based solution.

Circuit Breaker Pattern

One such design pattern is known as Circuit Breaker Pattern. It handle faults that may take a variable amount of time to rectify when connecting to a remote service or resource. The faults may occur due to slow network connections, timeouts, or the resources being overcommitted or temporarily unavailable. This pattern can improve the stability and resiliency of an application.

This pattern can prevent an application repeatedly trying to execute an operation that is likely to fail, allowing it to continue without waiting for the fault to be rectified or wasting CPU cycles while it determines that the fault is long lasting. The Circuit Breaker pattern also enables an application to detect whether the fault has been resolved. If the problem appears to have been rectified, the application can attempt to invoke the operation.

A circuit breaker acts as a proxy for operations that may fail. The proxy should monitor the number of recent failures that have occurred, and then use this information to decide whether to allow the operation to proceed, or simply return an exception immediately.

Proxy can be implemented as a state machine with the following states that mimic functionality of an electrical circuit breaker:

  • Closed: Request from the application is routed through to the operation. Proxy maintains a count of the number of recent failures, and if the call to the operation is unsuccessful the proxy increments this count. If the number of recent failures exceeds a specified threshold within a given time period, the proxy is placed into the Open state. At this point the proxy starts a timeout timer, and when this timer expires the proxy is placed into the Half-Open state.
  • Open: The request from the application fails immediately and an exception is returned to the application.
  • Half-Open: Limited number of requests from the application are allowed to pass through and invoke the operation. If these requests are successful, it is assumed that the fault that was previously causing the failure has been fixed and the circuit breaker switches to the Closed state (the failure counter is reset). If any request fails, the circuit breaker assumes that the fault is still present so it reverts back to the Open state and restarts the timeout timer to give the system a further period of time to recover from the failure.

Go to Top
Cloud Patterns - Circuit Breaker Pattern

Related Questions...(0) Ask A Question

Ask a Question

Go to Top