Azure blocking too many invalid API Requests

Bhat, Gurudatth 41 Reputation points
2021-11-12T14:49:40.92+00:00

I am developing one custom throttling solution for azure web API(app service) using APIM policy. When the request failure count is more then some threshold value , APIM will short circuit and send 429 status code. For this, I am using function app which queries error logs from azure application insights and based on logs count requests will get forwarded to API. I want to know, Is there any other simpler solution for handling too many invalid API requests. Is there any flows or limitations of using above solution since I am querying azure application insights(I am querying logs for last hour).

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,291 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,266 questions
0 comments No comments
{count} votes

Accepted answer
  1. Mike Urnun 9,836 Reputation points Microsoft Employee
    2021-11-12T22:16:32.217+00:00

    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!


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.