BackoffStrategies Class
- Namespace
- Kampute.HttpClient
- Assembly
- Kampute.HttpClient.dll
Definition
Provides a collection of factory methods for creating instances of different retry strategies.
public static class BackoffStrategies- Inheritance
- object
- BackoffStrategies
Remarks
Properties
None
Gets a strategy where no retry attempts are made.
public static IHttpBackoffProvider None { get; }Property Value
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy of no retry attempts.
Remarks
This strategy schedules no retry attempts, making it ideal for operations where failure handling is immediate or managed through other means.
Methods
Dynamic(Func<HttpRequestErrorContext, IRetryStrategy>)
Creates an instance of DynamicBackoffStrategy with a dynamic strategy factory based on the context of a failed HTTP request.
public static IHttpBackoffProvider Dynamic(Func<HttpRequestErrorContext, IRetryStrategy> strategyFactory)Parameters
strategyFactoryFunc<HttpRequestErrorContext, IRetryStrategy>- A factory function that creates IRetryStrategy instances based on the failed HTTP request context.
Returns
- IHttpBackoffProvider
- An instance of DynamicBackoffStrategy.
Exceptions
- ArgumentNullException
- Thrown if
strategyFactoryisnull.
Remarks
This strategy offers the highest flexibility by dynamically scheduling retries based on the specific context of a failure. It adapts to the nature of encountered errors, making it ideal for complex systems with varied types of transient failures that cannot be effectively handled by a static retry strategy.
Dynamic(Func<HttpRequestErrorContext, IRetryScheduler>)
Creates an instance of DynamicBackoffStrategy with a dynamic scheduler factory based on the context of a failed HTTP request.
public static IHttpBackoffProvider Dynamic(Func<HttpRequestErrorContext, IRetryScheduler> schedulerFactory)Parameters
schedulerFactoryFunc<HttpRequestErrorContext, IRetryScheduler>- A factory function that creates IRetryScheduler instances based on the failed HTTP request context.
Returns
- IHttpBackoffProvider
- An instance of DynamicBackoffStrategy.
Exceptions
- ArgumentNullException
- Thrown if
schedulerFactoryisnull.
Remarks
This strategy offers the highest flexibility by dynamically scheduling retries based on the specific context of a failure. It adapts to the nature of encountered errors, making it ideal for complex systems with varied types of transient failures that cannot be effectively handled by a static retry strategy.
Exponential(uint, TimeSpan, double)
Creates a strategy that performs multiple retry attempts with delays increasing exponentially between each attempt, up to a specified maximum number of retry attempts.
public static IHttpBackoffProvider Exponential(uint maxAttempts, TimeSpan initialDelay, double rate = 2)Parameters
maxAttemptsuint- The maximum number of retry attempts.
initialDelayTimeSpan- The delay before the first retry attempt.
ratedouble optional- The rate at which the delay increases for each subsequent retry attempt.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy with delays increasing exponentially between each attempt, up to a specified maximum number of retry attempts.
Exceptions
- ArgumentOutOfRangeException
- Thrown if
rateis less than 1.
Remarks
This strategy performs multiple retry attempts with delays increasing exponentially between each attempt. It is suitable for aggressively minimizing the impact on systems by rapidly increasing wait times between retry attempts.
Exponential(TimeSpan, TimeSpan, double)
Creates a strategy that performs multiple retry attempts with delays increasing exponentially between each attempt, up to a specified timeout.
public static IHttpBackoffProvider Exponential(TimeSpan timeout, TimeSpan initialDelay, double rate = 2)Parameters
timeoutTimeSpan- The maximum time to spend retrying.
initialDelayTimeSpan- The delay before the first retry attempt.
ratedouble optional- The rate at which the delay increases for each subsequent retry attempt.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy with delays increasing exponentially between each attempt, up to a specified timeout.
Exceptions
- ArgumentOutOfRangeException
- Thrown if
rateis less than 1.
Remarks
This strategy performs multiple retry attempts with delays increasing exponentially between each attempt, up to a specified timeout. It is suitable for aggressively minimizing the impact on systems by rapidly increasing wait times between retry attempts, while enforcing a maximum time limit for retrying.
Fibonacci(uint, TimeSpan)
Creates a strategy that performs multiple retry attempts with delays following the Fibonacci sequence between each attempt, up to a specified maximum number of retry attempts.
public static IHttpBackoffProvider Fibonacci(uint maxAttempts, TimeSpan initialDelay)Parameters
maxAttemptsuint- The maximum number of retry attempts.
initialDelayTimeSpan- The delay before the first retry attempt.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy with delays following the Fibonacci sequence between each attempt, up to a specified maximum number of retry attempts.
Remarks
This strategy performs multiple retry attempts with delays following the Fibonacci sequence between each attempt. It provides a balanced choice between aggressive and cautious retry pacing, suitable for a wide range of scenarios.
Fibonacci(TimeSpan, TimeSpan)
Creates a strategy that performs multiple retry attempts with delays following the Fibonacci sequence between each attempt, up to a specified timeout.
public static IHttpBackoffProvider Fibonacci(TimeSpan timeout, TimeSpan initialDelay)Parameters
timeoutTimeSpan- The maximum time to spend retrying.
initialDelayTimeSpan- The delay before the first retry attempt.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy with delays following the Fibonacci sequence between each attempt, up to a specified timeout.
Remarks
This strategy performs multiple retry attempts with delays following the Fibonacci sequence between each attempt, up to a specified timeout. It provides a balanced choice between aggressive and cautious retry pacing, suitable for a wide range of scenarios, while enforcing a maximum time limit for retrying.
Fibonacci(uint, TimeSpan, TimeSpan)
Creates a strategy that performs multiple retry attempts with delays following the Fibonacci sequence between each attempt, up to a specified maximum number of retry attempts.
public static IHttpBackoffProvider Fibonacci(uint maxAttempts, TimeSpan initialDelay, TimeSpan delayStep)Parameters
maxAttemptsuint- The maximum number of retry attempts.
initialDelayTimeSpan- The delay before the first retry attempt.
delayStepTimeSpan- The fixed amount of time that is scaled by the Fibonacci sequence and added to the initial delay for each subsequent retry attempt.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy with delays following the Fibonacci sequence between each attempt, up to a specified maximum number of retry attempts.
Remarks
This strategy performs multiple retry attempts with delays following the Fibonacci sequence between each attempt. It provides a balanced choice between aggressive and cautious retry pacing, suitable for a wide range of scenarios.
Fibonacci(TimeSpan, TimeSpan, TimeSpan)
Creates a strategy that performs multiple retry attempts with delays following the Fibonacci sequence between each attempt, up to a specified timeout.
public static IHttpBackoffProvider Fibonacci(TimeSpan timeout, TimeSpan initialDelay, TimeSpan delayStep)Parameters
timeoutTimeSpan- The maximum time to spend retrying.
initialDelayTimeSpan- The delay before the first retry attempt.
delayStepTimeSpan- The fixed amount of time that is scaled by the Fibonacci sequence and added to the initial delay for each subsequent retry attempt.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy with delays following the Fibonacci sequence between each attempt, up to a specified timeout.
Remarks
This strategy performs multiple retry attempts with delays following the Fibonacci sequence between each attempt, up to a specified timeout. It provides a balanced choice between aggressive and cautious retry pacing, suitable for a wide range of scenarios, while enforcing a maximum time limit for retrying.
Linear(uint, TimeSpan)
Creates a strategy that performs multiple retry attempts with delays increasing linearly between each attempt, up to a specified maximum number of retry attempts.
public static IHttpBackoffProvider Linear(uint maxAttempts, TimeSpan initialDelay)Parameters
maxAttemptsuint- The maximum number of retry attempts.
initialDelayTimeSpan- The delay before the first retry attempt.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy with delays increasing linearly between each attempt, up to a specified timeout.
Remarks
This strategy performs multiple retry attempts with delays increasing linearly between each attempt. It is optimal for reducing system load with gradually increasing wait times.
Linear(TimeSpan, TimeSpan)
Creates a strategy that performs multiple retry attempts with delays increasing linearly between each attempt, up to a specified timeout.
public static IHttpBackoffProvider Linear(TimeSpan timeout, TimeSpan initialDelay)Parameters
timeoutTimeSpan- The maximum time to spend retrying.
initialDelayTimeSpan- The delay before the first retry attempt.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy with delays increasing linearly between each attempt, up to a specified timeout.
Remarks
This strategy performs multiple retry attempts with delays increasing linearly between each attempt, up to a specified timeout. It is optimal for reducing system load with gradually increasing wait times, while enforcing a maximum time limit for retrying.
Linear(uint, TimeSpan, TimeSpan)
Creates a strategy that performs multiple retry attempts with delays increasing linearly between each attempt, up to a specified maximum number of retry attempts.
public static IHttpBackoffProvider Linear(uint maxAttempts, TimeSpan initialDelay, TimeSpan delayStep)Parameters
maxAttemptsuint- The maximum number of retry attempts.
initialDelayTimeSpan- The delay before the first retry attempt.
delayStepTimeSpan- The amount by which the delay increases for each subsequent retry attempt.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy of multiple attempts with a constant delay between each attempt, up to a specified timeout.
Remarks
This strategy performs multiple retry attempts with delays increasing linearly between each attempt. It is optimal for reducing system load with gradually increasing wait times.
Linear(TimeSpan, TimeSpan, TimeSpan)
Creates a strategy that performs multiple retry attempts with delays increasing linearly between each attempt, up to a specified timeout.
public static IHttpBackoffProvider Linear(TimeSpan timeout, TimeSpan initialDelay, TimeSpan delayStep)Parameters
timeoutTimeSpan- The maximum time to spend retrying.
initialDelayTimeSpan- The delay before the first retry attempt.
delayStepTimeSpan- The amount by which the delay increases for each subsequent retry attempt.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy with delays increasing linearly between each attempt, up to a specified maximum number of retry attempts.
Remarks
This strategy performs multiple retry attempts with delays increasing linearly between each attempt, up to a specified timeout. It is optimal for reducing system load with gradually increasing wait times, while enforcing a maximum time limit for retrying.
Once(TimeSpan)
Creates a strategy that performs a single retry attempt after the specified delay.
public static IHttpBackoffProvider Once(TimeSpan delay)Parameters
delayTimeSpan- The delay before the single retry attempt.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy of a single attempt after a specified delay.
Remarks
This strategy performs a single retry attempt after the specified delay. It is suitable for operations where one additional attempt may resolve a transient issue.
Once(DateTimeOffset)
Creates a strategy that performs a single retry attempt after the specified date and time.
public static IHttpBackoffProvider Once(DateTimeOffset after)Parameters
afterDateTimeOffset- The date and time after which the single retry attempt will be made.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy of a single attempt after a specified date and time.
Remarks
This strategy schedules a single retry attempt for a specified future point in time, ensuring operations are retried when certain conditions are likely met. If the specified time has already passed, it immediately schedules the retry attempt.
Uniform(uint, TimeSpan)
Creates a strategy that performs multiple retry attempts with a constant delay between each attempt, up to a specified maximum number of retry attempts.
public static IHttpBackoffProvider Uniform(uint maxAttempts, TimeSpan delay)Parameters
maxAttemptsuint- The maximum number of retry attempts.
delayTimeSpan- The constant delay between each retry attempt.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy of multiple attempts with a constant delay between each attempt, up to a specified maximum number of retry attempts.
Remarks
This strategy performs multiple retry attempts with a constant delay between each attempt. It is ideal for cases needing multiple attempts with predictable delays.
Uniform(TimeSpan, TimeSpan)
Creates a strategy that performs multiple retry attempts with a constant delay between each attempt, up to a specified timeout.
public static IHttpBackoffProvider Uniform(TimeSpan timeout, TimeSpan delay)Parameters
timeoutTimeSpan- The maximum time to spend retrying.
delayTimeSpan- The constant delay between each retry attempt.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider that defines a retry strategy of multiple attempts with a constant delay between each attempt, up to a specified timeout.
Remarks
This strategy performs multiple retry attempts with a constant delay between each attempt, up to a specified timeout. It is ideal for cases needing multiple attempts with predictable delays, but with a maximum time limit for retrying.

This class offers various retry strategies to manage transient failures in distributed systems for flexible, use case-specific configuration.
Strategies are ordered by increasing delay approach:
The
Dynamicstrategy stands apart, as its delay can vary based on the context of the failure. It tailors retry attempts to specific conditions, such as error type or system load, offering the flexibility to adapt retry logic for optimal outcomes. This approach is most useful in complex systems where a static retry strategy may not adequately address the nuances of different failure scenarios.