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
Neto
Neto16mo ago
each function call spawns a new lambda
edgaras
edgarasOP16mo ago
Myeah. But there is something about warm/cold lambda
Neto
Neto16mo ago
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
edgaras
edgarasOP16mo ago
Yeah but once it’s warm, wouldn’t it try using the same warm lambda? And then eventually timeout?
Neto
Neto16mo ago
you should 100% do a blank run with a smaller amount and see how it handles
edgaras
edgarasOP16mo ago
Definitely. I am still not sure this is the best way to do this in serverless
Neto
Neto16mo ago
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
edgaras
edgarasOP16mo ago
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
Neto
Neto16mo ago
about the timeout iirc the pro version of vercel is around 60s
edgaras
edgarasOP16mo ago
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
Neto
Neto16mo ago
you can check this video to have a different idea on how to do it
Neto
Neto16mo ago
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
edgaras
edgarasOP16mo ago
Thnx I will try looking into it! Long running jobs in Vercel/Next are not very well documented…
Neto
Neto16mo ago
inchris.
inchris.16mo ago
To be fair lambdas / serverless function aren't designed for long running jobs I'd say
Neto
Neto16mo ago
with aws you have more flexibility around lambdas
inchris.
inchris.16mo ago
You can always rent a VPS ( a server that you own ) and run your job there
Neto
Neto16mo ago
with vercel you are tied to that nextjs should/can do
edgaras
edgarasOP16mo ago
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?
Neto
Neto16mo ago
yep if they fail for some reason, sucks to suck
edgaras
edgarasOP16mo ago
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.
Want results from more Discord servers?
Add your server