How can I implement rate limits on Next.js APIs and tRPC?
Unanswered
Spectacled bear posted this in #help-forum
Spectacled bearOP
I’m working on a Next.js project with tRPC for my API layer. I want to implement rate limits to prevent abuse and protect the server from potential issues. Can someone guide me on how to set up rate limits effectively for Next.js APIs and tRPC? Any advice or code examples would be greatly appreciated. Thanks in advance!
5 Replies
u can use Redis(Vercel KV or Upstash). my sample codes
https://github.com/tfutada/zenn-nextjs/blob/main/middleware-2.ts
https://github.com/tfutada/zenn-nextjs/blob/main/middleware-2.ts
Spectacled bearOP
Is there any other option then using Redis ?
My application doesn't need to scale across multiple instances.
oh i thought you host it on Vercel. if it is self-hosted on a single instance, you can use a global hash map.
Node.js is single thread event loop. so no worries about mutex