Next.js Discord

Discord Forum

Zero downtime updating in production?

Answered
Thrianta posted this in #help-forum
Open in Discord
ThriantaOP
I have a quick question about self-hosting a Next.js server on my own virtual server. I currently run a few Next.js websites that receive quite a fair amount of traffic. Every few days, I'll perform a pull on the production server and use next build. Sometimes while the application is building, I will receive traffic to my website will almost certainly results in both a client and server error. What is the best practice for updating the application? Should I always shutdown before building, then start it back up? There must be a better way to avoid downtime, like a zero downtime deployment...
Answered by DirtyCajunRice | AppDir
automation, containerization, and orchestration are the bread and butter of the industry now.

no problem, good luck!
View full answer

41 Replies

yeah there are 100 better ways
none of which involve using a full vm for a website
docker containers
serverless
loadbalancing
A/B and canary routing
ThriantaOP
I currently use load balancing via Nginx but how can I configure everything to work seamlessly together like that?
I would have to dynamically tell Nginx to switch which upstream server to use on the fly
nah not at all
you configure nginx to healtcheck the endpoint
and you set 2 ports for each site
each time you update, you spin it up on the opposing port
ThriantaOP
So for example, use 3000 when I start the site, and next time I update use 3001, then alternate back and forth on each update?
exactly
you need 2 folders for it
unless your build is running separately than your source
then you just need 2 dist folders
ThriantaOP
Interesting
that way A is not overwriting B live
all of this is literally the purpose of docker containers… but if you prefer to old school it… “this is the way” lol
ThriantaOP
Never got into Docker at all, CLI is way overcomplicated for me
If there was some ncurses tool for managing containers, I might consider it
i know lots for k8s. None for just flat docker
ThriantaOP
But all of that definitely seems like a great idea, will just need to find a good way to implement it well
As well as automate
there are lots of local web guis tho
back in the day there was “portainer” for docker
just expose it and restrict to a password and you have ui management of your docker env
ThriantaOP
Basically like a phpMyAdmin but for Docker?
yes exactly
ThriantaOP
Man I haven't heard about phpMyAdmin in so long...
haha. because people dont hate themselves
ThriantaOP
Lmao
and use cloud
ThriantaOP
I just need to force myself to learn Docker/other deployment methods
Have always self deployed
100%. Its a gift that will keep on giving
ThriantaOP
Thank you, you've definitely helped out
automation, containerization, and orchestration are the bread and butter of the industry now.

no problem, good luck!
Answer
ThriantaOP
But also a shit-show when it goes wrong. I've heard the stories of GitLab database replication orchestration going sideways
Luckily I don't need to scale nationwide 😂