Configure Retries
Send a request again when the service behind the API fails, so that a brief failure is not seen by the caller.
How it works
When a request to the backend fails for a transient reason, the gateway sends it again, after a short wait that grows with each attempt. The caller sees one request that succeeded.
A retried request may be executed twice
Retry on connection failures for any operation. Retry on 5xx only for idempotent operations, or the backend may create two orders.
Every parameter and its default: reference.
Use cases
For requests that are safe to repeat: reads, and writes that your service recognises when it receives them twice.
Prerequisites
- An API instance that is deployed and answers.
Procedure
- In API Manager, go to API Instances and open the API. To cover everything published on a gateway instead, open the gateway.
- Open its Backend traffic policies and add the rule retry.
- In Max Retries, give how many times a failed request is sent again.
- In Retry On, list what triggers a retry:
5xx,gateway-error,reset,connect-failure. - Adjust Base Interval and Max Interval, the wait between attempts.
- Deploy.
Parameters
| Field | What it is | Default |
|---|---|---|
| Max Retries | How many times a failed request is sent again. | 3 |
| Retry On | The failures that trigger a retry. | 5xx, gateway-error, reset |
| Base Interval | The wait before the first retry. It grows with each attempt. | 100ms |
| Max Interval | The longest wait between two attempts. | 10s |
Behavior and limits
- A retry sends the same request again: on a write, it can create a duplicate unless your service recognises a request it already handled.
- Retries add load to a service that is already failing. Combine them with a circuit breaker.
- The total time of a request with its retries is bounded by the timeout.
See also
- Policies: every rule at a glance