Async events API: RateLimitError avoidance

Hello, we are working on a project and encountering the RateLimitError while using the Async Events API. It seems we add more jobs (events) to the queue within a minute than the allowed limit of 500 events per minute. To address this, we are trying to implement logic to throttle the rate at which events are pushed to the queue.

Is there any “proper” solution to it? How would you handle such scenario? we are thinking of this solution taking in account the doc stating “The total number of events pushed per minute exceeds the defined limits. To overcome this, retry adding events after a minute.”


async function pushEventToQueue(payload) {
    try {
        await queue.push(payload);
    } catch (error) {
        if (error instanceof RateLimitError) {
            console.warn("Rate limit exceeded. Retrying after a minute...");
            // Implement retry logic after a minute
            await new Promise(resolve => setTimeout(resolve, 60000)); // Wait for 1 minute
            await pushEventToQueue(payload); // Retry pushing the event
        } else {
            console.error("Error pushing event to queue:", error);
            // Handle other errors as needed
        }
    }
}

Is it generally a good approach? isn’t those 60 seconds too much to wait? We will be glad for any opinion :slight_smile:

It seems like the recommended solution to me. If it’s rate limited by the minute, waiting a minute makes sure you get past that. :person_shrugging:

Thank you for your assistance. I believe we have managed to work around the issue. However, we encountered an interesting aspect that we would like to clarify.

According to the Async Events documentation, the RateLimitError is described as: “RateLimitError - the total number of events pushed per minute exceeds the defined limits. To overcome this, retry adding events after a minute.”

Our observation was that even the importQueue.getJob(jobId) function affects the rate limit, which was unexpected based on the documentation provided. Could you please confirm if this behavior is intended?

I have no insight on that myself. If you don’t get an answer here, you could try opening a support ticket.