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
Erisa6mo 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
Aflina6mo 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-Jak36mo 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
Aflina6mo 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-Jak36mo ago
The doc Erisa sent goes over the built in rate limit capabilities. Everything else would have to be done in a worker.
Aflina
Aflina6mo 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
More Posts
Store a JWT to be pulled from a workerI'm need a worker to attach a JWT in the headers of a call to a 3rd party API. This JWT should be repages functions The server running locally is abnormal 500I started pages functions locally through wrangler, which sends an http request and returns 500 to tRequest to URL on the same zone but in CNAME configurationHello, I have a weird behavior that I have an hard time debugging. I reach out my worker via my custAfter the Discord failure, a sharp increase in visits by 33% from Singapore (and the website is fromSince the Analitics failure on November 2-6, 2023, statistics show a huge number of visits to my webIs there a way to use `pg` in a Next.js project setup with `@cloudflare/next-on-pages?I have project that is setup following https://developers.cloudflare.com/pages/framework-guides/deplA record broken????ok so bascily i set an A record and it was working perfectly fine like going good with no issues but"EvalError: Code generation from strings disallowed for this context"I use sveltekit for server side rendering. when I enter the speicific page.svelte that import "@moA record what do i put i cant find anything about itok so basicly for my a record i need to put an ipv4 but what do i put for that ipv4 as ive tried my Customizing Zero Trust Warp posture checksI'm interested in know custom posture checks are possible? For instance running a custom script, or How to do client-side rewrites on statically exported Next.js site?I have a statically exported Next.js site, meaning a single-page app built with `next export` and up