I am trying with the Quota, but its allowing the requests more than the configurations

I am trying with the quota, and I am expecting allow only 2 request/minute. (as of now for testing purpose i have kept it as two min/request). but its allowing more than 10 - 15 requests after that I am getting as expected error msg, but i should get the error message after 3 request.

Quota configuration as follows

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Quota async="false" continueOnError="false" enabled="true" name="Quota-1" type="calendar">
<DisplayName>Quota-1</DisplayName>
<Properties/>
<Allow count="2" countRef="verifyapikey.verify-api-key.allow_request"/>
<Interval>1</Interval>
<Synchronous>true</Synchronous>
<TimeUnit ref="request.header.quota_timeout">minute</TimeUnit>
<StartTime>2021-6-6 12:00:00</StartTime>
</Quota>

In developer app we have create custom attribute "allow_request" with the value as 2

Thank you..

0 2 47
2 REPLIES 2

Please refer to the distributed element in the quota policy configuration. For your use case, you should set it to true ie

<Distributed>true</Distributed>

https://docs.apigee.com/api-platform/reference/policies/quota-policy#distributed

This will maintain a central counter. Otherwise, requests are processed by one of many Message Processors which will each have their own independent counters leading to the behaviour you're seeing.

Yes, Apigee uses pools of servers to process requests, and in order to coordinate quotas across this pool, Apigee uses a persistent store. ServerA may receive a request, then check and update its quota count. Concurrently, ServerB may then receive a request, and check and update its quota count. Periodically, the servers coordinate and reconcile their counts, via the persistent store.

By default this reconciliation does not happen with each request. The reason for this: if Apigee reconciled quota counts across all proxies, all servers, for each request, it would result in a significant delay for transactional synchronization, driving down maximum possible throughput.

Therefore, Apigee chooses to use "eventually consistent" quota counts. The result is that if you have a small micro-test, in which you configure a quota limit of 2 per minute, then send 20 requests into the proxy within 1 second, the rate limit (Quota) policy will not restrict the calls. You may see 10-15 requests handled, before the quota policy limits the request. This is by design.

By contrast if your rate limit requirement is more ... mainstream, such as 1000 requests per minute, you still may receive some "fuzzy" enforcement, for example the policy may allow 1008 requests in a minute before limiting the calls, but the deviation from the configured limit and the enforced limit will be much smaller.

As Dane wrote, If you REALLY want transactional limits, you can set the Distributed element to true. Be aware this will greatly reduce the maximum potential throughput for your API proxy, and it may affect the performance of other proxies in your organization as well. Take care when choosing to use Distributed =true. It will work well in small demonstrations, but may introduce implications that are not good for larger scale use.