In APIM currently we have product subscription key level throttling. But obviously if we have multiple API's within the same product, one API could consumes more quota than expected and prevent others being able to use the application. So as per the MS documentation (https://learn.microsoft.com/en-us/azure/api-management/api-management-sample-flexible-throttling) we can use combine policies.
The question is with that approach whether we can use as below,
API-1 300 calls per 60 seconds where product subscription key =123
API-2 200 calls per 60 seconds where product subscription key =123
API-3 200 calls per 60 seconds where product subscription key =123
If so what could be the the total number of calls for the product subscription key? if it make sense.
I took below approach to have combine policies. But it doesn't like.
<rate-limit-by-key calls="50" renewal-period="60" counter-key="@("somevalue" + context.Request.Headers.GetValueOrDefault("Ocp-Apim-Subscription-Key"))" />
<rate-limit calls="10" renewal-period="30">
<api name="AddressSearch API dev" calls="5" renewal-period="30" />
<operation name="Search_GetAddressSuggestions" calls="3" renewal-period="30" />
</rate-limit>
So to have the rate limiting API level I have come up with below which addressed my requirement.
<choose>
<when condition="@(context.Operation.Id.Equals("End point name1"))">
<rate-limit-by-key calls="40" renewal-period="30" counter-key="@(context.Api.Name + context.Operation.Name + context.Request.Headers.GetValueOrDefault("Ocp-Apim-Subscription-Key"))" />
</when>
<when condition="@(context.Operation.Id.Equals("End point name2"))">
<rate-limit-by-key calls="20" renewal-period="30" counter-key="@(context.Api.Name + context.Operation.Name + context.Request.Headers.GetValueOrDefault("Ocp-Apim-Subscription-Key"))" />
</when>
<otherwise>
<rate-limit-by-key calls="15" renewal-period="30" counter-key="@(context.Api.Name + context.Operation.Name + context.Request.Headers.GetValueOrDefault("Ocp-Apim-Subscription-Key"))" />
</otherwise>
</choose>
Hope this helps.