Cargando...
Simula y visualiza estrategias de reintento (Full Jitter, Equal Jitter, Decorrelated) para evitar colisiones por estampida (Thundering Herd)
Selecciona patrones típicos de fallos de red y entrega de webhooks
Ajusta retardos base, tope máximo y algoritmo de dispersión (jitter)
Uniformly randomizes sleep between 0 and exponential ceiling. Best for spreading out spikes.
// TypeScript resilient fetch wrapper with FULL jitter
export async function fetchWithRetry(
url: string,
options?: RequestInit,
retries = 5,
baseDelay = 200,
maxDelay = 5000
): Promise<Response> {
let prevDelay = baseDelay;
for (let attempt = 1; attempt <= retries; attempt++) {
try {
const res = await fetch(url, options);
if (res.ok || res.status < 500 && res.status !== 429) return res;
throw new Error(`HTTP ${res.status}`);
} catch (err) {
if (attempt === retries) throw err;
const ceiling = Math.min(maxDelay, baseDelay * Math.pow(2, attempt));
const delay = Math.random() * ceiling;
prevDelay = delay;
await new Promise(r => setTimeout(r, delay));
}
}
throw new Error('Retries exhausted');
}# Python (urllib3 / requests) with FULL jitter
import time
import random
def fetch_with_retry(request_fn, retries=5, base_ms=200, max_ms=5000):
prev_delay = base_ms / 1000.0
for attempt in range(1, retries + 1):
try:
return request_fn()
except Exception as e:
if attempt == retries:
raise e
ceiling = min(max_ms / 1000.0, (base_ms / 1000.0) * (2 ** attempt))
delay = random.uniform(0, ceiling)
prev_delay = delay
time.sleep(delay)
// Go Backoff Retry Loop
package main
import (
"math/rand"
"time"
)
func Backoff(attempt int, base time.Duration, max time.Duration) time.Duration {
ceiling := time.Duration(float64(base) * (1 << attempt))
if ceiling > max {
ceiling = max
}
// FULL Jitter
return time.Duration(rand.Int63n(int64(ceiling)))
}