Tripping the circuit

Circuit breaker pattern

This is probably one of the most useful “cloud” patterns out there and it is fairly easy to implement.
There are great articles and implementations, like Polly, already on the internet about this pattern so why another one?

Κρείττον οψιμαθή είναι ή αμαθή.
Socrates 469-399 BC., Philosopher

Better too have learned lately than never, as he tried to explain why he learned to play guitar in his old age.

I have learned better by reading, implementing and writing about something so stick with me.


Almost every application communicate with other services or resources, and they fail…

The reasons:

When this happen our system becomes unstable, unreliable, brittle and failures cascade.

Let’s go with an example of a failing remote service, let’s say we have the following scenario

What happens in our application?

The above is a simplified example but is not that far fetched.


Using a circuit breaker can improve the stability and resilience of our application. The circuit is actually a state machine with 3 states

For deeper knowledge on the pattern please read the following excellent articles


By using a circuit breaker we have the following benefits:


There are two implementation of the circuit breaker. They share the same philosophy but are written in C# and Go. Both implementations have a setting provider interface which can be implemented in order to get the settings from anywhere. There is a in-memory settings implementation which holds the settings in memory. Both implementation are key based which means that for every key the implementation provides a separate circuit which is actually the state. The following setting exist for each key:

The C# implementation can be found @ clouddotnet. The implementation is generic, asynchronous and thread safe and lock-free.
The Go implementation can be found @ gocloud. The implementation is idiomatic and “goroutine” safe.



My blog is hosted in github so for any change, improvement or fix you can either open a issue or submit a pull request.
The same goes for both implementations.

comments powered by Disqus