Skip to content
Circuit Breaker pattern for .NET
C# F# Other
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.
.nuget Update FAKE May 19, 2017
build Update FAKE May 19, 2017
samples/CircuitBreaker.Net.Sample Move NuGet properties to csproj Nov 20, 2017
src Move NuGet properties to csproj Nov 20, 2017
tests/CircuitBreaker.Net.Tests .NET 4.6 seems consistent to fail here via dotnet test -f net46; it's… Nov 20, 2017
.gitignore Initial commit Sep 3, 2015
.travis.yml Change file permissions in git Mar 11, 2016
CircuitBreaker.Net.sln Migrate to net standard 1.3 and upgrade test and sample projects to n… Nov 14, 2017
LICENSE Initial commit Sep 3, 2015 Update Jun 19, 2017


Build Status NuGet version


CircuitBreaker.Net is an implementation of the Circuit Breaker pattern for .NET. This pattern can improve the stability and resiliency of your application, especially in SOAP, microservices and distributed environments. The pattern serves two main purposes: to isolate communication with third-party services, so that your application won't be affected by their fails. And to react to third-party services' fails: it could be a pause, throttling, fail-over, default behavior, etc.
You can read about the pattern on MSDN or from Martin Fowler.


It's available via a nuget package
PM> Install-Package CircuitBreaker.Net

Example Usage

// Initialize the circuit breaker
var circuitBreaker = new CircuitBreaker(
    maxFailures: 3,
    invocationTimeout: TimeSpan.FromMilliseconds(100),
    circuitResetTimeout: TimeSpan.FromMilliseconds(10000));

    // perform a potentially fragile call through the circuit breaker
    // or its async version
    // await circuitBreaker.ExecuteAsync(externalService.CallAsync);
catch (CircuitBreakerOpenException)
    // the service is unavailable, failover here
catch (CircuitBreakerTimeoutException)
    // handle timeouts
catch (Exception)
    // handle other unexpected exceptions


There are not so many of them. I didn't find any that would suit me. Polly seems the most mature from all of them but it has a locking nature and it doesn't provide a way to specify a separate TaskScheduler to execute actions. But that's a crucial aspect when you call a third-party service, because those calls could stuff your "main" TaskScheduler. Actually none of those libraries support injection of a TaskScheduler. Helpful.CircuitBreaker by RokitSalad isn't thread safe. CircuitBreaker by kylos101 executes actions on the same thread. ManagedCircuitBreaker by AsherW is a fork of Polly with emphasize on IoC containers. The code provided on MSDN isn't production ready and just a piece of code. And so on so forth. So that the yet another library was born. I hope you will find it helpful. 😉

You can’t perform that action at this time.