Get the latest tech news

Simpler Backoff


Exponential backoff with jitter is de rigeur for making service calls. This code, or something like it, probably looks really familiar: func do(ctx context.Context) error { const ( maxAttempts = 10 baseDelay = 1 * time.Second maxDelay = 60 * time.Second ) delay := baseDelay for attempt := range maxAttempts { err := request(ctx) if err == nil { return nil } delay *= 2 delay = min(delay, maxDelay) jitter := multiplyDuration(delay, rand.

Exponential backoff with jitter is de rigeur for making service calls. There’s no need to reasoning about behavior across loops, and if there’s a bug in the calculations, it won’t affect subsequent iterations. Changing the backoff schedule and number of attempts now feels safe and trivial.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Simpler Backoff

Simpler Backoff