Retries, timeouts, and circuit breakers

Retries re-issue a failed request (with backoff) to handle transient failures. Timeouts stop waiting after a limit so one slow dependency doesn’t block forever. Circuit breaker stops calling a failing dependency for a period (open), then allows probes (half-open) and closes when healthy — protecting the system from cascading failure.

Retry with backoff

sequenceDiagram participant C as Client participant S as Server C->>S: Request S-->>C: 503 / timeout C->>C: Wait 1s (backoff) C->>S: Retry S-->>C: 503 C->>C: Wait 2s (exponential) C->>S: Retry S-->>C: 200 OK

Circuit breaker states

stateDiagram-v2 [*] --> Closed: Normal Closed --> Open: Failures >= threshold Open --> HalfOpen: After timeout HalfOpen --> Closed: Success HalfOpen --> Open: Failure
MechanismPurpose
Retry + backoffHandle transient failures; avoid hammering
TimeoutBound wait time; fail fast
Circuit breakerStop calling failing service; fail fast; allow recovery

Use timeouts on every outbound call. Use retries with exponential backoff for idempotent or safe operations. Use a circuit breaker when a dependency is repeatedly failing so the rest of the system doesn’t stall or cascade.