Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

audiojames's avatar

Throttle Vapor Queue for sending emails...

We are in the process of moving our application to vapor, and have come across an issue when sending multiple emails. As part of the sign up process, admins can upload a csv with perhaps thousands of users. This triggers a welcome email to be sent to each user. We use amazon SES for mailing, and that has a send limit of 14 per second. Previously we were able to throttle the queued jobs with redis to ensure we don't exceed this limit and get a bunch of unnecessary failed jobs.

With vapor, it is very possible that SQS will process these jobs at a rate higher than SES can cope with, resulting in failed jobs and emails not getting sent. Is there a good way around this?

I am aware we can increase the send limit with SES, but that still leaves a hard limit that we may exceed...

0 likes
6 replies
bugsysha's avatar
bugsysha
Best Answer
Level 61

Queue those emails and add delay to them. Take the count of users and divide it by the limit per second. That will give you max delay. Start from 0 and increment it for every chunk.

1 like
audiojames's avatar

Yeah, I was trying to avoid that as it just costs more in unnecessary lambda time, but maybe that is the only way...

bugsysha's avatar

Not sure how would you save when execution time should be roughly the same.

audiojames's avatar

Perhaps I misunderstood, is there a way to add delay to a vapor SQS queue?

Please or to participate in this conversation.