Principle:42 evey Hermes plugins Retry with Backoff
| Knowledge Sources | |
|---|---|
| Domains | Reliability, Error_Handling, Distributed_Systems |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
A reliability pattern that retries transiently failing operations with exponentially increasing wait times between attempts, reducing load on overwhelmed services and improving success rates.
Description
Retry with Backoff addresses transient failures — network timeouts, rate limits, temporary service unavailability — by retrying the operation with increasing delays. The exponential backoff formula wait = base × 2^(attempt-1) produces delays of 1s, 2s, 4s, etc., giving the failing service time to recover.
Key design decisions:
- Empty responses count as failures: An LLM returning an empty string is treated as a retryable error, not a success.
- All retries exhausted → raise: After the maximum number of retries, the error is raised to the caller rather than silently swallowed.
- Success on first non-empty response: The first attempt that returns content succeeds immediately; no extra latency from unnecessary retries.
Usage
Use this principle when calling external services (LLM APIs, HTTP endpoints) that may fail transiently. Suitable for operations where idempotency holds (retrying the same prompt is safe). Not suitable for non-idempotent operations (e.g., sending an email) where retries could cause duplicate side effects.
Theoretical Basis
The exponential backoff formula:
Where is the attempt number (1-indexed) and is the initial delay. For base=1 and 3 retries, the wait sequence is: 1s (after attempt 1), 2s (after attempt 2).
# Abstract algorithm (NOT real implementation)
for attempt in range(1, max_retries + 1):
try:
result = call_service()
if result is not empty:
return result
last_error = "empty response"
except Exception as e:
last_error = e
if attempt < max_retries:
sleep(2 ** (attempt - 1)) # 1s, 2s, 4s...
raise RuntimeError(last_error)
The backoff reduces thundering-herd problems: if many clients retry simultaneously after a service outage, exponential backoff spreads their retries over time rather than hammering the service all at once.