APIProduct Quota Question

Hello all . Thank you for helping answer question.
I am new to Apigee and I would like to know if  the following statements true ?

1. APIProduct quota settings will override APIProxy's quota settings .
2. APIProducts quota unit  "day" would mean 24 hours starting 00:00:00 UTC ?
3. APIProducts quota unit "month" would mean rolling window of 30 days  or the first day of the calendar month?


And . 
1. I understand APIProxy's allow us to implement quotas using xml . Is there a similar mechanism for APIProcucts ?

Solved Solved
2 6 191
1 ACCEPTED SOLUTION


@vimystic wrote:

When we first set the time unit (default or calendar) ,


Hi - I'm sorry, the Quota policy is a flexible policy, and perhaps the documentation is not as clear as it might be.  "default, flexi, and calendar" are Quota TYPES.  That table deals with three of the different TYPES of quota you can define. And the table attempts to describe the differences in the way the different types of quota work, with respect to resetting the count. 

The Time Unit is going to be something like minute, hour, day, week, or month. 


@vimystic wrote:

I understand it will reset at the end of they day, week, month etc. Does this mean the existing time until the end of the unit gets a pro-rated quota or the full quota ?


As noted in the documentation, the reset of the Quota count is different for each different TYPE of quota.  Only in the case of the default quota type does the count reset exactly at the end of the time period. It does not mean that the Existing time until the end of the unit gets a prorated quota. 

An example, suppose you define a default quota with a "week" timeunit.  Default means you don't specify a particular start time.  so the quota counting interval is "start of week until end of week".  The documentation doesn't explicitly state it, but I believe "start of week" refers to Monday at 00:00.   You define other parameters (count and interval) so that the quota is enforced as 1000 requests per week. If the client doesn't send any requests in until Friday, the client still has 1000 requests remaining until Monday at 00:00. If the client waits until Sunday to begin sending requests, then the client can send 1000 requests until Monday 00:00 (or the second after Sunday 23:59:59 if you like). 


@vimystic wrote:

Is there a way to nest a rolling window within an existing quota policy? for example. Would it be possible to set a quota limit of 10,000 per month , but also set a rolling window limit of 1000 per day ? 
(update) I read about   Spike Arrest Policy . Is that the optimal solution ?


Not "within" the policy, but Yes, you can compose two Rate Limits in the same API proxy. The simple way is to include 2 Quota policies in the flow.  One for the limit of 10,000 per month (a Calendar or default quota type I suppose), and one for a rolling window Quota with 1000/day.  The request is allowed only if both Quota policies succeed. If either reject then there is a 429 Too Many Requests sent back. I believe you will want to insure you use a different identifier for each policy. You don't need a SpikeArrest for this. Two successive Quota policies should do it. 

There is one nuance - it is possible for the first Quota to pass and the second (let's say the rolling window) to reject. That means the count for the first quota policy - 10k requests per month - would be incremented, even though the request itself was not rate limited.This may or may not be what you want.  I can imagine that you might want to count the requests that are over the daily limit, on the monthly limit.  If for some reason you do not want to count them, you need to insert a ResetQuota policy in the FaultHandler for the RateLimitExceeded fault.  Basically , grant credit for the monthly credit, if the daily limit ratelimit fires. I hope this is clear.

 

View solution in original post

6 REPLIES 6

1. An API Product quota on its own does nothing. A quota policy in your proxy needs to refer to values set in the API product.

2. This can be configured to suit your requirement https://cloud.google.com/apigee/docs/api-platform/reference/policies/quota-policy#starttime

3. This will vary depending on type attribute used in your quota policy https://cloud.google.com/apigee/docs/api-platform/reference/policies/quota-policy#quotapolicytypes

Thank you very much for the reply @dknezic

At the moment , I am aware that we can set the following values on an APIProduct , using apigee api's , as shown in the image . 

Screenshot 2023-06-20 at 3.44.21 PM.png

Is there a way to add the StartTime and Type Attributes as well ?

Would these be correct?

1. quotaStartTime 
2. quotaType 




Is there a way to add the StartTime and Type Attributes as well ?

No. The quotaType is specified in the Quota policy.  The starttime applies only to specific quota types, and that is also something you specify in the quota policy. 

What problem are you trying to solve?  In my experience, the "quota model" -- that is to say, how the quota will work, what gets counted, is it a rolling window or per-day quota, etc --  is something the API product team decides. And then the product team can set different parameters on that model, for different API Products.

It's not the case that the API Product team wants a large variation in the kinds of Quotas.  usually they select ONE model. 

So I'm interested to understand why you think this would be valuable.

 

Thank you @dchiesa1 .


I now understand that StartTime and Type belong to a quota policy that is assigned in an APIProxy . 

The quota, quotaInterval and quotaTimeUnit are settings available in an APIProduct and can be  referenced by the APIProxies that have a quota policy if needed. 

I now have some more questions about this table. 

Screenshot 2023-06-21 at 2.28.21 PM.png

1 . When we first set the time unit (default or calendar) , I understand it will reset at the end of they day, week, month etc. Does this mean the existing time until the end of the unit gets a pro-rated quota or the full quota ?

2. Is there a way to nest a rolling window within an existing quota policy? for example. Would it be possible to set a quota limit of 10,000 per month , but also set a rolling window limit of 1000 per day ? 
(update) I read about   Spike Arrest Policy . Is that the optimal solution ?

Thanks again for helping out. 
(I edited 3 questions into 1 to simply , apologies for the verbosity)


@vimystic wrote:

When we first set the time unit (default or calendar) ,


Hi - I'm sorry, the Quota policy is a flexible policy, and perhaps the documentation is not as clear as it might be.  "default, flexi, and calendar" are Quota TYPES.  That table deals with three of the different TYPES of quota you can define. And the table attempts to describe the differences in the way the different types of quota work, with respect to resetting the count. 

The Time Unit is going to be something like minute, hour, day, week, or month. 


@vimystic wrote:

I understand it will reset at the end of they day, week, month etc. Does this mean the existing time until the end of the unit gets a pro-rated quota or the full quota ?


As noted in the documentation, the reset of the Quota count is different for each different TYPE of quota.  Only in the case of the default quota type does the count reset exactly at the end of the time period. It does not mean that the Existing time until the end of the unit gets a prorated quota. 

An example, suppose you define a default quota with a "week" timeunit.  Default means you don't specify a particular start time.  so the quota counting interval is "start of week until end of week".  The documentation doesn't explicitly state it, but I believe "start of week" refers to Monday at 00:00.   You define other parameters (count and interval) so that the quota is enforced as 1000 requests per week. If the client doesn't send any requests in until Friday, the client still has 1000 requests remaining until Monday at 00:00. If the client waits until Sunday to begin sending requests, then the client can send 1000 requests until Monday 00:00 (or the second after Sunday 23:59:59 if you like). 


@vimystic wrote:

Is there a way to nest a rolling window within an existing quota policy? for example. Would it be possible to set a quota limit of 10,000 per month , but also set a rolling window limit of 1000 per day ? 
(update) I read about   Spike Arrest Policy . Is that the optimal solution ?


Not "within" the policy, but Yes, you can compose two Rate Limits in the same API proxy. The simple way is to include 2 Quota policies in the flow.  One for the limit of 10,000 per month (a Calendar or default quota type I suppose), and one for a rolling window Quota with 1000/day.  The request is allowed only if both Quota policies succeed. If either reject then there is a 429 Too Many Requests sent back. I believe you will want to insure you use a different identifier for each policy. You don't need a SpikeArrest for this. Two successive Quota policies should do it. 

There is one nuance - it is possible for the first Quota to pass and the second (let's say the rolling window) to reject. That means the count for the first quota policy - 10k requests per month - would be incremented, even though the request itself was not rate limited.This may or may not be what you want.  I can imagine that you might want to count the requests that are over the daily limit, on the monthly limit.  If for some reason you do not want to count them, you need to insert a ResetQuota policy in the FaultHandler for the RateLimitExceeded fault.  Basically , grant credit for the monthly credit, if the daily limit ratelimit fires. I hope this is clear.

 

Thank you both for all the answers.