🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)
🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)

🔧 Programmierung 🕛 kürzlich 4 Min Lesezeit
0

Retry Pattern: Handling Transient Failures in Distributed Systems

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

In distributed environments, transient failures are inevitable: network latency, timeouts, temporarily unavailable services. The Retry pattern provides a robust strategy for handling these temporary failures, allowing applications to automatically recover from errors that can resolve themselves.






Understanding the Retry Pattern



The Retry pattern implements an automatic retry strategy when an operation fails, assuming that the cause of the failure is temporary and can be resolved without manual intervention. The key lies in distinguishing between transient and permanent failures, and applying appropriate retry strategies.






Common Strategies





  1. Immediate Retry: Retries the operation immediately.


  2. Retry with Backoff: Increases the time between retries.


  3. Exponential Retry: Doubles the waiting time between attempts.


  4. Retry with Jitter: Adds randomness to prevent the thundering herd problem.






Practical Implementation



Let's look at different implementations of the Retry pattern in Python:






1. Simple Retry with Decorator






CODE
import time
from functools import wraps
from typing import Callable, Type, Tuple

def retry(
exceptions: Tuple[Type[Exception]] = (Exception,),
max_attempts: int = 3,
delay: float = 1
):
def decorator(func: Callable):
@wraps(func)
def wrapper(*args, **kwargs):
attempts = 0
while attempts < max_attempts:
try:
return func(*args, **kwargs)
except exceptions as e:
attempts += 1
if attempts == max_attempts:
raise e
time.sleep(delay)
return None
return wrapper
return decorator

@retry(exceptions=(ConnectionError, TimeoutError), max_attempts=3)
def fetch_data(url: str):
# API call simulation
return requests.get(url)









2. Retry with Exponential Backoff






CODE
import random
from typing import Optional

class ExponentialBackoff:
def __init__(
self,
initial_delay: float = 1.0,
max_delay: float = 60.0,
max_attempts: int = 5,
jitter: bool = True
):
self.initial_delay = initial_delay
self.max_delay = max_delay
self.max_attempts = max_attempts
self.jitter = jitter
self.attempt = 0

def next_delay(self) -> Optional[float]:
if self.attempt >= self.max_attempts:
return None

delay = min(
self.initial_delay * (2 ** self.attempt),
self.max_delay
)

if self.jitter:
delay *= (0.5 + random.random())

self.attempt += 1
return delay

async def retry_operation(operation: Callable, backoff: ExponentialBackoff):
last_exception = None

while (delay := backoff.next_delay()) is not None:
try:
return await operation()
except Exception as e:
last_exception = e
await asyncio.sleep(delay)

raise last_exception









3. Retry with Circuit Breaker






CODE
from dataclasses import dataclass
from datetime import datetime, timedelta

@dataclass
class CircuitBreakerConfig:
failure_threshold: int = 5
reset_timeout: timedelta = timedelta(minutes=1)
retry_timeout: timedelta = timedelta(seconds=10)

class CircuitBreaker:
def __init__(self, config: CircuitBreakerConfig):
self.config = config
self.failures = 0
self.last_failure = None
self.state = "CLOSED"

def can_retry(self) -> bool:
if self.state == "CLOSED":
return True

if self.state == "OPEN":
if datetime.now() - self.last_failure > self.config.reset_timeout:
self.state = "HALF_OPEN"
return True
return False

return True # HALF_OPEN

def record_failure(self):
self.failures += 1
self.last_failure = datetime.now()

if self.failures >= self.config.failure_threshold:
self.state = "OPEN"

def record_success(self):
if self.state == "HALF_OPEN":
self.state = "CLOSED"
self.failures = 0
self.last_failure = None

async def retry_with_circuit_breaker(
operation: Callable,
circuit_breaker: CircuitBreaker,
backoff: ExponentialBackoff
):
while True:
if not circuit_breaker.can_retry():
raise Exception("Circuit breaker is open")

try:
result = await operation()
circuit_breaker.record_success()
return result
except Exception as e:
circuit_breaker.record_failure()
if (delay := backoff.next_delay()) is None:
raise e
await asyncio.sleep(delay)









Cloud Applications



The Retry pattern is particularly useful in cloud scenarios:






1. Microservices Communication






CODE
from fastapi import FastAPI, HTTPException
from tenacity import retry, stop_after_attempt, wait_exponential

app = FastAPI()

@retry(
stop=stop_after_attempt(3),
wait=wait_exponential(multiplier=1, min=4, max=10),
retry=retry_if_exception_type(ConnectionError)
)
async def call_dependent_service(data: dict):
async with httpx.AsyncClient() as client:
response = await client.post(
"http://dependent-service/api/v1/process",
json=data,
timeout=5.0
)
return response.json()

@app.post("/process")
async def process_request(data: dict):
try:
return await call_dependent_service(data)
except Exception:
raise HTTPException(
status_code=503,
detail="Service temporarily unavailable"
)









2. Database Operations






CODE
from sqlalchemy import create_engine
from sqlalchemy.exc import OperationalError
from contextlib import contextmanager

class DatabaseRetry:
def __init__(self, url: str, max_attempts: int = 3):
self.engine = create_engine(url)
self.max_attempts = max_attempts

@contextmanager
def session(self):
attempt = 0
while True:
try:
with self.engine.connect() as connection:
yield connection
break
except OperationalError:
attempt += 1
if attempt >= self.max_attempts:
raise
time.sleep(2 ** attempt)









Benefits of the Retry Pattern





  1. Resilience: Automatically handles transient failures.


  2. Availability: Improves overall system availability.


  3. Transparency: Retries are transparent to the user.


  4. Flexibility: Allows different strategies based on use case.






Design Considerations



When implementing the Retry pattern, consider:





  1. Idempotency: Operations must be safe to retry.


  2. Timeouts: Set clear limits for retries.


  3. Logging: Record retries for monitoring.


  4. Backoff: Use strategies that prevent system overload.






Conclusion



The Retry pattern is essential in modern distributed architectures. A careful implementation, considering idempotency and backoff strategies, can significantly improve your system's resilience. However, it should be used judiciously to avoid masking systemic issues that require attention.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
GPT-6 Astra Release Today? OpenAI’s Next Major AI Model Is Almost Here
1 Quelle
Apple accuses OpenAI of destroying evidence as trade-secrets fight intensifies
1 Quelle
Major AI platforms go down in unprecedented simultaneous outage
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Retry Pattern: Handling Transient Failures in Distributed Systems

Thematisch verwandte Begriffe: Retry, Pattern, Handling, Transient · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...