Quota policies in series

hari_vr
Participant IV

Question in short:
In a scenario where multiple quotas have to be checked one after the another for a set of API Proxies (lets say at the product level, developer level and developer app level, in that order), in case one of the quota policies fails, is there any way to roll back the quota that was incremented in the preceeding quota policies?

To elaborate, if we assume the below

6825-apigeequotaquestionstructure.png

In each APIProxy, if we assume the below policies in the preflow:

    <Step>
        <Name>OAuthv2.VerifyAccessToken</Name>
    </Step>
    <Step>
        <Name>Quota.Product</Name>
    </Step>
    <Step>
        <Name>Quota.Developer</Name>
    </Step>
    <Step>
        <Name>Quota.App</Name>
    </Step>

Lets say that the count limits for these policies are 20 per hour for Quota.Product (Pdt1), 15 per hour for Quota.Developer (Developer1) and 10 per hour for Quota.App (App1).

Assuming that 10 transactions have been handled by APIProxy1 the first thirty seconds, the quota available counter would be 10,5 and zero respectively.

When the next transaction comes in for APIProxy1, the Quota.Product policy will process it and pass it on, decreasing available counter to 9. Quota.Developer will process it and pass it on, decreasing available counter to 4 and Quota.App will fail because the quota limit has already been reached.

Now the issue here is that the quota used counter has been incremented at the Product and at the Developer level even though the transaction was rejected at the App level quota policy, thus eating up available quota. Any further transactions (say to APIProxy2 or APIProxy3) would be rejected as well, and this would further decrease the Product and Developer level quota which could ahve been used elsewhere.

How can we mitigate this issue? Is there any way to undo the increment in the quota counter? Or is this a design issue and needs a complete design overhaul?

Tagging @Sudhee Sreedhara since he had written up a good article on using multiple quotas here.

0 2 125
2 REPLIES 2

sidd-harth
Participant V

Hi @Hari, I am not sure but maybe we can use ResetQuota policy in this scenario. As per my understanding, Reset Quota policy can be used for Increasing Quota.

You have 20 per hour for Quota.Product (Pdt1), 15 per hour for Quota.Developer (Developer1) and 10 per hour for Quota.App (App1).

So when an 11th call is made App1 will give an error & flow will be changed to error flow. Here in error flow, we can use FaultRules to add a couple of ResetQuota's with specific conditions to match and reset(increase) the quota of Pdt1 & Developer1 by 1.

As long as App1 gives a Quota error it is going to enter error flow and resets the Pdt1 & Dev1 quotas by 1.

Note - I haven't tried this approach yet, just mentioned the solution which came to my mind after reading the question.

I will try this approach & update this answer if possible.

Yes, I had considered this option. It is an inelegant option (lots of ifs and conditions), but it is definitely a workable solution. Thanks!

An easy option is to accept the problem and just increase the quota values by about 5-10% to cover any failures or quota leaks that can occur.

In both these solutions, I am wondering what effect this will have on monetization when it comes into the picture.