Hello @Bhat, Gurudatth
APIM provides throttling policies that'll enable you to implement the same solution in a more efficient manner. In particular, you'll want to examine how the <rate-limit-by-key />
and <on-error />
policies work.
Here are their docs:
Here's a blog post that seems to be going over a similar workflow that you can leverage & customize to your solution: "API Management : Customize throttling message"
You can instead use the <rate-limit-by-key />
policy where the increment condition can be error codes received from your backend service occurring over the specified period & the number of times you define. For getting the error code & other info you need from the backend response, please review the policy expression feature & context variable of APIM.
I hope this helps, please let me know if you need further assistance implementing this solution and I'd be happy to help!