Zum Inhalt springen
_CORE
KI & Agentensysteme Unternehmensinformationssysteme Cloud & Platform Engineering Datenplattform & Integration Sicherheit & Compliance QA, Testing & Observability IoT, Automatisierung & Robotik Mobile & Digitale Produkte Banken & Finanzen Versicherungen Öffentliche Verwaltung Verteidigung & Sicherheit Gesundheitswesen Energie & Versorgung Telko & Medien Industrie & Fertigung Logistik & E-Commerce Retail & Treueprogramme
Referenzen Technologien Blog Know-how Tools
Über uns Zusammenarbeit Karriere
CS EN DE
Lassen Sie uns sprechen

Retry Pattern — opakování s rozumem

24. 02. 2024 1 Min. Lesezeit intermediate

Architecture Beginner

Retry Pattern — opakování s rozumem

RetryResilienceError Handling 3 min read

Správná implementation retry logiky. Exponential backoff, jitter a kdy NEretryovat.

Exponential Backoff s Jitter

async function retryWithBackoff(fn, maxRetries = 3) {
    for (let attempt = 0; attempt <= maxRetries; attempt++) {
        try { return await fn(); }
        catch (error) {
            if (attempt === maxRetries) throw error;
            if (!isTransient(error)) throw error;
            const delay = Math.pow(2, attempt) * 1000 * (0.5 + Math.random() * 0.5);
            await sleep(delay);
        }
    }
}
function isTransient(error) {
    const s = error.response?.status;
    return s === 429 || s === 503 || s >= 500;
}

Kdy NEretryovat

  • 4xx errors (kromě 429)
  • Non-idempotent operace without idempotency klíče
  • Autentizační errors (401/403)
  • Dlouho runscí operace

Summary

Exponential backoff + jitter + max retries. Retryujte jen transientní errors a idempotentní operace.

Need Help with Implementation?

Our team has experience designing and implementing modern architectures. We’re happy to help.

Free Consultation

Teilen:

CORE SYSTEMS Team

Wir bauen Kernsysteme und KI-Agenten, die den Betrieb am Laufen halten. 15 Jahre Erfahrung mit Enterprise-IT.