Retry in Distributed Systems — How Production Systems Recover From Temporary Failures
Not every failure is permanent. This is something I didn't think about before. When something fails in my app, my first thought was something broke, fix it. But when I started learning how distributed systems actually work, I realized that some failures are not really failures. They're just temporary. Network glitch. API timeout. A service that just restarted. Rate limiting kicking in. These are all failures but they last for a very short time window. If your system tries the same operation again after a few seconds, it will probably succeed. So the question is does your system know how to try again? Or does it just give up the first time something goes wrong? That's what retry is. What Retry Actually Does Without a retry system, if a temporary failure happens that's it. The entire operation fails. The user sees an error. The request is gone. With retry, your system automatically attempts the operation again after a failure. The goal is simple recover from temporary failures without the user even knowing something went wrong. This felt obvious to me once I understood it. But building it properly is where it gets interesting. The Configuration: What Each Part Controls When I looked into how retry systems are actually configured, there were more options than I expected. And each one exists for a specific reason. maxAttempts — this defines the maximum number of times the operation can be attempted. You don't want infinite retries. At some point if it keeps failing, it's probably not a temporary problem. exponential backoff — instead of retrying immediately every time, the delay between retries doubles after each failure. First retry after 1 second, second after 2 seconds, third after 4 seconds. This gives the failing service time to recover instead of bombarding it with requests. baseDelay — this is the starting delay used in the exponential backoff. The first wait time before retrying. maxDelay — this caps the maximum delay. Without this, the exponential backoff keeps