Retry vs Circuit Breaker: When to Use Each

aspnetcoredotnetpollyresilience
Retry vs Circuit Breaker: When to Use Each

Retry and circuit breaker get lumped together as "resilience patterns," but they assume opposite things about a failure.

A retry is optimistic. It assumes the failure is transient: a dropped packet, a brief timeout, a node restarting. Try again and it'll probably work.

A circuit breaker is pessimistic. It assumes the failure is systemic: the dependency is down, overloaded, or degraded. Trying again right now just adds load to something that's already struggling.

Both can be right, on different failures, which is why real systems use both. Once you compose them, the order decides which one sees a failure first.

Retry: For Transient Failures

Use a retry when a failure is likely to resolve on its own within a short window. Network blips, a database failover, an HTTP 503 from a service that's momentarily busy: these are transient, and a second or third attempt often succeeds.

In Polly v8 a retry is a strategy on a resilience pipeline:

dotnet add package Polly.Core
using Polly;
using Polly.Retry;
using Polly.Timeout;

var retry = new ResiliencePipelineBuilder()
    .AddRetry(new RetryStrategyOptions
    {
        ShouldHandle = new PredicateBuilder()
            .Handle<HttpRequestException>()
            .Handle<TimeoutRejectedException>(),
        MaxRetryAttempts = 3,
        Delay = TimeSpan.FromMilliseconds(200),
        BackoffType = DelayBackoffType.Exponential,
        UseJitter = true
    })
    .Build();

Two things make a retry safe. First, exponential backoff with jitter: BackoffType = Exponential spaces attempts out so you don't hammer a recovering service, and UseJitter = true prevents every client retrying in lockstep and creating a thundering herd. Second, only retrying operations that are safe to repeat. A retry re-executes the call, so the target must be idempotent or you risk duplicate side effects.

But a retry has a blind spot. If the dependency is down, every client's retries pile more load onto it, right when it can least handle it. That's the failure model the breaker exists for.

Circuit Breaker: For Systemic Failures

A circuit breaker watches the failure rate across many calls. When failures cross a threshold, it "opens" and stops calling the dependency entirely for a cooldown, failing fast instead. After the cooldown it goes "half-open," lets a trial call through, and either closes (recovered) or re-opens (still broken).

using Polly.CircuitBreaker;

var breaker = new ResiliencePipelineBuilder()
    .AddCircuitBreaker(new CircuitBreakerStrategyOptions
    {
        ShouldHandle = new PredicateBuilder()
            .Handle<HttpRequestException>()
            .Handle<TimeoutRejectedException>(),
        FailureRatio = 0.5,                        // trip at 50% failures
        SamplingDuration = TimeSpan.FromSeconds(10), // over a 10s window
        MinimumThroughput = 10,                    // but only with >= 10 calls
        BreakDuration = TimeSpan.FromSeconds(30)   // stay open for 30s
    })
    .Build();

MinimumThroughput is easy to overlook. The breaker won't trip on 2 failures out of 2 calls, because that's not enough evidence. It needs at least 10 calls in the sampling window before the 50% ratio means anything. This stops a couple of unlucky failures from opening the circuit on a low-traffic endpoint.

A breaker does not fix a single bad call. It protects the dependency and gives your app a fast, predictable failure instead of a slow timeout when the dependency is down.

What Is the Difference Between Retry and a Circuit Breaker?

A retry operates on one operation and assumes the failure is transient. A circuit breaker operates on the stream of calls to a dependency and assumes the failure is systemic.

ConcernRetryCircuit breaker
Assumes the failure isTransientSystemic
ScopeOne operationEvery call to one dependency
What it doesRe-attempts the call after a backoff delayStops calling for the break duration and fails fast
Typical triggerA network blip, a failover, a momentary 503A dependency that is down, overloaded, or degraded
Watch out forDuplicate side effects on non-idempotent callsOpening on too little evidence if MinimumThroughput is too low
Position when combinedOuter strategyInside the retry, so it sees every attempt

They're complementary because the same dependency can produce both kinds of failure. A few transient blips are retry territory, and if the dependency goes down, the sustained failure rate is breaker territory.

Using Both: Order Decides Who Sees the Failure

When you compose retry and breaker, you have to decide which one wraps the other.

The circuit breaker goes inside the retry.

var pipeline = new ResiliencePipelineBuilder()
    .AddRetry(new RetryStrategyOptions
    {
        ShouldHandle = new PredicateBuilder()
            .Handle<HttpRequestException>()
            .Handle<TimeoutRejectedException>(),
        // Do NOT retry an open circuit.
        MaxRetryAttempts = 3,
        Delay = TimeSpan.FromMilliseconds(200),
        BackoffType = DelayBackoffType.Exponential,
        UseJitter = true
    })
    .AddCircuitBreaker(new CircuitBreakerStrategyOptions
    {
        ShouldHandle = new PredicateBuilder()
            .Handle<HttpRequestException>()
            .Handle<TimeoutRejectedException>(),
        FailureRatio = 0.5,
        SamplingDuration = TimeSpan.FromSeconds(10),
        MinimumThroughput = 10,
        BreakDuration = TimeSpan.FromSeconds(30)
    })
    .Build();

In a Polly pipeline, the first strategy you add is the outermost. So a call flows through the retry, then the breaker, then to your delegate.

The breaker must see every individual attempt. Placed inside, each of the retry's attempts passes through the breaker, so all four failed attempts (the first try plus three retries) count toward its failure ratio.

Flip the order (breaker outside retry) and the breaker sees one logical operation, no matter how many times the retry looped internally. Four failed attempts register as a single failure to the breaker, its ratio is understated, and it trips far too late.

And the retry must stop when the circuit is open. Once the breaker is open, it throws BrokenCircuitException immediately without calling the dependency. Because the retry's ShouldHandle only handles HttpRequestException and TimeoutRejectedException, it does not re-attempt on BrokenCircuitException. The exception propagates out, the retry stops instantly, and the caller fails fast.

If you accidentally retried the BrokenCircuitException, you'd use up every retry attempt on a strategy designed to fail fast. Leaving ShouldHandle unset does exactly that, because Polly's default retries every exception except OperationCanceledException.

While the dependency has occasional blips, the breaker stays closed and the retry absorbs them. Once failures become systemic, the breaker opens, and the retry stops immediately because it won't retry a circuit-open failure.

The retry sits outermost and the circuit breaker inside it, so the breaker observes every individual attempt; when the circuit opens it throws BrokenCircuitException, which the retry does not re-attempt, so the caller fails fast

Add a Timeout and a Fallback

Retry and breaker are two strategies in a fuller pipeline. In practice you bracket them with a timeout on the outside (so the whole retry sequence has a budget) and often a fallback for when everything fails. Here retryOptions and breakerOptions hold the same RetryStrategyOptions and CircuitBreakerStrategyOptions as the previous example:

var pipeline = new ResiliencePipelineBuilder()
    .AddTimeout(TimeSpan.FromSeconds(10)) // total budget for all attempts
    .AddRetry(retryOptions)
    .AddCircuitBreaker(breakerOptions)
    .AddTimeout(TimeSpan.FromSeconds(2))  // per-attempt timeout
    .Build();

The outer and inner timeouts are doing different jobs, which is the whole subject of timeout strategies in .NET. For a deeper treatment of the individual patterns, I've written up the retry pattern with Polly and the circuit breaker pattern on their own. The broader set of these is covered in building resilient cloud applications with .NET, and for HTTP you often get the whole stack from AddStandardResilienceHandler as shown in overriding the default resilience handlers.

Summary

Retry and circuit breaker assume opposite things about a failure.

  • Use retry for transient failures, with exponential backoff and jitter, only on idempotent operations. It fixes one bad call.
  • Use a circuit breaker for systemic failures. It watches the failure rate and stops calling a struggling dependency so retries can't storm it.
  • Use both, with the breaker inside the retry: the breaker counts every attempt toward its failure ratio, and the retry sees BrokenCircuitException and stops fast.
  • Never retry BrokenCircuitException. Keep it out of the retry's ShouldHandle so an open circuit fails the call immediately.

Frequently Asked Questions

What is the difference between retry and circuit breaker?

A retry re-attempts a failed operation, assuming the failure is transient and a second try will succeed. A circuit breaker tracks the failure rate across many calls and, once it crosses a threshold, stops calling the dependency for a cooldown period, assuming the failure is systemic and retrying would only add load.

Should I use retry and circuit breaker together?

Usually yes. They cover different failure modes: retry absorbs blips, the breaker protects a struggling dependency from a retry storm. Put the circuit breaker inside the retry so it observes every raw attempt, and so the retry sees BrokenCircuitException and stops instead of hammering an open circuit.

Why does the circuit breaker go inside the retry?

So the breaker counts each individual attempt toward its failure statistics. If the breaker were outside, a single logical retry sequence would look like one call to it, and its failure ratio would be wrong. Inside, it sees every attempt, trips accurately, and then short-circuits the retry by throwing BrokenCircuitException, which a retry that only handles transient exceptions does not re-attempt.

Does retrying an open circuit make things worse?

Only if you retry the BrokenCircuitException, which you should not. When the breaker is open, it fails fast without calling the dependency, so the dependency gets time to recover. Configure your retry to not handle BrokenCircuitException so an open circuit ends the attempt immediately rather than looping against a fast-failing strategy.

  • One slow downstream service can take out your entire application without returning a single error, by tying up the connections, memory, and blocked threads every other request needs. The bulkhead pattern caps how much of your capacity any single dependency can use. Here is how to build bulkheads in .NET with semaphores, Polly concurrency limiters, and partitioned HttpClients.

  • Polly v8 replaced policies with resilience pipelines: a rewritten core with allocation-free execution, built-in telemetry, and one composition model instead of PolicyWrap. Here is how the new API maps to the old one, how to register pipelines with DI, and why the order you add strategies changes what your pipeline does.

  • You have retries, circuit breakers, and timeouts configured. Have you ever seen them fire? Simmy injects faults, latency, and bad responses into your Polly pipelines so you can prove your resilience policies work before a real outage tests them. Fault injection often turns up a policy that was a misconfigured no-op.

Browse all Resilience guides →
Loading comments...

Go deeper

Whenever you're ready, there are 5 ways I can help you:

  1. Learn to deploy and run your apps on a VPS with Dokploy and Tailscale. Keep administration private, automate releases, and practice restoring backups, with source code and a runbook you can reuse.

  2. Join 5,000+ students in this comprehensive course that will teach you the system I use to ship production-ready applications using Clean Architecture. Learn how to apply the best practices of modern software architecture.

  3. Join 2,800+ engineers in this in-depth course that will transform the way you build modern systems. You will learn the best practices for applying the Modular Monolith architecture in a real-world scenario.

  4. Join 1,900+ students in this course that will teach you how to build production-ready REST APIs using the latest ASP.NET Core features and best practices. It includes a fully functional UI application that we'll integrate with the REST API.

  5. Join a community of 5,000+ engineers and software architects. You will also unlock access to the source code I use in my YouTube videos, early access to future videos, and exclusive discounts for my courses.

The .NET Weekly

One practical .NET tip, every Saturday.

Join 66,000+ engineers who read it. Free, and you can unsubscribe any time.