backoff

package
v0.11.5-coffee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package backoff provides a reusable exponential backoff calculator with jitter.

This is an internal package and MUST NOT be imported by external consumers. It is used by the Gateway reconnection logic and the rate limiter to compute retry delays that avoid thundering-herd problems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Calculate

func Calculate(attempt int, base, max time.Duration) time.Duration

Calculate returns an exponential backoff duration for the given attempt.

The formula is: min(base * 2^attempt + jitter, max)

The jitter is a random duration between 0 and base, added to avoid thundering-herd problems when many clients retry simultaneously.

attempt should be 0-indexed (i.e. the first retry is attempt 0). base is the starting backoff duration before any exponential scaling. max is the upper-bound cap on the returned duration.

If attempt is negative it is treated as 0. If base is zero or negative the returned duration will only contain jitter (capped by max). If max is zero or negative the function returns 0.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL