Retry Policy
A retry policy is a service mesh setting that automatically retries failed requests without application changes. In Istio it is defined per route in a VirtualService, with the number of attempts, a per-try timeout, and the conditions that trigger a retry.
How retries work
When a request fails, the caller's sidecar sends it again, and the application may never see the first failure. This smooths over transient problems like a connection reset during a pod restart.
Configure in Istio
apiVersion: networking.istio.io/v1kind: VirtualServicemetadata: name: payments-service namespace: productionspec: hosts: - payments-service http: - route: - destination: host: payments-service timeout: 10s retries: attempts: 3 perTryTimeout: 3s retryOn: connect-failure,refused-stream,gateway-errorIstio retries by default (twice, on certain connection-level failures) even without a retries block. Set attempts: 0 to disable.
| retryOn value | Triggers on |
|---|---|
| 5xx | Any 5xx response |
| connect-failure | Failure to connect |
| gateway-error | 502, 503, 504 |
| reset | Connection reset |
| retriable-4xx | 409 responses |
Safety rules
- Retry only idempotent operations. GET, HEAD, PUT, and DELETE are usually safe.
- POST and PATCH need an idempotency key, or a duplicate may be processed. A payment initiation retried without one can double-charge.
- Do not retry client errors like 400, 401, 403, or 404.
Remember
timeoutis the total budget for all attempts. Three 3-second attempts need at least 9 seconds of timeout to complete.
Common MistakeRetrying non-idempotent POST requests. If the response was lost, the retry repeats the action.
TipCombine retries with circuit breaking and a total timeout so retries cannot amplify an outage into a retry storm.
Frequently Asked Questions
How is a mesh retry different from retry code in the app?
It runs in the proxy and applies consistently to every service, in any language, with conditions defined declaratively per route. App-level retries depend on each team implementing them.
Why can retries make an outage worse?
Each failure multiplies load on an already struggling service. Without a total timeout, a retry budget, or circuit breaking, retries can turn a partial failure into a full one.
What does perTryTimeout do?
It limits how long a single attempt may take before it counts as failed and the next retry starts, while the route timeout caps the whole sequence.