# Exponential Backoff and Jitter in .NET

> When a service blips, every client that failed retries on the same schedule: 2 seconds, 4 seconds, 8 seconds. The result is synchronized waves of traffic hammering a recovering dependency. Jitter breaks the synchronization, and Polly v8 supports it with a single property.

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

Canonical: https://milanjovanovic.tech/blog/exponential-backoff-jitter-dotnet

A dependency blips for two seconds.
Ten thousand in-flight requests fail.

Every one of those callers runs the same retry policy: wait 2 seconds, then 4, then 8.
So at T+2 seconds, ten thousand retries arrive *in the same instant*.
The recovering service, still cold, falls over again.
At T+6 the second synchronized wave lands, at T+14 the third, and then the retries run out.

The outage lasted 2 seconds.
Your retry policy stretched it to 14.
This is the thundering herd, and the fix costs one property in Polly v8.

![A single blip fails ten thousand requests at once; without jitter they all retry at the same instant and knock the recovering service over again, while with jitter the retry delays spread across the interval and the service recovers smoothly](https://milanjovanovic.tech/blogs/articles/exponential-backoff-jitter-dotnet/thundering-herd-jitter.png)

## Why Exponential Backoff Alone Isn't Enough

Backing off exponentially is the right instinct.
Immediate, fixed-interval retries pound a struggling dependency; doubling the delay (2s, 4s, 8s, 16s) gives it room to recover, which is why it's the default in the [**retry pattern**](https://milanjovanovic.tech/blog/retry-pattern-dotnet-polly).

But exponential backoff assumes that clients fail at *different* times.
In real outages they don't.
A deploy, a failover, a network partition fails everyone within the same few hundred milliseconds, and from that moment identical policies produce identical schedules.
Deterministic delays turn one spike into a series of spikes.
The exponent spaces the waves out; it does nothing to break them up.

The waves also *concentrate* load.
If the service can handle 1,000 requests per second, ten thousand retries spread over 10 seconds would be fine.
The same ten thousand compressed into one instant is 10x capacity.
Requests fail, and those failures schedule the next synchronized wave.

## Jitter Breaks the Synchronization

Jitter is randomness added to each delay so that clients desynchronize.
Instead of everyone sleeping exactly 4 seconds, each client sleeps a random duration drawn from a range around 4 seconds, and the retries spread out over that range.

The classic formulations, from the AWS Architecture Blog's analysis:

- **Full jitter**: sleep a random value between 0 and the exponential cap for this attempt. Maximum spread, and the least total work in AWS's simulations, though decorrelated jitter finished slightly sooner.
- **Equal jitter**: sleep half the exponential value plus a random amount up to the other half. A compromise that guarantees a minimum wait.
- **Decorrelated jitter**: compute each delay as a random function of the *previous* delay (`min(cap, random(base, prev * 3))`) instead of tracking an exponential schedule at all. It spreads retries smoothly and prevents clients from drifting back into sync across attempts.

You don't need to memorize the formulas, because Polly implements this for you.
Jittered retries arrive spread across the whole interval instead of at its edges.

## Polly v8: One Property

In [**Polly v8**](https://milanjovanovic.tech/blog/polly-v8-resilience-pipelines), jitter is built into the retry strategy:

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

```csharp
using Polly;
using Polly.Retry;

ResiliencePipeline pipeline = new ResiliencePipelineBuilder()
    .AddRetry(new RetryStrategyOptions
    {
        ShouldHandle = new PredicateBuilder()
            .Handle<HttpRequestException>()
            // HttpClient.Timeout throws this, wrapping a TimeoutException.
            .Handle<TaskCanceledException>(ex => ex.InnerException is TimeoutException),
        MaxRetryAttempts = 4,
        Delay = TimeSpan.FromSeconds(1),      // base delay
        BackoffType = DelayBackoffType.Exponential,
        UseJitter = true,                      // the one property
        MaxDelay = TimeSpan.FromSeconds(30)    // cap the growth
    })
    .Build();

await pipeline.ExecuteAsync(
    async ct => await httpClient.GetAsync("/api/orders", ct),
    cancellationToken);
```

With `BackoffType = Exponential` and `UseJitter = true`, Polly uses a decorrelated jitter formula (based on the Polly.Contrib.WaitAndRetry work) rather than multiplying the exponential delay by a random factor.
Two clients that fail at the same instant will follow visibly different schedules from the first retry onward.

Set `MaxDelay` too.
Exponential growth past 30 seconds rarely helps anyone; by then you want a [**circuit breaker**](https://milanjovanovic.tech/blog/retry-vs-circuit-breaker) making the stop/go decision instead of a sleeping retry loop.

For `HttpClient`, you usually don't even write this much, because `AddStandardResilienceHandler` from `Microsoft.Extensions.Http.Resilience` ships retries with exponential backoff and jitter already enabled:

```bash
dotnet add package Microsoft.Extensions.Http.Resilience
```

```csharp
builder.Services.AddHttpClient("orders", client =>
{
    client.BaseAddress = new Uri("https://orders.internal");
})
.AddStandardResilienceHandler();
```

If you need to tweak the defaults, you can [**override the standard resilience handlers**](https://milanjovanovic.tech/blog/overriding-default-http-resilience-handlers-in-dotnet) rather than rebuilding the pipeline from scratch.

## When the Server Tells You When to Retry

Jitter is for when you're guessing.
Sometimes you aren't: a `429` or `503` with a `Retry-After` header is the server stating exactly when to come back.
That signal should override the computed backoff, via `DelayGenerator`:

```csharp
using System.Net;
using Polly;
using Polly.Retry;

builder.Services.AddHttpClient("partner", client =>
{
    client.BaseAddress = new Uri("https://partner.internal");
})
.AddResilienceHandler("partner-retry", pipeline =>
{
    pipeline.AddRetry(new RetryStrategyOptions<HttpResponseMessage>
    {
        ShouldHandle = new PredicateBuilder<HttpResponseMessage>()
            .HandleResult(r => r.StatusCode == HttpStatusCode.TooManyRequests)
            .HandleResult(r => r.StatusCode == HttpStatusCode.ServiceUnavailable)
            .Handle<HttpRequestException>(),
        MaxRetryAttempts = 4,
        Delay = TimeSpan.FromSeconds(1),
        BackoffType = DelayBackoffType.Exponential,
        UseJitter = true,
        DelayGenerator = args =>
        {
            if (args.Outcome.Result?.Headers.RetryAfter?.Delta
                is TimeSpan retryAfter)
            {
                return ValueTask.FromResult<TimeSpan?>(retryAfter);
            }

            return ValueTask.FromResult<TimeSpan?>(null); // jittered backoff
        }
    });
});
```

`HttpRetryStrategyOptions`, which `AddStandardResilienceHandler` uses, already does this through its `ShouldRetryAfterHeader` property (`true` by default).

`Retry-After` can *re-synchronize* the herd, because the server hands every client the same number.
Well-behaved servers jitter the values they send.
If yours is the server, and it isn't jittering, vary the header value; if you're the client and the herd is yours (thousands of instances of the same worker), consider adding a small random pad on top of `Retry-After`.
More on the header semantics in **understanding rate limit headers**.

## The Same Math Applies Beyond HTTP

Everything above generalizes to any shared resource where the same event unblocks many concurrent clients:

- **Message consumers.** A poison queue or a broker restart unblocks every consumer at once. Redelivery delays need jitter for exactly the same reason HTTP retries do; I covered the mechanics in **message retry and backoff**.
- **Scheduled jobs.** A hundred instances running a sync job "every 5 minutes" from the same deploy timestamp produce a 100x spike every 5 minutes. Jitter the start offset.
- **Cache rebuilds.** When a hot key expires, every request that misses tries to rebuild it simultaneously. That variant is a cache stampede, and jittered TTLs are half of the standard fix.
- **Reconnect loops.** WebSocket and database reconnects after a failover are a textbook herd. SignalR's default reconnect schedule is deterministic, which is fine for small client counts and worth jittering for large ones.

## Verify It's Actually Working

A retry policy is easy to misconfigure into a no-op, and jitter is invisible in the happy path.
Two cheap checks:

Log the actual delays in `OnRetry` and confirm they're irregular:

```csharp
OnRetry = args =>
{
    logger.LogWarning(
        "Retry {Attempt} after {Delay}ms (outcome: {Outcome})",
        args.AttemptNumber + 1, // AttemptNumber is zero-based
        args.RetryDelay.TotalMilliseconds,
        args.Outcome.Exception?.GetType().Name ?? "result");

    return ValueTask.CompletedTask;
}
```

With a 2-second base delay, exact values of 2000, 4000, 8000 mean jitter isn't applied.
Jittered delays look irregular and don't always grow: one run with the same base delay logged 1273, 3406, 1750.

Better still, [**inject faults with Simmy**](https://milanjovanovic.tech/blog/chaos-engineering-simmy-dotnet) in staging and watch the request-rate graph on the dependency.
Synchronized retries show up as sharp spikes; jittered retries show up as a smooth elevated plateau.

## Summary

Exponential backoff decides *how long* to wait.
Jitter makes clients wait *different* amounts, which prevents synchronized retry waves.

In Polly v8 you need `BackoffType = DelayBackoffType.Exponential`, `UseJitter = true`, a sensible `MaxDelay`, and a `DelayGenerator` that honors `Retry-After` when the server sends one.
The standard resilience handler for `HttpClient` already uses jittered exponential backoff and honors `Retry-After` through `ShouldRetryAfterHeader`.
It leaves `MaxDelay` unset and relies on its 30-second total request timeout to bound the retries, so set `MaxDelay` yourself if you raise the retry count.

## Frequently asked questions

### What is jitter in retry logic?

Jitter is deliberate randomness added to retry delays. Without it, all clients that failed at the same moment retry at the same moments, producing synchronized traffic spikes against a recovering service. Randomizing each client's delay spreads the retries evenly over time.

### How do I enable jitter in Polly?

In Polly v8, set UseJitter = true on RetryStrategyOptions together with DelayBackoffType.Exponential. Polly then applies a decorrelated jitter formula that both randomizes and desynchronizes delays. You do not need to implement any jitter math yourself.

### What is decorrelated jitter?

Decorrelated jitter computes each delay from a random function of the previous delay rather than from a fixed exponential schedule. Compared to randomizing around the exponential curve, it produces a smoother spread of retries and avoids clients re-synchronizing after several attempts.

### What is the thundering herd problem?

It is the pattern where many clients, unblocked by the same event, act simultaneously and overwhelm a shared resource. In retry terms: a brief outage fails thousands of requests, and identical backoff schedules make all of them retry at the same instants, which can knock over the service each time it starts recovering.
