Retry
Overview
Retry helps in applying a retry policy in order to try and transform failed requests into successful ones. What is considered as success can be defined by specific criteria. The Retry remedy plugin supports custom configuration for wait times between retry attempts.
In case the retry attempts sequence did not conclude with a successful response, the last failed response will be returned to the caller.
Client-Side Retries
The Retry remedy plugin is designed to offload required retry attempts to the client-side rather than handling them within Lunar Proxy itself. This is done in order to avoid client-side timeouts.
For this purpose, the Retry remedy plugin works tightly alongside Lunar Interceptors, which in turn react to specific internal headers handed over by Lunar Proxy in case a retry attempt is required.
Configuration
global:
remedies:
- name: Retry
enabled: true
config:
retry:
attempts: <attempts>
initial_cooldown_seconds: <initial_cooldown_seconds>
cooldown_multiplier: <cooldown_multiplier>
conditions:
status_code:
- from: <min_status_code>
to: <max_status_code>
The following configuration options are available for this remediation plugin:
Parameter | Example Value | Possible Values | Description |
---|---|---|---|
attempts | 3 | Any positive integer | The maximal number of retry attempts |
initial_cooldown_seconds | 1 | Any positive integer | The initial number of seconds to wait before a retry attempt |
cooldown_multiplier | 2 | Any positive integer | The multiplier to apply for number of seconds to wait between attempts. Use 1 to apply constant wait time between requests |
min_status_code | 500 | Any positive integer | The lower end of status codes to apply retry upon. Inclusive |
max_status_code | 599 | Any positive integer above min_status_code | The higher end of status codes to apply retry upon. Inclusive |
Examples
endpoints:
- url: api.com/resource/{id}
method: GET
remedies:
- name: Retry
enabled: true
config:
retry:
attempts: 3
initial_cooldown_seconds: 1
cooldown_multiplier: 2
conditions:
status_code:
- from: 500
to: 599
In the example above, the plugin will perform 3 or less retry attempts until a non-5XX response comes back from the API provider. In case all 3 retry attempts are required, the wait times after each attempt would be:
Attempt | Wait Time |
---|---|
#1 | 1 second (1 X 1) |
#2 | 2 second (1 X 2) |
#3 | 4 second (1 X 4) |
This is because initial_cooldown_seconds
is set to 1
and cooldown_multiplier
is set to 2
.
Currently, it is only possible to configure retry conditions regarding status code range.
Since the range is inclusive on both ends, specifying the same status code in both from
and to
fields would effectively apply the remedy for that specific status code only.
Use Cases
-
Artificially Increasing Provider's Availability: As any other web service, API providers might experience temporary outages that result in an undesired server-side error (5XX). These can be mitigated by a simple delayed retry.
-
Chaining With Throttling Remedy Plugins: The purpose of Lunar's various throttling remedy plugins is to return an internal, initiated Too Many Requests response. Thus, chaining a retry remedy after these can prove beneficial in order to transform requests into an eventual successful response while avoiding exceeding rate limits and being punished with exponential backoff
Retry-After
times.