Table of Contents

Class ExponentialBackoff

Namespace
Excalibur.Dispatch.Resilience
Assembly
Excalibur.Dispatch.dll

Provides a stateless, allocation-free exponential backoff delay calculation.

public static class ExponentialBackoff
Inheritance
ExponentialBackoff
Inherited Members

Remarks

This is the single source of truth for the exponential backoff math used by transports and retry strategies. The computed delay is exactly min(BaseDelay * Multiplier^(attempt-1), MaxDelay).

It computes the NOMINAL delay and applies no randomisation, which is what makes it genuinely pure. It previously applied a symmetric jitter band here, and the "pure and total" claim below was false while it did -- the method called Shared, so a caller who read the documentation and cached a result got a value the next call would not reproduce. Randomisation now belongs solely to the calculator obtained from BackoffCalculatorFactory, so there is one jitter implementation in this package rather than a second one reachable through a flag on a value type.

The function is pure and total: same inputs, same output, and it never throws. Out-of-range inputs are clamped (see Calculate(int, in BackoffParameters)) rather than rejected.

Methods

Calculate(int, in BackoffParameters)

Calculates the exponential backoff delay for the given attempt.

public static TimeSpan Calculate(int attempt, in BackoffParameters parameters)

Parameters

attempt int

The 1-based retry attempt number. Values below 1 are treated as 1.

parameters BackoffParameters

The backoff schedule parameters.

Returns

TimeSpan

A non-negative delay equal to min(BaseDelay * Multiplier^(attempt-1), MaxDelay).

Remarks

This method is pure and total: it never throws, and the same arguments always produce the same delay. attempt is clamped to at least 1, Multiplier is clamped up to 1.0 when smaller, the result is capped at MaxDelay and is never negative. To randomise the result, use the calculator from BackoffCalculatorFactory rather than post-processing this value: it samples BELOW the already-capped delay, which is the ordering that keeps jitter alive once the nominal ladder passes the cap.