How to rate limit an API call ? + Integrate that with Stripe ?
Unanswered
Ant posted this in #help-forum
AntOP
I want to build a Next.js 15 application where users can make API requests to perform certain actions (e.g., fetching data or submitting forms). However, I need to ensure that the API is rate-limited to prevent abuse. Additionally, I want to integrate Stripe to handle payments, which will allow users to upgrade their accounts and gain higher rate limits.
8 Replies
@Ant I want to build a Next.js 15 application where users can make API requests to perform certain actions (e.g., fetching data or submitting forms). However, I need to ensure that the API is rate-limited to prevent abuse. Additionally, I want to integrate Stripe to handle payments, which will allow users to upgrade their accounts and gain higher rate limits.
For Rate limiting, if you're deploying to Vercel, you can use [Vercel Rate limiting](https://vercel.com/guides/add-rate-limiting-vercel)
If you're deploying on any other provider, you can check if it has a network level rate limiting option or edge rate limiting available.
If you're deploying on any other provider, you can check if it has a network level rate limiting option or edge rate limiting available.
If not, you can use application level rate limiting with [upstash](https://upstash.com/blog/upstash-ratelimit), or any other provider like DynamoDB
AntOP
which is preferred ?
as in a better practice ?
Network Level or Edge Rate limiting is the best option whenever possible, like with Vercel Rate limiting.
If not available, Application Rate limiting can be used
If not available, Application Rate limiting can be used
I personally use DynamoDB & Upstash, as I deploy either on CF pages or AWS
AntOP
I see Ill look into Edge Rate limiting
Basset Fauve de Bretagne
If your end goal is to have different rate limits per user, application level rate limits is the best, you can do it right before your business logic of the api route or building a middleware to be shared across several endpoints. With that you have more control over when and how to rate limit. Quick way as mentioned is upstash or any other low latency storage.