Linux Networking & TCP/IP for Developers · Lezione

Pattern di resilienza: circuit breaker, retry e timeout

Mantenga integri i sistemi distribuiti in caso di guasto usando timeout, retry limitati con backoff e il pattern circuit breaker per prevenire interruzioni a cascata.

Lezione 4 di 413 passaggi

Pattern di resilienza: circuit breaker, retry e timeout è una lezione Linux Networking & TCP/IP for Developers gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Linux Networking & TCP/IP for Developers, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Linux Networking & TCP/IP for Developers include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

Failure Is Normal

In a microservices network, calls cross machines and links that will fail. Resilience patterns keep one slow or broken service from dragging down the whole system.

Always Set Timeouts

A call with no timeout can hang forever, exhausting threads and connections. Every remote call must have a deadline.

import requests
r = requests.get('http://orders/api', timeout=2.0)

The Danger of Naive Retries

Retrying immediately after a failure can amplify an outage — a struggling service gets hit even harder. Retries must be bounded and spaced.

Exponential Backoff

Increase the wait between attempts exponentially so a recovering service gets breathing room.

for attempt in range(5):
    try:
        return call()
    except Exception:
        wait = 2 ** attempt
        time.sleep(wait)

Adding Jitter

If many clients back off on the same schedule they retry in sync, creating a thundering herd. Add random jitter to spread the load.

import random
wait = (2 ** attempt) + random.uniform(0, 1)

Retry Only Idempotent Operations

Retrying a non-idempotent write (like 'charge card') can double-execute it. Only retry safe operations, or use idempotency keys to make writes safe.

The Circuit Breaker

A circuit breaker tracks failures to a dependency. After too many, it opens and fails fast instead of waiting on a dead service.

This stops resources from piling up on a doomed call.

Breaker States

A circuit breaker has three states:

  • Closed — calls flow normally
  • Open — calls fail immediately
  • Half-Open — a few test calls probe recovery

Breaker in Code

A minimal breaker counts failures and trips after a threshold, refusing calls until a cooldown elapses.

if breaker.is_open():
    raise CircuitOpenError()
try:
    result = call()
    breaker.record_success()
except Exception:
    breaker.record_failure()
    raise

Fallbacks and Graceful Degradation

When a breaker is open, return a sensible fallback: cached data, a default value, or a reduced feature set. A degraded response beats a total failure.

Bulkheads

The bulkhead pattern isolates resources (thread pools, connection pools) per dependency, so one saturated dependency cannot starve the others.

Quick Check

Test your resilience knowledge.

Recap

You can now build resilient service calls:

  • Always set timeouts
  • Bounded retries with exponential backoff + jitter
  • Retry only idempotent operations
  • Circuit breakers (closed/open/half-open) to fail fast
  • Fallbacks and bulkheads for graceful degradation

This complements your load balancing, service mesh, and API gateway lessons.

Gratis per iniziare

Impara Linux Networking & TCP/IP for Developers con un tutor IA — gratis

Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.

Corsi
12
Lezioni
48

Domande Frequenti

La lezione «Pattern di resilienza: circuit breaker, retry e timeout» è gratuita?

Sì — il testo completo di «Pattern di resilienza: circuit breaker, retry e timeout» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Linux Networking & TCP/IP for Developers, passa a CoddyKit PRO. Il corso Linux Networking & TCP/IP for Developers include 4 lezioni in totale.

Cosa imparerò in «Pattern di resilienza: circuit breaker, retry e timeout»?

Mantenga integri i sistemi distribuiti in caso di guasto usando timeout, retry limitati con backoff e il pattern circuit breaker per prevenire interruzioni a cascata. Eserciti Linux Networking & TCP/IP for Developers con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Linux Networking & TCP/IP for Developers?

Non è richiesta alcuna esperienza precedente. Linux Networking & TCP/IP for Developers su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Pattern di resilienza: circuit breaker, retry e timeout»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Linux Networking & TCP/IP for Developers?

Sì. Ogni lezione Linux Networking & TCP/IP for Developers include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Strategie di bilanciamento del carico
  2. Architetture service mesh (Istio/Linkerd)
  3. API Gateway e routing edge
  4. Pattern di resilienza: circuit breaker, retry e timeout
← Torna a Linux Networking & TCP/IP for Developers