Have you ever made changes to your website and were slightly terrified that something was going to break? I have, and it's not fun. This is why I like
Blue-Green Deployments. You can use it and update your apps on a VPS with zero downtime. Sounds cool, right? Just let me explain in the simplest way.
What Blue-Green Deployment Means
Think of it like you have two rooms. One room is
“Blue,” and the other is “
Green.” Everyone is in the Blue room while you're fixing or updating the Green room. When it’s time, you move everyone to the Green room. No one sees the mess while you work.
Why Do I Recommend it?
I'll be very upfront: I tried
blue-green deployments because I hate when my site goes down.
You can certainly expect:
- Zero downtime
- Easy rollback (you can do it at anytime)
- Peace of mind
- Orderly updates without any mess
Once you try it, you'll never go back to the old way of deployment.
Create Two Versions of Your Application
On your
VPS, you're going to keep two versions of your application.
Example
- /var/www/app_blue
- /var/www/app_green
Utilize Nginx or Apache to Redirect Traffic
The
web server is the one that determines which of the two versions will be displayed to users. I use
Nginx, but
Apache will work too.
You are Only Changing One Item
You only need to do the following:
- Change root folder in the configuration
- Reload the web-server
This switch is seamless. Users will not see any downtime. And it always feels safe.
Use Docker for a Cleaner Transition
I will use a
Docker container that is named
"app_blue” and
“app_green" on occasion.
Why Docker is easier:
- More separation
- Easy to update
- Easy to revert
Just update the new container, test it, and switch to that version when you are ready.
Always Test Before Making The Switch
I always test before I make the switch to the new version.
I test:
- Error logs
- Main page
- API
- Basic functionality
Testing helps to avoid unforseen issues. We all know that feeling when we push a new version and it is junk, right?
Switch and You're Done
Once you know the new version is working, you just switch to it in a few seconds.
If something breaks, then you just switch back again. It literally is just like hitting the
"Undo" button.
Conclusion
Blue-green deployments allow you to deploy updates in a safe and smooth manner. You keep one version running on the
live VPS and prepare your next version on a separate VPS. As soon as you confirm everything is working properly, you just switch to your new version without any downtime.
Try it once and you will feel confident every time you need to update your
VPS. It honestly feels great, when everything works, without a one second outage.