Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Serverless deployment (Google Cloud)

default discord avatar
ar0n3 years ago
27

What is the current situation on deploying in a serverless environment? (Support, latency, etc.) Thank you.

  • default discord avatar
    markatomniux3 years ago

    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.

  • default discord avatar
    ar0n3 years ago
    @191776538205618177

    but surely you still have to validate on the backend anyway no? (security reasons) also why Cloud Run and not Cloud Functions?

  • default discord avatar
    bombnp3 years ago

    do you suffer from cold starts? When there's no instance running, it takes a long time to be available (>20 secs)

  • default discord avatar
    ar0n3 years ago
    @275258786388639744

    you can always do the cron trick and do a dead-end request every ~15s

  • default discord avatar
    bombnp3 years ago

    but that would mean the instance would always be running, which incurs cost, yes?

  • default discord avatar
    ar0n3 years ago

    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

  • default discord avatar
    bombnp3 years ago

    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?

  • default discord avatar
    ar0n3 years ago

    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 module

    error

    @275258786388639744
  • default discord avatar
    bombnp3 years ago

    where does this error come from?

  • default discord avatar
    ar0n3 years ago

    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

  • default discord avatar
    bombnp3 years ago

    I have not deployed to cloud functions yet, only cloud run (which i switched to EC2 because i hated cold start)

  • default discord avatar
    ar0n3 years ago

    AWS?



    why not Google's instances?

  • default discord avatar
    bombnp3 years ago

    I've always preferred AWS for cloud, I just tried out Cloud Run because it seemed cheap with how it works

  • default discord avatar
    ar0n3 years ago

    You know that AWS provides Lambda?

  • default discord avatar
    bombnp3 years ago

    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

  • default discord avatar
    ar0n3 years ago

    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



  • default discord avatar
    bombnp3 years ago

    ahh ty

  • default discord avatar
    ar0n3 years ago

    your cold start shouldn't take 20 seconds though, are you building or something everytime?



    or maybe fetching the dependencies rather than from cache

  • default discord avatar
    bombnp3 years ago

    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

  • default discord avatar
    ar0n3 years ago

    If you're fetching the dependencies fresh + building the panel then serving it'll take a long time wasting effort on unneeded things

  • default discord avatar
    bombnp3 years ago

    nope, it's already built inside Dockerfile

  • default discord avatar
    ar0n3 years ago

    strange



    @275258786388639744

    after some struggle I have a Payload server running on Cloud Functions, on warm-start client sees a ~40-50ms delay.

    NODE_ENV=development

    causes massive delays and weirdness,

    NODE_ENV=production

    fixes this, just something you might've missed previously :)

  • discord user avatar
    jarrod_not_jared
    3 years ago

    serverless is... something we have thought a lot about, the 1.6.x release laid the groundwork for some neat things in this space

  • default discord avatar
    bombnp3 years ago

    interesting. Thanks! Will keep that in mind while I investigate.

  • default discord avatar
    markatomniux3 years ago

    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

  • default discord avatar
    bombnp3 years ago

    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?

  • default discord avatar
    markatomniux3 years ago

    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 on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.