Currently We are triggering rate-limiting functionality, each time when user hits the service, code will check for the count in redis, if submission count is within the configured limit, we increment the count and allow the user to perform the operation otherwise we will recursively check for the limit for every 1 sec until validation succeeds.
async function _rateLimit() {
const key = als.get("instanceId");
let islimitExceeded = await redisClient.checkSubmissionCount(key,
constants.REQUEST_LIMIT); // REQUEST_LIMIT is the configured limit lets take as 10
if (!islimitExceeded) {
await redisClient.incrementSubmissionCount(key);// increment the count and allow the user to perform the operation
}
else {
await util.promisify(setTimeout)(1000).then(_rateLimit);
}
}
Now the requirement is to throw the error if the limit is still exceeded(islimitExceeded=true) even after 10 seconds recursive check.
Help on this scenario . Thanks.