Zum Inhalt springen
_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
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

Architektura Začátečník

Retry Pattern — opakování s rozumem

RetryResilienceError Handling 3 min čtení

Správná implementace 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 chyby (kromě 429)
  • Non-idempotent operace bez idempotency klíče
  • Autentizační chyby (401/403)
  • Dlouho běžící operace

Shrnutí

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

Potřebujete pomoct s implementací?

Náš tým má zkušenosti s návrhem a implementací moderních architektur. Rádi vám pomůžeme.

Nezávazná konzultace

Teilen:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.