You are on page 1of 10

Circuit Breaker

2020-06-04
Author: Altaf Adil
MuleSoft Solutions Architect
Agenda

 Problem and Context

 Circuit Breaker Design Pattern

 Circuit Breaker Using AMQ

 Circuit Breaker using Custom Policy


Problem and Context

In a distributed environment, calls to remote resources and services can fail due
to:

1. Transient Faults - Slow network connections


Timeouts
Resources being overcommitted
Temporarily unavailable

These faults typically correct themselves after a short period of time and can be
handled using retry pattern.

2. Outages - Partial loss of connectivity


Complete failure of a service

These faults might take much longer to fix and might be pointless for an
application to continually retry an operation

All contents © MuleSoft Inc. 3


Solution

Circuit Breaker Design Pattern

A circuit breaker is an automatic switch that stops the flow of electricity in the event of a
failure. This sort of behavior is also useful when integrating with remote systems.

The Retry pattern enables an application to retry an operation in the expectation that it'll
succeed. The Circuit Breaker pattern prevents an application from performing an operation
that is likely to fail.

An application can combine both retry and circuit breaker patterns.

All contents © MuleSoft Inc. 4


Circuit Breaker Pattern

Closed: The request from the application is routed to


the operation.

Open: The request from the application fails


immediately and an exception is returned to the
application.

Half-Open: A limited number of requests from the


application are allowed to pass through and invoke
the operation.

All contents © MuleSoft Inc. 5


Circuit Breaker Using AMQ

All contents © MuleSoft Inc. 6


Circuit Breaker Using AMQ

Configure the Subscribe processor:


     Subscriber Type – Prefetch
     Acknowledgment Mode – Set to MANUAL

As the Acknowledgement Mode is set to MANUAL, we


need to Ack the message post successful completion of
the flow. So that the message doesn’t get retried

In case of Error Scenarios:

Technical Errors - Catch the error and subsequent to Error


Handling, Nack the message so that the message stays on
the queue and will be subsequently redelivered.

Functional Errors – Catch the error and subsequent to


Error Handling, Ack the message so that the message is
removed from the queue.

All contents © MuleSoft Inc. 7


Why create Custom Policy

Disadvantages of Circuit Breaker using AMQ


1. Using AMQ requires modification to existing API
2. AMQ is NOT included in base subscription
3. In manual ACK mode, a message may timeout before processing is completed,
resulting in possible duplicate processing
4. Error handling needs to be changed in existing code

Advantages of Custom Policy


5. Can be applied to existing APIs without modification
6. Reusable across an organization
7. Can be reprocessed instantly if Circuit Breaker is open by deleting OS entry
All contents © MuleSoft Inc. 8
Circuit Breaker Custom Policy Flow

All contents © MuleSoft Inc. 9


Thank You

You might also like