
Stop Writing Manual Retry Loops in Go: Why Your Current Logic is Probably Dangerous
If you've been writing Go for more than a week, you've likely written a retry loop. It usually starts like this: for i := 0 ; i < 3 ; i ++ { err := doSomething () if err == nil { break } time . Sleep ( 1 * time . Second ) } It's simple, idiomatic, and... a ticking time bomb in production. In a distributed system, transient failures—network blips, database locks, rate limits—are mathematical certainties. While a simple for loop feels like enough, it often fails exactly when your system is under the most stress. Here is why your manual retry logic is probably dangerous, and how to fix it using Resile . The 3 Silent Killers of Manual Retries 1. The Thundering Herd (Missing Jitter) If your service has 1,000 instances and the database goes down for a second, all 1,000 instances will fail at once. With a fixed time.Sleep(1 * time.Second) , all 1,000 instances will then wake up at the exact same millisecond and hammer the database again. This is a self-inflicted DDoS attack. Without Jitter (r
Continue reading on Dev.to
Opens in a new tab


