Developers

Linear Backoff

Linear backoff takes a simpler approach by linearly increasing the delay duration with each failed attempt. For example, the delay might be incremented by a fixed amount, such as 1 second, after each unsuccessful try. While it provides a consistent and predictable delay pattern, linear backoff may not be as efficient as exponential backoff in preventing consecutive 429 errors when the rate limit is strict.

Example implementation

Pseudo-code

define max_retries
define initial_delay

function retry(operation, max_retries, initial_delay)
    // Initialize the attempt counter and the current delay
    attempt <- 0
    delay <- initial_delay

    while attempt < max_retries do
        try
            // Attempt to perform the operation
            operation()
            // If successful, exit the function
            return
        catch
            // If the operation fails, increment the attempt counter
            attempt <- attempt + 1
            // Pause for the current delay period
            sleep delay
            // Increase the delay by a fixed amount (the initial delay)
            delay <- delay + initial_delay
    end while
    // If all retries fail, the function will finish here
end function

Simulation