daun
daun•10mo ago

Rate limiting / limiting paginated queries

Hi Convex community 🙂 I'm looking for a way to rate limit or limit paginated queries, or related workarounds. I've already read the docs - https://docs.convex.dev/database/pagination however, I could not find a good way to limit number of calls, or number of paginated contents of paginated queries from the server side.
6 Replies
Indy
Indy•10mo ago
Depending on what sort of rate limiting use case you're thinking of this may also be useful: https://stack.convex.dev/help-my-app-is-overreacting
Help, my app is overreacting!
Reactive backends like Convex make building live-updating apps a cinch, but default behavior might be too reactive for some use cases. Not to worry! L...
daun
daunOP•10mo ago
Thanks, I've read the thread, I'm asking this to prevent too much resource being somewhat automatically scraped or therefore too much network bandwidth is used. However I wonder if it's possible to limit the pagination cursor from the server-side query function. For example, I'm trying to implement 'Free tier users can only retrieve 500 posts.' I can easily check if the user is authenticated or not already but I'm not sure if limiting pagination cursor is available in the API.
erquhart
erquhart•10mo ago
GitHub
convex-nextjs-app-router-demo/convex/posts.ts at bcc7749acb93ad29f4...
Demo showing a Next.js App Router app powered by Convex backend - get-convex/convex-nextjs-app-router-demo
ian
ian•10mo ago
for a free tier you could also do more hard-coded offset pagination. e.g. the first request fetches the first 100. The next fetches 200 and returns the last 200, and you limit it to 500 max. Then for pro you could have infinite scroll. just a thought
ian
ian•8mo ago
I just added a helper for rate limiting in convex-helpers@0.1.38. More info in this new Stack post: https://stack.convex.dev/rate-limiting
Implementing Rate Limiting with only two numbers
Implementing application rate limiting when you have fast access to a database with strong ACID guarantees. Token bucket and fixed window, with fairne...

Did you find this page helpful?