ExponentialBackoff

class ExponentialBackoff(val initialDelay: Duration = 100.milliseconds, val maxDelay: Duration = 10.seconds, val factor: Double = 2.0, val jitter: Boolean = true) : BackoffStrategy

A backoff strategy that increases the delay between retries exponentially.

This strategy calculates the delay for each attempt using the formula: delay = min(maxDelay, initialDelay * factor^(attempt - 1))

If jitter is enabled, a random variance is added to the delay to prevent multiple clients from retrying simultaneously (the "thundering herd" problem).

Constructors

Link copied to clipboard
constructor(initialDelay: Duration = 100.milliseconds, maxDelay: Duration = 10.seconds, factor: Double = 2.0, jitter: Boolean = true)

Properties

Link copied to clipboard

The multiplier for each subsequent delay. Must be >= 1.0.

Link copied to clipboard

The base delay for the first retry attempt.

Link copied to clipboard

If true, adds a random +/- 20% variance to the delay duration.

Link copied to clipboard

The maximum delay that will be used, capping the exponential growth.

Functions

Link copied to clipboard
open suspend override fun delay(attempt: Int)

Suspends for the delay duration appropriate for the given attempt (1-based).