What is the current situation on deploying in a serverless environment? (Support, latency, etc.) Thank you.
We use Google Cloud Run to host our Payload app and it's pretty decent. Good value for money and is scaleable. We use Nextjs on the frontend so the backend doesn't need to be particularly fast due to Next revalidating the front end behind the scenes.
but surely you still have to validate on the backend anyway no? (security reasons) also why Cloud Run and not Cloud Functions?
do you suffer from cold starts? When there's no instance running, it takes a long time to be available (>20 secs)
you can always do the cron trick and do a dead-end request every ~15s
but that would mean the instance would always be running, which incurs cost, yes?
no, the costs come from initiation and time. The initiation cost is minimal, the ram and cpu time cost will also be minimal because your request should take 50ms
just make an express route /keepAlive or something that immediately responds a 200 then finishes
ohhhh i've always thought the price is incured for the time "the instance is alive", but it's the time "the instance processes our request" isn't it?
the instance being warmed up isn't price incurred to my knowledge, here's the cost if u did it every 15 seconds, it took 50ms on a 1gb 1.4ghz instance
basically the cost is nothing, I'm assuming 0.1mb per call
which it wont be
although that's fitting into my free tier
-_- no option to estimate without it
okay it's about $0.30 a month
on just cpu and ram
including networking idk $1
Any ideas how to avoid the
Cannot use import statement outside a moduleerror
@275258786388639744where does this error come from?
when deploying to cloud function
I'm getting the error because server.js and Payload uses require() but the config file and others uses import
runs fine locally but google hates me
I have not deployed to cloud functions yet, only cloud run (which i switched to EC2 because i hated cold start)
AWS?
why not Google's instances?
I've always preferred AWS for cloud, I just tried out Cloud Run because it seemed cheap with how it works
You know that AWS provides Lambda?
yea i might try that out too
not sure if payload goes well with serverless functions like Lambda, since it needs db connection every time it fires, but might be worth trying
If the db is on the same premises the latency should be relatively similar to running the db locally (ish)
so a mongodb running on the same region should be fine
ahh ty
your cold start shouldn't take 20 seconds though, are you building or something everytime?
or maybe fetching the dependencies rather than from cache
Yea i thought it was off too. Didn't really investigate yet because I was very busy with getting all the features up.
It was a docker image of the entire payload app, with all the admin panel and stuff
still, it shouldn't be long since everything's built already
note: the db is in mongo atlas free tier
If you're fetching the dependencies fresh + building the panel then serving it'll take a long time wasting effort on unneeded things
nope, it's already built inside Dockerfile
strange
after some struggle I have a Payload server running on Cloud Functions, on warm-start client sees a ~40-50ms delay.
NODE_ENV=developmentcauses massive delays and weirdness,
NODE_ENV=productionfixes this, just something you might've missed previously :)
serverless is... something we have thought a lot about, the 1.6.x release laid the groundwork for some neat things in this space
interesting. Thanks! Will keep that in mind while I investigate.
cloud run with docker was the simplest to setup. We don't need to worry about performance of Payload as long as the frontend (hosted in vercel) is fast. With Payload only being used when revalidating, because this is technically done in the background, we generally don't need to worry about computing power of the MongoDB or Payload instance. Our entire stack costs about $3 a month. Cold starts take about 10 seconds to load the dashboard. That's a hell of a lot faster than Strapi and even faster than Wordpress
when you say 10 seconds cold start, do u mean only to load the dashboard? or does it take 10 seconds to access Payload's REST API as well?
To load the login page. 10 seconds is an extreme case, it's closer to 5 seconds.
Once logged in Payload runs pretty fast. About a second or so for changes to be saved. If you've ever worked on large Wordpress Projects, you'll know that even just 2 seconds to save a page is FAST
Star
Discord
online
Get dedicated engineering support directly from the Payload team.