Recently moved my app to Next and Vercel. Running into issues with errors for the API's sometimes
Unanswered
Havana posted this in #help-forum
HavanaOP
So I'm having this issue where I moved some of my API's to client side fetching to speed things up a bit from getServerSideProps, but the thing is sometimes the clientside fetches will give me errors. If I refresh the page everything seems to be good to go but on first load I'll get errors sometimes. I'm assuming it's a cold start problem mixing with the client but is there a way to avoid this?
17 Replies
this is the 3rd time to see this type of issue. what’s happening? is this AWS lambda or Vercel gateway hiccup?
in my case the first call takes around 2sec in Lambda and App Router.
HavanaOP
@tafutada777 so this isnt normal? ive been racking my brain trying to break my api's apart and etc... to avoid any issues with possibly heavy api's requests but at this point its unavoidable
yeah, it's typical
i saw some question like urs, which ended up with cold start.
my suggestions are
create a new project from scratch, deploy a simple hello world project to make sure if you see cold start issue.
change region like US major cities if possible.
bump lib versions such as react, nextjs and so on...
It works on my machine.
i saw some question like urs, which ended up with cold start.
my suggestions are
create a new project from scratch, deploy a simple hello world project to make sure if you see cold start issue.
change region like US major cities if possible.
bump lib versions such as react, nextjs and so on...
HavanaOP
i mean i started the project like 1 week ago i would hope all my packages are up to date
as i mensioned, try different regions and App Router.
HavanaOP
regarding regions its where my db is. i think it might be just coldstarts timing out my client side requests. ill try app router though. thank you!
try a plain simple hello world project without db or any other services to identify the culprit. just my two cents. it's up to u
HavanaOP
do you think if i moved away from serverless and set my api up on a server it could help?
u mean self-hosted like AWS, GCP?
in my case, i hosted a Next.js on GCP k8s. so cold issue won't happen.
HavanaOP
im hosted on vercel, i mean moving my api's to like heroku or something
load balanceer switched traffic after an instance spin up.
u mean running a single instance on vm, keep it running without auto scaling?
do u know why cold start happens btw? the meaning of cold start?
in general computer science.
HavanaOP
Yes