Monthly user quota management / rate limiting

Hi! I want to build a SaaS product and have an API available to clients (requests allowed via domain names or API Key) and I want to have subscription plans with monthly requests limits. Is there any way to do this before the request hits the worker? (I want to prevent requests costs if a user already used his quota). Is therey any cost effective way to do this? Thank you!
6 Replies
Erisa
Erisa12mo ago
The only way to do rate limiting before hitting a Worker is to use https://developers.cloudflare.com/waf/rate-limiting-rules/ which have various limitations on how you can set them up
Aflina
AflinaOP12mo ago
@Erisa | Support Engineer Is there any way to return a cached response before hitting the worker? I'm thinking about a solution where I have the quota in my D1 and then I either use WAF (but that has limitations) or I set a cache with a X expiration date Will cloudflare snippets allow me to do this? Using cache perhaps?
Cyb3r-Jak3
Cyb3r-Jak312mo ago
Workers run in front of cache so they will always run if the request makes it past the WAF. Snippets would allow you to return a response before hitting the worker but snippets don’t have access to cache or bindings so you wouldn’t be able to track requests.
Aflina
AflinaOP12mo ago
@Cyb3r-Jok3 thanks for the reply! Do you know if there is any way of doing what I want with snippets or other tool before reaching the worker? I love workers but I can't make my saas product work without limits 😢
Cyb3r-Jak3
Cyb3r-Jak312mo ago
The doc Erisa sent goes over the built in rate limit capabilities. Everything else would have to be done in a worker.
Aflina
AflinaOP11mo ago
I thought since we could use Cache API in the worker we could perhaps do the same in the Snippet. Thanks anyway! @Erisa | Support Engineer Is something planned to allow cached responses before hitting the worker? It would be great so my team can decide if cf workers are viable for us. Thank you 🎄
Want results from more Discord servers?
Add your server