Class ExponentialBackoffRetryStrategy

java.lang.Object
de.cuioss.http.client.retry.ExponentialBackoffRetryStrategy
All Implemented Interfaces:
RetryStrategy

public class ExponentialBackoffRetryStrategy extends Object implements RetryStrategy
Exponential backoff retry strategy with jitter to prevent thundering herd.

Algorithm based on AWS Architecture Blog recommendations: - Base delay starts at initialDelay - Each retry multiplies by backoffMultiplier - Random jitter applied: delay * (1 ± jitterFactor) - Maximum delay capped at maxDelay - Total attempts limited by maxAttempts

The strategy includes intelligent exception classification to determine which exceptions should trigger retries versus immediate failure.

  • Method Details

    • execute

      public <T> CompletableFuture<HttpResultObject<T>> execute(HttpOperation<T> operation, RetryContext context)
      Description copied from interface: RetryStrategy
      Executes the given HTTP operation with retry logic using virtual threads and async execution.

      This method runs operations on virtual threads with non-blocking delays between retry attempts. The implementation uses CompletableFuture.delayedExecutor() with virtual thread executors to provide efficient, scalable retry operations without blocking threads during delays.

      Specified by:
      execute in interface RetryStrategy
      Type Parameters:
      T - the type of result returned by the operation
      Parameters:
      operation - the HTTP operation to retry
      context - retry context with operation name and attempt info
      Returns:
      CompletableFuture containing HttpResultObject with result and comprehensive error/retry information
    • builder

      Creates a builder for configuring the exponential backoff strategy.
      Returns:
      a new builder instance with default values