Julia capped exponential backoff retry helper
Julia
using Random
function retry_with_backoff(f; attempts=5, base=0.05, cap=2.0)
for i in 1:attempts
try
return f()
catch
i == attempts && rethrow()
delay = min(cap, base * 2.0^(i - 1))
sleep(delay * (0.5 + rand())) # jitter avoids thundering herds
end
end
end
# retry_with_backoff(() -> HTTP.get(url)) handles transient failures
println(retry_with_backoff(() -> sqrt(16)))