How to implement concurrency rate limiting with Node/Express?

59
November 21, 2020, at 5:40 PM

For "normal" rate limiting, where I want at most N calls per T time (e.g. no more than 2000 calls in an hour), I can just count each hit.

However, for highly scalable and concurrent APIs distributed across several workers, I need to support concurrency of up to 20+ simultaneous API calls per second.

Say I want to rate limit 20 max concurrency limit. So, I need to be able to reliably figure out whether there are 20 concurrent calls at this very instant and block the 21st one, saying that it's over the rate limit.

So, I'm thinking that this needs to be enforced in one of two ways:

  • Infrastructure level where you limit the maximum number of workers (compute instances) assigned to a specific type of task
  • Maintain some kind of concurrency score and update it with each API call. This would be updated up to 20 times per second, so it needs to be extremely performant and accessible by a fleet of instances. Something like a redis in a local network in a single datacenter region.

Which of these is better? Or perhaps there is some other standard solution for this problem? What are the best practices for implementing rate limiting for concurrency?

READ ALSO
PDFTron : - how to get pdf file from gridfs (mongodb), add watermark in it and send it to client?

PDFTron : - how to get pdf file from gridfs (mongodb), add watermark in it and send it to client?

I am using Gridfs to store large files in mognodbNow I am using PDFTron for pdf editing and want to watermark pdf

74
How nodejs handles two different customer request (at same second)? Please explain the flow?

How nodejs handles two different customer request (at same second)? Please explain the flow?

How node js handles two different customer request (at same second)? Please explain the flow? I know java script is single threaded will place the request on the event loop and while waiting for response will imitate other request and when response data comes data will be given back to user

29
Error: PostCSS plugin tailwindcss requires PostCSS 8

Error: PostCSS plugin tailwindcss requires PostCSS 8

I installed the new tailwindcss version 20 and I've got the following error

281
Angular post request refused, but nodejs post request works

Angular post request refused, but nodejs post request works

I have an express app which listening on port 5000 like this:

71