As asked
Write a retry wrapper in Go that retries a function call with exponential backoff and full jitter. It should respect a maximum number of retries and a maximum delay cap. Explain why jitter matters for SRE.
Sample answer outline
The candidate should implement base delay doubling each attempt, capped at maxDelay, with jitter as `rand.Int63n(currentDelay)` to spread retries across the retry window. They should explain that without jitter, all clients back off to the same delay and then send a synchronized burst (thundering herd), which can overwhelm a recovering service. Context cancellation should also be respected.
Reference implementation (go)
package main
import (
"context"
"math/rand"
"time"
)
func RetryWithBackoff(
ctx context.Context,
maxRetries int,
baseDelay time.Duration,
maxDelay time.Duration,
fn func() error,
) error {
// TODO: implement exponential backoff with full jitter
return nil
}Expect these follow-ups
- What is the difference between full jitter and decorrelated jitter?
- When should you NOT retry, even with backoff?