Skip to main content
Version: Next

Retry Flow

The Retry Flow automatically handles retries for failed API requests based on configurable criteria, such as status codes and retry strategies. It is designed to enhance API reliability by managing temporary failures without requiring client-side retry logic.

Flow Diagram


Scenarios

  1. Handling Temporary API Failures: Automatically retry failed requests, reducing manual error handling.
  2. Improving Reliability: Manage network issues and server downtime with exponential backoff retries.
  3. Enhanced Monitoring: Track retry attempts, cooldowns, and related performance metrics.

Flow Configuration Template

/etc/lunar-proxy/flows/flow.yaml
name: RetryFlow

filter:
url: "api.com/resource/{id}" # Target URL pattern for retry logic
processors:
FilterProcessor:
processor: Filter
parameters:
- key: status_code_range
value: 400-500 # Set the range if status code to trigger the filter.
metrics:
enabled: true
labels:
- flow_name
- processor_key
- http_method
- host
- status_code
- consumer_tag
RetryProcessor:
processor: Retry # Specifies the Retry processor
parameters:
- key: attempts
value: 3 # Maximum number of retry attempts
- key: cooldown_between_attempts_seconds
value: 2 # Initial cooldown time before the first retry (in seconds)
- key: cooldown_multiplier
value: 2 # Multiplier for exponential backoff
- key: maximum_cooldown_seconds
value: 3600 # Maximum time to wait between each retry (in seconds)
metrics:
enabled: true # Enables metric collection
labels:
- flow_name # Include the flow name as a label
- processor_key # Include the processor key as a label
- http_method # Include the HTTP method (GET, POST, etc.)
- url # Include the URL of the request
- status_code # Include the HTTP status code of the response
flow:
request:
- from:
stream:
name: globalStream
at: start
to:
stream:
name: globalStream
at: end
response:
- from:
stream:
name: globalStream # Use the global stream for capturing requests
at: start
to:
processor:
name: FilterProcessor
- from:
processor:
name: FilterProcessor
condition: miss
to:
stream:
name: globalStream
at: end
- from:
processor:
name: FilterProcessor
condition: hit # In case the status code match the configured range
to:
processor:
name: RetryProcessor # Route the request to the RetryProcessor
- from:
processor:
name: RetryProcessor
condition: retry
to:
stream:
name: globalStream
at: end
- from:
processor:
name: RetryProcessor
condition: failed
to:
stream:
name: globalStream
at: end


Flow Example

This is an example of a fully configured Retry Flow that retries failed API requests based on status codes, with exponential backoff.

/etc/lunar-proxy/flows/flow.yaml
name: RetryFlow

filter:
url: "api.com/resource/{id}"
processors:
RetryProcessor:
processor: Retry
parameters:
- key: attempts
value: 5
- key: cooldown_between_attempts_seconds
value: 5
- key: cooldown_multiplier
value: 1.5
- key: maximum_cooldown_seconds
value: 3600
FilterProcessor:
processor: Filter
parameters:
- key: status_code_range
value: 400-500
flow:
request:
- from:
stream:
name: globalStream
at: start
to:
stream:
name: globalStream
at: end
response:
- from:
stream:
name: globalStream
at: start
to:
processor:
name: FilterProcessor
- from:
processor:
name: FilterProcessor
condition: miss
to:
stream:
name: globalStream
at: end
- from:
processor:
name: FilterProcessor
condition: hit
to:
processor:
name: RetryProcessor
- from:
processor:
name: RetryProcessor
condition: retry
to:
stream:
name: globalStream
at: end
- from:
processor:
name: RetryProcessor
condition: failed
to:
stream:
name: globalStream
at: end

Flow Components


Troubleshooting

  1. Retries Not Triggering:
    • Verify that status_code_range is correctly configured.
    • Ensure the API response status code falls within the specified range.
  2. Excessive Retry Attempts:
    • Check the attempts parameter and reduce it if necessary.
    • Adjust the cooldown_multiplier to increase wait times between retries.
    • Make sure that in case of long cooldown the value of LUNAR_RETRY_REQUEST_TIMEOUT_SEC is also increased. the default is 100