Blue/Green Deployments in Service Fabric

The technique of Blue/Green deployments has been around for a long time. The goal is to reduce downtime by provisioning two identical production environments and switch between them during releases. It also enables easy rollbacks in case of a bad upgrade.

In the world of Service Fabric, all upgrades are always Rolling Upgrades, which enables Zero Downtime but, how do we create our secondary identical Green environment if the app is upgraded every time. This is where multiple versions of application types can be used. As described here, we will use multiple instances of a service based on multiple versions of an application type to perform our testing and then upgrade the primary version using rolling upgrades. Let's see how we can do this using PowerShell:

(The script and sample code used in this article is available on GitHub)

First, create application package using Visual Studio



Next, deploy Version 1.0 using PowerShell (this is our Blue deployment)

version1-script version1-sfexplorer

Now lets test the Version 1.0 API.


We can see that the API is returning 2 cities. Now lets make the code changes for version 2.0 to return more cities and update the version in the manifest files.


Then, create the application package again using Visual Studio and deploy Version 2.0 (this is our Green deployment)

version2-script version2-sfexplorer

We now have two instances of our application running with two different versions of our application type. We can now Test Version 2.0 of our app "fabric:/MyAppTest".


Once all our tests are passing for Version 2.0, we can upgrade our primary app "fabric:/MyApp" with the new version using Rolling Updates

(Note: I using just 10 seconds for health stabilization to fasten my upgrades process, in the real world you may want to increase this)

upgrade-script upgrade-sfexplorer

Once the rolling update is successful, we can check that both of our instances are now Version 2.0


Note that we still have Version 1.0 of our application type so in case if want to rollback we can do this easily using the same upgrade command.

I will cover how we can integrate this in our CI/CD pipelines using the built-in Service Fabric tasks in VSTS in my next post.