Two resilience primitives
A timeout combinator fails a stage that takes too long, converting a hung call into a prompt error. A retry combinator resubscribes or re invokes after a failure, hoping the fault was transient.
Timeout details
A timeout starts a timer when work begins. If no result arrives in the window, it cancels the underlying operation and emits an error. Always pair a timeout with cancellation so the abandoned work actually stops.
Retry with backoff
Naive retry hammers a struggling service and makes things worse. Add:
- Exponential backoff so each attempt waits longer.
- Jitter so many clients do not retry in sync.
- A maximum attempts cap so failures eventually surface.
Only retry the retryable
Retrying a malformed request or an authorization failure wastes effort because the outcome will not change. Restrict retries to transient signals like timeouts and server errors.
Key idea
Timeouts bound latency by failing slow calls, and retries with backoff and jitter recover transient faults without stampeding the service.