I want to limit my products like this:
- starter: no parallel calls (only allow synchronous calls)
- premium: 10 parallel calls (allow asynchronous call with a limit)
The service behind the api gateway needs some time so some people want to make asynchronous calls to get more results.
The only limitations I found from azure are rate and quota limits. But their limitations are for calls per time, I need it for parallel calls.
I thought about this logic:
<inbound>
<http-call>
send user id to a azure function, that increases the counter for the user, returns the current counter
</http-call>
<when>
compare counter value with the product limit (x = 0 for starter or x <= 10 for premium)
if true route to the service, if false generate a "too many requests" response
</when>
</inbound>
<outbound>
<http-call>
decrease the counter
</http-call>
</outbound>
I am not sure if this is the best logic, because the function needs time to update the values. Is there any way to hold some kind of "shared variable", that can be accessed by every requests to check the counter in the api management and not by an external function?