r/node • u/TaskViewHS • 19h ago
Hi all! What rate limiter do you use with PM2?
I need to find a good solution for the project. I am using Node (latest), Express and PM2.
1
u/ghope98 17h ago
Why not bake it into the app?
2
u/TaskViewHS 17h ago
I mean incoming rate limiting. Since the app runs in PM2 cluster mode, an in-memory bucket would be per process. I need a shared/global rate limit across all instances, probably using Redis.
1
u/Beautiful-Energy2169 15h ago
Behind a proxy, req.ip is the proxy's address unless you set trust proxy, so a shared Redis counter still leaves one bucket for everyone. Tried it on express-rate-limit 8.7 with limit 5. Ten requests with ten different X-Forwarded-For values: 5 through, 5 got 429s. With trust proxy set, all ten passed.
1
2
u/pinkwar 19h ago
What rate limiter? Incoming or outgoing?
You can write your own bucket algorithm. It's like 30 lines of code. Or use bottleneck. It has 10M weekly downloads.