# Retry vs Circuit Breaker: When to Use Each

> Retry and circuit breaker assume opposite things about a failure. Retries assume it is transient and try again; breakers assume it is systemic and stop calling the dependency. When you use both, the order decides which one sees a failure first. Here is the Polly v8 pipeline that composes them, with the breaker inside the retry.

Published: 2026-11-26. Author: Milan Jovanović. Topic: Resilience. Tags: aspnetcore, dotnet, polly, resilience.

Canonical: https://milanjovanovic.tech/blog/retry-vs-circuit-breaker

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**](https://milanjovanovic.tech/blog/polly-v8-resilience-pipelines) a retry is a strategy on a resilience pipeline:

```bash
dotnet add package Polly.Core
```

```csharp
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**](https://milanjovanovic.tech/blog/exponential-backoff-jitter-dotnet): `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).

```csharp
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**.

| Concern | Retry | Circuit breaker |
| --- | --- | --- |
| Assumes the failure is | Transient | Systemic |
| Scope | One operation | Every call to one dependency |
| What it does | Re-attempts the call after a backoff delay | Stops calling for the break duration and fails fast |
| Typical trigger | A network blip, a failover, a momentary 503 | A dependency that is down, overloaded, or degraded |
| Watch out for | Duplicate side effects on non-idempotent calls | Opening on too little evidence if MinimumThroughput is too low |
| Position when combined | Outer strategy | Inside 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.**

```csharp
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](https://milanjovanovic.tech/blogs/articles/retry-vs-circuit-breaker/retry-breaker-pipeline.png)

## 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**](https://milanjovanovic.tech/blog/fallback-pattern-polly-dotnet) for when everything fails.
Here `retryOptions` and `breakerOptions` hold the same `RetryStrategyOptions` and `CircuitBreakerStrategyOptions` as the previous example:

```csharp
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**](https://milanjovanovic.tech/blog/timeout-strategy-dotnet).
For a deeper treatment of the individual patterns, I've written up the [**retry pattern with Polly**](https://milanjovanovic.tech/blog/retry-pattern-dotnet-polly) and the [**circuit breaker pattern**](https://milanjovanovic.tech/blog/circuit-breaker-pattern-dotnet) on their own.
The broader set of these is covered in [**building resilient cloud applications with .NET**](https://milanjovanovic.tech/blog/building-resilient-cloud-applications-with-dotnet), and for HTTP you often get the whole stack from `AddStandardResilienceHandler` as shown in [**overriding the default resilience handlers**](https://milanjovanovic.tech/blog/overriding-default-http-resilience-handlers-in-dotnet).

## 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.
