How to rate limit calls in azure function app?

Deshmukh, Vijit 496 Reputation points
2023-10-04T08:01:32.4166667+00:00

Hi Team,

We are using azure function app, whose various functions is being used as api.

Is there any way we can limit the function calls e.g., 10 calls/min. from azure portal.

Or anything that can be implemented from Azure front-door as well.

Please, guide on this.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,323 questions
Azure Front Door
Azure Front Door
An Azure service that provides a cloud content delivery network with threat protection.
584 questions
{count} votes

Accepted answer
  1. JananiRamesh-MSFT 21,861 Reputation points
    2023-10-04T13:46:03.78+00:00

    @Deshmukh, Vijit Thanks for reaching out. you can use Azure Front Door to limit the number of requests. You can configure rate limiting by using custom WAF rules. When you configure a rate limit rule, you specify the threshold, which is the number of web requests that are allowed from each socket IP address within a time period.

    Reference: https://learn.microsoft.com/en-us/azure/web-application-firewall/afds/waf-front-door-rate-limit-configure?pivots=portal

    {
      "name": "RateLimitRule",
      "priority": 1,
      "ruleType": "RateLimitRule",
      "rateLimitDurationInMinutes": 1,
      "rateLimitThreshold": 100,
      "matchConditions": [
        {
          "matchVariable": "RemoteAddr",
          "operator": "IPMatch",
          "negateCondition": false,
          "matchValue": ["0.0.0.0/0"]
        }
      ],
      "action": "Block"
    }
    

    The above sample rule will block any IP address that makes more than 100 requests in one minute.

    Note:

    A few considerations to keep in mind while you determine threshold values and time windows for rate limiting:

    • Larger window size and smaller thresholds are most effective in preventing against DDoS attacks.
    • Setting larger time window sizes (for example, five minutes over one minute) and larger threshold values (for example, 200 over 100) tend to be more accurate in enforcing close to rate limits thresholds than using the shorter time window sizes and lower threshold values.

    If the threshold is low enough, the first request to the new Azure Front Door server could pass the rate limit check. So, for a low threshold (for example, less than about 200 requests per minute), you might see some requests above the threshold get through.

    So, you cannot keep the threshold at 10 and expect it to work. You need a higher threshold like 200 or more.

    If you need it for 10 calls/min, then Front Door is not the right choice.

    Reference thread: Azure FrontDoor WAF rate limit unexpected behavior - Microsoft Q&A

    Alternatively, you can also limit the number of function calls per minute using Azure APIM.

    Azure API Management provides a variety of API security options for incoming requests. You can configure rate limits on your API Management instance to limit the number of requests per minute.

    To learn more about how to configure rate limits in Azure API Management, please see https://learn.microsoft.com/en-us/azure/api-management/api-management-sample-flexible-throttling#configure-rate-limits-for-your-api

    let me know incase of further queries, I would be happy to assist you.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful