How to setup retry when the per minute limit is reached for request methods

Hi Team,

I have a marketplace app where the requests are failing due to the per minute limit being reached. I have 3 request methods which are performed whenever a new contact is created or update in Freshsales and a specific condition is satisfied. When a large number of records are imported in Freshsales, the app fails to trigger the request methods for many records and this is happening due to the per minute limit being reached.

In the catch block, I have entered the below code,

catch (error) {
      attempts++;
      console.error(`Attempt ${attempts} failed. Error:`, error);

      // Check if the error is related to the API rate limit or connection error
      if (error.status === 429) {
        console.log(`Retrying in ${retryDelay / 1000} seconds due to connection error...`);
        await busyWaitDelay(retryDelay); // Use the custom busy-wait delay function here
      } else {
        console.error("Non rate limit error: ", error);
        throw error; // If it's not a rate limit error, rethrow the error
      }
      if (attempts >= maxAttempts) {
        console.log("Max retry attempts reached for email: ", emails);
        throw new Error('Max retry attempts reached.');
      }
    }

Unfortunately, this is not working and the retry does not happen. I am having a 3 mins delay for the retry and hence did not try the suggestion in the below link,

Can someone let me know on how I can have the retry setup for the per minute limit being reached?

I subclass my web requester and add the logic for throttling. That helps me avoid hitting the limit.
You can likely find a library that does this for you. It’s a fairly common issue.

That way, you will not need to rewrite that logic in every request.

Hi Christian,

Thanks for your response. I tried different methods of throttling (example using a counter which can reset after 1 minute) but it does not work because the serverless app re-instantiates when a new event is received. Due to this, the counter keeps starting from 0 for every new event. I also tried having a separate helper.js where again the same issue happened.

For now, I have implemented a retry mechanism using Scheduled events so that the failed requests can be retried - Freshworks Developer Docs | Configure scheduled events

The limitation here is that we can scheduled events after 5 mins only (as we can’t use setTimeout or setInterval functions).

Also for accounts where high number of requests are received, working on increasing the per minute limit based on requirements.

Thanks

Ugh yeah - you would have to use a persistence layer to store each request with a timestamp. Then, query that time period for the total.

I mainly do web API, so my web requestor is a Singleton.