Production Updates
Unanswered
West African Lion posted this in #help-forum
West African LionOP
Hey, I am soon release a little website of mine which is critical that the downtime is not too high.
The problem is, building the website takes about ~1min. Any idea how I can speed it up? I already tried making the bundle size smaller, and use that optimizeLibrary param in nextjs to strip big libraries, but that barely helped.
Any other tips to speed it up?
The problem is, building the website takes about ~1min. Any idea how I can speed it up? I already tried making the bundle size smaller, and use that optimizeLibrary param in nextjs to strip big libraries, but that barely helped.
Any other tips to speed it up?
18 Replies
@West African Lion Hey, I am soon release a little website of mine which is critical that the downtime is not too high.
The problem is, building the website takes about ~1min. Any idea how I can speed it up? I already tried making the bundle size smaller, and use that optimizeLibrary param in nextjs to strip big libraries, but that barely helped.
Any other tips to speed it up?
when its just about downtime, then you can keep the current deployment active, while the next one is building and after the building part is done, it automatically will be promoted to the current deployment
@West African Lion But I need to restart, no?
after you set it up properly, you dont need to. I guess you are self hosting, right? Write a deployment script, that does all of this for you and you have 0.0 downtime caused through builds. If you are on plattforms like vercel or using self hosting "helpers" like coolify, it will be handled automaticallyfor you
@B33fb0n3 after you set it up properly, you dont need to. I guess you are self hosting, right? Write a deployment script, that does all of this for you and you have 0.0 downtime caused through builds. If you are on plattforms like vercel or using self hosting "helpers" like coolify, it will be handled automaticallyfor you
West African LionOP
Yes I am selfhosting using pterodactyl
It‘s running in a turborepo and building everything on restart
great. Instead of restarting the whole server, just restart the specific container (that then builds and deploys)
@B33fb0n3 great. Instead of restarting the whole server, just restart the specific container (that then builds and deploys)
West African LionOP
Yes but that causes the server to go down
@West African Lion Yes but that causes the server to go down
normally you have one server running and it continues to stay online and then just your docker containers on that machine restarts, not that the whole server restarts. Thats also a reason why we have docker
@B33fb0n3 normally you have one server running and it continues to stay online and then just your docker containers on that machine restarts, not that the whole server restarts. Thats also a reason why we have docker
West African LionOP
Mo I don‘t restart the entire server
My bad
I mean the container
When I want to update the website, I need to restart the container
I cannot build it before restarting
Its just
Click start → build → container started → stop → start → build → container started
Click start → build → container started → stop → start → build → container started
And that building takes like a min
Which cuases a minute of downtime
ah now it makes more sense yea. You can create a building container for your app or a deployment script, that builds the whole thing and after the build it finished, it takes down the old container and instantly starts it, so there is no downtime.
As we working with containers, you can also have multiple containers open and restart one after another, so there is 100% no downtime
As we working with containers, you can also have multiple containers open and restart one after another, so there is 100% no downtime
Sun bear
Depends on how you host the application. If you are using Docker maybe you can take inspiration from a setup I have in production.
I host the Next.js container on a small VPS which is not really powerful and building the image takes ~8 minutes on it. Because of this I created a script which offloads the building of the image to my local machine where it takes ~1.5 minutes. After the image is built I compress it to a
Once the image is uploaded to the VPS I swap the production image using
This ensures that I have about <1 second downtime, while not having to do some complicated blue-green setup which slows down the production server.
I host the Next.js container on a small VPS which is not really powerful and building the image takes ~8 minutes on it. Because of this I created a script which offloads the building of the image to my local machine where it takes ~1.5 minutes. After the image is built I compress it to a
image.tar file, and send it to VPS using ssh and scp.Once the image is uploaded to the VPS I swap the production image using
docker load and docker compose to restart the container with the new image.This ensures that I have about <1 second downtime, while not having to do some complicated blue-green setup which slows down the production server.