Quota policy implementation

Not applicable

@Ozan Seymen@arghya das@Srividya Annapragada@Dino@santosh_ghalsasi

Hi Team,

I have a requirement to implement quota policy as below.I am to maintain separate counters based on type(input parameter, type : A or B).A type specific count breach check is done at the time of receiving the request from calling entity.Also, type specific Counter increment done upon receiving response from the downsteam system based on response code (For 2xx and 4xx response codes counter is incremented and for 5xx counter should not be incremented)

Thanks in advance.

0 7 293
7 REPLIES 7

@Madhuri Sridharan , Welcome to Apigee Community.

It's definitely doable. Did you give it a try using Quota policy ? Are you stuck at any point of time?

I am planning on maintaining ACounter and BCounter in KVM and comparing it with the quota limit value in the preflow. Based on the response code, I will increment the counter and put the new value in KVM in the target postflow.

@Madhuri Sridharan , You DO NOT need to maintain counters / increment counters in KVM. Quota policy does the same. Did you give it a try ? Where exactly you see an issue ?

I have to send the available count for that particular type in my response. Hence I am using separate counters. Steps followed:

1. Check if type is A or B in input

2. Fetch current value of ACounter and BCounter from KVM

3. Have a quota policy to fetch the Quota Limit value of the day for the app.(limit is same for both types)

4. Check if ACounter/ BCounter value is less than Quota limit and call the downstream system

5. If response code is 2XX or 4XX, increment respective counter and put the value in KVM. Also send this field in response.

@Madhuri Sridharan , Available count is available in flow variables out of the box once quota policy executes. You don't need to maintain same in KVM. KVM is an overkill here. I will keep you posted with working example. Give it a try in the meantime. Keep us posted if any.

@Madhuri Sridharan , You said per app in point 3. If i understand correctly, You need quota per app & different counters based on request input A or B. If i am not wrong you would like to track different counters based on app also right ?

@Madhuri Sridharan, You could use the <Identifier> element of the quota policy as the counter and set it to a composite key. Then you would not have to use the KVM.

For example, create a composite key via a Javascript callout prior to the Quota

var type = context.getVariable( "request.header.X-Type");
var client_id = context.getVariable( "apigee.client_id");
context.setVariable("quotaCompositeKey", type+client_id);

Then use that key in the Quota policy

<Quota async="false" continueOnError="false" enabled="true" name="QuotaByApp" type="flexi">
    <DisplayName>QuotaByApp</DisplayName>
    <Properties/>
    <Identifier ref="quotaCompositeKey"/>
    <Allow count="10" countRef="accesstoken.appQuotaLimit"/>
    <Interval ref="accesstoken.appQuotaInterval">1</Interval>
    <TimeUnit ref="accesstoken.appQuotaTimeunit">minute</TimeUnit>
    <Distributed>true</Distributed>
    <Synchronous>true</Synchronous>
</Quota>

In this case the same App can pass different X-Type header values (e.g. A, B).