Quota Used/Available Count Inconsistent

Not applicable

Description: The count returned by the Quota Policy is inconsistent and confusing for Integrating users

Noted: https://community.apigee.com/questions/41329/quota-counter-not-consistent.html

We are hoping to implement returning headers so application users can know their limit, available count, and reset time using the following variables:

ratelimit.QuotaPolicy.allowed.count: Allowed count.
ratelimit.QuotaPolicy.available.count: Current available value.
ratelimit.QuotaPolicy.expiry.time: UTC time when the counter resets.

As described in this documentation:

http://docs.apigee.com/api-services/reference/quota-policy

Our current Quota policy is as follows:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Quota async="false" continueOnError="false" enabled="true" name="Quota" type="rollingwindow">
    <DisplayName>Quota</DisplayName>
    <Identifier ref="developer.id"/>
    <Allow count="5000" countRef="app.limit"/>
    <Interval ref="app.interval">1</Interval>
    <TimeUnit ref="app.timeUnit">minute</TimeUnit>
</Quota>

How we are returning the headers:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Add-Rate-Limit-Headers">
    <AssignTo createNew="false" type="response"/>
    <Set>
        <Headers>
            <Header name="RateLimit-Limit">{ratelimit.Quota.allowed.count}</Header>
            <Header name="RateLimit-Available">{ratelimit.Quota.available.count}</Header>
            <Header name="RateLimit-Reset">{ratelimit.Quota.expiry.time}</Header>
        </Headers>
    </Set>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
</AssignMessage>

That is all working as expected, however, when inspecting the headers returned for one Developer the ratelimit.Quota.available.count is inconsistent as we make multiple calls. An example of the count movement is below:

999, 998, 996, 995, 997, 997, 994

The count is usually around what the true count should be but does not consistently, accurately return the count. This behavior is the same using available.count and used.count. Are there any plans to fix this or any workarounds?

Solved Solved
0 4 1,118
1 ACCEPTED SOLUTION

@Benjamin Campbell

It's expected and as per design. Find out the reason below.

  • Quota depends on number of message processors if it's not distributed & synchronous.
  • If you set to distributed, Central Quota Counter is maintained or else, It will be at message processor level. More about same here.
  • Set "Synchronous" to true to update the central quota counter synchronously. More about same here.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Quota async="false" continueOnError="false" enabled="true" name="Quota" type="rollingwindow">
    <DisplayName>Quota</DisplayName>
    <Identifier ref="developer.id"/>
    <Allow count="5000" countRef="app.limit"/>
    <Interval ref="app.interval">1</Interval>
    <TimeUnit ref="app.timeUnit">minute</TimeUnit>
    <Distributed>true</Distributed>
    <Synchronous>true</Synchronous>
</Quota>

You can also watch 4mv4d video that explains same hands on here. Give it a try & let us know what do you see in trace variables. I have just verified same & counter remain consistent if you use above distributed & synchronous set to true in the policy.

Hope it helps. Keep us posted if any.

View solution in original post

4 REPLIES 4

@Benjamin Campbell

It's expected and as per design. Find out the reason below.

  • Quota depends on number of message processors if it's not distributed & synchronous.
  • If you set to distributed, Central Quota Counter is maintained or else, It will be at message processor level. More about same here.
  • Set "Synchronous" to true to update the central quota counter synchronously. More about same here.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Quota async="false" continueOnError="false" enabled="true" name="Quota" type="rollingwindow">
    <DisplayName>Quota</DisplayName>
    <Identifier ref="developer.id"/>
    <Allow count="5000" countRef="app.limit"/>
    <Interval ref="app.interval">1</Interval>
    <TimeUnit ref="app.timeUnit">minute</TimeUnit>
    <Distributed>true</Distributed>
    <Synchronous>true</Synchronous>
</Quota>

You can also watch 4mv4d video that explains same hands on here. Give it a try & let us know what do you see in trace variables. I have just verified same & counter remain consistent if you use above distributed & synchronous set to true in the policy.

Hope it helps. Keep us posted if any.

Thank you! Great explanation, I appreciate your help.

Anytime 🙂 Glad it helps. Keep us posted moving forward if any.

Not applicable

Hi,

I used below line in AssignMessage-

<Headername="RateLimit-Limit">{ratelimit.Quota.allowed.count}</Header><Headername="RateLimit-Available">{ratelimit.Quota.available.count}</Header><Headername="RateLimit-Reset">{ratelimit.Quota.expiry.time}</Header>

its not giving any quota count information in response header. Can someone please help me to get the left/used quota before reaching to the limit.