Retry post request Mechanism in Backend in python flask

104 Views Asked by At

Context: I have one API, where inside the API 3 different external POST APIs are called. And behaviour should be if all 3 APIs give success response, then only overall API should be success. And even if 1 failed we do the rollback on the POST call. Now the issue is with one external API that has very high response time. P98 is 5 sec.

Our service is in Flask, and we have 10 second timeout on external request.post method.

Now we are building a solution where we have to do retry in the backend API itself. So I have 2 solutions, does both consume same server resource?

  1. Retry 3 times on timeout. (3* 10 sec = 30sec)
  2. Increase timeout to 30 sec on request.post call

Does both above approaches consumes same server resource?

1

There are 1 best solutions below

3
tax evader On

Shouldn't timeout and retry configuration usually be done on the client side (requester) as clients have more control over their request timeout limit and retry policy?

I think the second approach (if it's possible) to increase timeout should be more efficient as it requires less communications between client and server but ideally if an attempt fail, it should communicate to the client as soon as possible to let the client decide if it should attempt another retry, so I think the first solution might be more appropriate