Linux Networking & TCP/IP for Developers · Lección

Patrones de resiliencia: circuit breakers, reintentos y timeouts

Mantenga los sistemas distribuidos en buen estado ante fallos mediante timeouts, reintentos limitados con backoff y el patrón circuit breaker para evitar interrupciones en cascada.

Lección 4 de 413 pasos

Patrones de resiliencia: circuit breakers, reintentos y timeouts es una lección gratuita de Linux Networking & TCP/IP for Developers en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Linux Networking & TCP/IP for Developers, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Linux Networking & TCP/IP for Developers incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

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 para empezar

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

Escribe y ejecuta código real en tu navegador, obtén ayuda instantánea de un tutor de IA disponible 24/7 y continúa donde lo dejaste en la web o en la aplicación.

Cursos
12
Lecciones
48

Preguntas frecuentes

¿La lección «Patrones de resiliencia: circuit breakers, reintentos y timeouts» es gratis?

Sí — el texto completo de «Patrones de resiliencia: circuit breakers, reintentos y timeouts» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Linux Networking & TCP/IP for Developers, actualiza a CoddyKit PRO. El curso de Linux Networking & TCP/IP for Developers incluye 4 lecciones en total.

¿Qué aprenderé en «Patrones de resiliencia: circuit breakers, reintentos y timeouts»?

Mantenga los sistemas distribuidos en buen estado ante fallos mediante timeouts, reintentos limitados con backoff y el patrón circuit breaker para evitar interrupciones en cascada. Practicas Linux Networking & TCP/IP for Developers con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Linux Networking & TCP/IP for Developers?

No se requiere experiencia previa. Linux Networking & TCP/IP for Developers en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Patrones de resiliencia: circuit breakers, reintentos y timeouts»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Linux Networking & TCP/IP for Developers?

Sí. Cada lección de Linux Networking & TCP/IP for Developers incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Estrategias de balanceo de carga
  2. Arquitecturas de service mesh (Istio/Linkerd)
  3. API Gateway y enrutamiento perimetral
  4. Patrones de resiliencia: circuit breakers, reintentos y timeouts
← Volver a Linux Networking & TCP/IP for Developers