RetryPolicy

data class RetryPolicy(val maxAttempts: Int = 3, val initialDelay: Duration = 100.milliseconds, val maxDelay: Duration = 10.seconds, val multiplier: Double = 2.0, val jitter: Double = 0.1, val retryOn: (Throwable) -> Boolean = { true })

Retry policy for saga step execution with exponential backoff.

Defines how failed saga steps should be retried, including:

  • Maximum retry attempts

  • Exponential backoff with configurable parameters

  • Jitter to prevent thundering herd

  • Conditional retry based on exception type

Usage Example

val retryPolicy = RetryPolicy(
maxAttempts = 3,
initialDelay = 100.milliseconds,
maxDelay = 5.seconds,
multiplier = 2.0,
jitter = 0.1
)

sagaExecutor<Ctx, Result> {
step("flaky-operation") { context ->
externalService.call(context)
}
.withRetry(retryPolicy)
}

Constructors

Link copied to clipboard
constructor(maxAttempts: Int = 3, initialDelay: Duration = 100.milliseconds, maxDelay: Duration = 10.seconds, multiplier: Double = 2.0, jitter: Double = 0.1, retryOn: (Throwable) -> Boolean = { true })

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Initial delay before first retry

Link copied to clipboard

Random jitter factor (0.0 to 1.0) to add randomness

Link copied to clipboard

Maximum number of retry attempts (not including initial attempt)

Link copied to clipboard

Maximum delay between retries

Link copied to clipboard

Exponential backoff multiplier

Link copied to clipboard

Predicate to determine if exception should trigger retry

Functions

Link copied to clipboard
fun calculateDelay(attempt: Int): Duration

Calculate delay for a specific retry attempt.

Link copied to clipboard
fun shouldRetry(exception: Throwable): Boolean

Determine if the given exception should trigger a retry.