Does API function timeout if it’s triggered by multiple cron jobs?
I need to send a newsletter to 20k subscribers. Resend doesn’t yet support bulk email sending, so I want to build my own using Resend, Vercel Cron and Next.js API route.
I am not certain though, will a serverless function timeout if I keep triggering it via cron every second for like half an hour?
22 Replies
each function call spawns a new lambda
Myeah. But there is something about warm/cold lambda
cold lambda is when the lambda takes some time to start
with 20k calls instantly
some of them will suffer from that
majority of them wont
Yeah but once it’s warm, wouldn’t it try using the same warm lambda? And then eventually timeout?
you should 100% do a blank run with a smaller amount and see how it handles
Definitely. I am still not sure this is the best way to do this in serverless
that aspect of routing between lambdas is only to aws to deal with
in the real world
if you batch those functions calls
like 500 blocks each
most of them will hit the same warm lambdas after some calls
I will try to batch a bit also. Resend can send 10emails a second, so I can send around 200 emails in 30 sec in a serverless function
about the timeout
iirc the pro version of vercel is around 60s
Yes but it says better run 30-60 secs. And generally lambdas are made to run up to a few secs max
The reason I am asking because I was confused about a warm lambda, if it will try to use the same one for same job cuz it’s warm, and eventually timeout. Need to test that. On localhost the response time was adding up for some reason, the more I was calling same function. But I was testing it recursively, maybe that’s why
you can check this video to have a different idea on how to do it
Web Dev Cody
YouTube
How I generated 10,000 PDFs in seconds using SST
📘 T3 Stack Tutorial: https://1017897100294.gumroad.com/l/jipjfm
🤖 SaaS I'm Building: https://www.icongeneratorai.com/
💬 Discord: https://discord.gg/4kGbBaa
🔔 Newsletter: https://newsletter.webdevcody.com/
📁 GitHub: https://github.com/webdevcody
📺 Twitch: https://www.twitch.tv/webdevcody
🤖 Website: https://webdevcody.com
🐦 Twitter: https://twitt...
main issue probably will be the first lambda, the trigger, to be alive for the 20k
you can probably do a "fan out" approach to it
Thnx I will try looking into it! Long running jobs in Vercel/Next are not very well documented…
To be fair lambdas / serverless function aren't designed for long running jobs I'd say
with aws you have more flexibility around lambdas
You can always rent a VPS ( a server that you own ) and run your job there
with vercel you are tied to that nextjs should/can do
Yeah… I know. I would just like to keep it all in one code base. Just to send this newsletter now I have to start VPS, maintain it etc.). I rather have something that is hacky and works but in the same Next.js codebase.
So Vercel Cron + multiple serverless function triggers was my last hope before getting to something like Qstash, or running a separate node.js app in VPS…
Here you call the functions without requiring to return a response right?
yep
if they fail for some reason, sucks to suck
Well, I will be calling my Postgres db on every call, checking for unsent emails and then after successfully sending, marking every user row as sent. So should be fine even if some of them fails. Failed ones will be retried on other calls.