We just added bluegreen deployment strategy for appsV2 and I’m here to tell you all about it.
How does it work (highlevel)
Assuming your app has 5 machines & you initiate a deployment,
- We boot up 5 new (green) machines running your new release.
- Once the green machines have started, we run healthchecks to ensure they’re ready for production traffic.
- If all healthchecks pass, we then mark the green machines as ready for traffic and tear down the previous(blue) machines
- Profit?
How do I use it
It’s easy, but first, you need to update your flyctl to the latest version.
After, you can either set bluegreen
as the deployment strategy in your fly.toml
[deploy]
strategy = "bluegreen"
Or, you can just pass it an argument to your fly deploy command.
fly deploy --strategy=bluegreen
What’s actually happening? (for the curious)
We made 0 changes to our proxy for this feature. Our proxy has no idea which machine is green or blue. Rather, we’re using 2 new machine apis we recently added to hide/unhide machines from the proxy. Flyctl, our chief orchestrator, only checks health and toggles switches on or off.
You’re probably wondering how we rollback
safely, I’ve got details for you too. We keep your blue deployment alive till we have 100% confidence in the green deployment. If for any reason we are unable to get the green machines into a healthy state, we undo everything we’ve done and bail out. This means your old deployment stays intact & untouched. This is also means, there’s a brief period where your 2 deployments can serve traffic, but it’s very brief.
And so, till the green machines are healthy, they’ll remain hidden from the proxy. Once they’re healthy, we put them in the spotlight. If something goes wrong, we cleanup and bail out. Nice & easy.
Notes
- It’s quite fast, so if you have a large deployment, you should absolutely try it out!
- All the orchestration is conducted entirely by flyctl. You know it, you love it!
- It’s an all or none strategy. If any of the steps fail, flyctl will rollback safely to your previous release.
- You may see extra health-checks on your dashboard during a deployment. Once the deployment completes, we’ll clean them up. There’s ongoing work to remove this behaviour.
So, update your flyctl, try it out, and let us know what you think. We are always listening!