Is it possible to retry API request to a target server when we get 5XX ?

When making requests to the target server, if the server responds with a 5xx error. Is it possible to retry again ?

Solved Solved
0 12 5,862
1 ACCEPTED SOLUTION

Yes it is possible to retry if the response from the target server (NOT from Apigee Edge) is 5XX. For example, if the target server responds with a 500, then you could retry the request to a different target server.

To enable retry on 5XX errors, you need to set the "ServerUnhealthyResponse" element with appropriate response codes as unhealthy responses.

For ex: If you want to retry on 500, 502 and 503, then you need to set it as follows:

<TargetEndpoint name="default">
  <HTTPTargetConnection>
      <LoadBalancer>
        <Algorithm>RoundRobin</Algorithm>
        <Server name="target1" />
        <Server name="target2" />
        <MaxFailures>5</MaxFailures>
        <RetryEnabled>true</RetryEnabled>
        <ServerUnhealthyResponse>
            <ResponseCode>500</ResponseCode>
            <ResponseCode>502</ResponseCode>
            <ResponseCode>503</ResponseCode>
        </ServerUnhealthyResponse>
      </LoadBalancer>
      <Path>/test</Path>
  </HTTPTargetConnection>
</TargetEndpoint>

You can read more about retry feature in this link

View solution in original post

12 REPLIES 12

Yes it is possible to retry if the response from the target server (NOT from Apigee Edge) is 5XX. For example, if the target server responds with a 500, then you could retry the request to a different target server.

To enable retry on 5XX errors, you need to set the "ServerUnhealthyResponse" element with appropriate response codes as unhealthy responses.

For ex: If you want to retry on 500, 502 and 503, then you need to set it as follows:

<TargetEndpoint name="default">
  <HTTPTargetConnection>
      <LoadBalancer>
        <Algorithm>RoundRobin</Algorithm>
        <Server name="target1" />
        <Server name="target2" />
        <MaxFailures>5</MaxFailures>
        <RetryEnabled>true</RetryEnabled>
        <ServerUnhealthyResponse>
            <ResponseCode>500</ResponseCode>
            <ResponseCode>502</ResponseCode>
            <ResponseCode>503</ResponseCode>
        </ServerUnhealthyResponse>
      </LoadBalancer>
      <Path>/test</Path>
  </HTTPTargetConnection>
</TargetEndpoint>

You can read more about retry feature in this link

Hi @adevegowda ,

We are noticing strange behavior with the retry.

When our request is retried to a different backend server by apigee, the request body from the previous request is stripped off.  I can't believe that could be true. Do you know about any such behavior? 

 

That sounds very surprising. If you can reliably reproduce that behavior, please contact Apigee support and provide them the information so that they can diagnose the problem. 

Is it possible to retry to only one target server?

@angelfire is this possible?

 

No. Check the documentation.  Retry requires at least two targetservers.

If you want to build in retry, you may wish to consider using Application Integration, which has the capability to run conditional retry, among many other integration scenarios.  Richard Seroter recently posted a useful overview,  and you can also visit the integration cloud forum  here on the googlecloudcommunity site to ask integration-specific questions.

No, as documented, you need multiple targets and RetryEnabled. 

screenshot-20230822-084815.png

 

Hi,

Is it possible to hold the same request for some time (75 seconds) and then retry it to the same Target Endpoint when I receive a 429 error from them?

@kurtkanaskie @dchiesa1@Sai Saran Vaidyanathan@dknezic @ganadurai @Harish123 @shrenikkumar-s @Peeyush_Singhai , @Renuka_atnoor

Can you share the limits on the above retry?

1) What is the max request payload size of per request retry?

2) Is there max number of requests you can keep retry concurrently, say a backend down for 30 secs and there is 20K request in a short time.  How much can you keep?

3) What are other configuration parameters besides maxFailures? like delay retries?

4) What happens to the connection/keep-alive when the API is in a retry state?  Does the synchronous request keep open for max allow per API?

Have you found answers to your questions? Can you please share if you have one.
Thanks

Hi @dchiesa1 @adevegowda @pshah2 @ajith-ajmal @pshah2 @shrenikkumar-s 

My code is working for retry but only in limed sicarios -

1. Retry working for single target host ✔️

2. Retry working for server connectivity (Apigee-->target system) issues and giving the expected retry response (503, 502). ✔️

3. Whenever target system is throwing 500 error to apigee retry mechanism is not working for below code. if I include 500 error status in "ServerUnhealthyResponse" codes by default it considering as server unhealthy and sending 503 error back to source but retry working as expected and for the retry also its giving same error 503.   

Expected output:  Whenever apigee receives 500 (error at data level not in connectivity) form target. Apigee needs to retry once if it fails again, we need same response to back to source. 

Can you please help me on above motioned sicario? 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
<Description/>
<FaultRules/>
<PreFlow name="PreFlow">
<Request/>
<Response/>
</PreFlow>
<PostFlow name="PostFlow">
<Request/>
<Response/>
</PostFlow>
<Flows/>
<HTTPTargetConnection>
<LoadBalancer>
<Algorithm>RoundRobin</Algorithm>
<Server name="target"/>
<MaxFailures>1</MaxFailures>
<RetryEnabled>true</RetryEnabled>
<RetryPolicy>
<MaxRetries>1</MaxRetries>
<!-- Number of retries for 500 errors -->
<ResponseCode>500</ResponseCode>
<RetryOnResponseCodes/>
</RetryPolicy>
<ServerUnhealthyResponse>
<ResponseCode>502</ResponseCode>
<ResponseCode>503</ResponseCode>
</ServerUnhealthyResponse>
</LoadBalancer>
<Path>/testing</Path>
</HTTPTargetConnection>
</TargetEndpoint>