Zero Downtime Deployments Using Azure Deployment Slots
No developer today wants to test his code on live production environments. Especially if they are customer facing. This is pretty much like an open-heart surgery.
Thus, we need multiple deployment environments, e.g. Dev, Staging, Q&A or however you want to call them.
Microsoft Azure offers the Option of “Deployment Slots“. Depending on your App Service Plan you can have up to 5 (on “Standard”) or even up to 20 (on “Premium”) of them. Tiers “Standard“, “Shared” and “Free” do not offer Deployment Slots at all. Each Slot is basically a full WebApp. Actually, your initially deployed WebApp is sitting in the “production” slot (which is one of your total available slots).
To add a slot, simply navigate to your WebApp choose Deployment Slot and click Add Slot.
After giving it a meaningful name, you can either hit OK, and create an empty slot, or if you have an existing configuration, you can choose it as a source (like the default WebApp production Slot).
After its creation, you will find an overview of all Deployment Slots created for this WebApp within its Deployment Slot section.
Hint: If you check the Deployment Slot section, your previously created Slot is called <webapp>-<slot name> (while the slot name is whatever you chose). If you look at your All Resources menu, your slot is just called <slot name>.
If you select your slot in either way, you will see a page which looks almost identical to the corresponding production WebApp.
If you check the URL or (in my case) the Git Clone URL, you will notice that the only difference is the added “-dev” (which is my slot name) behind the actual app name.
I have already modified my highly complex WebApp content, so that you can spot the difference between production and dev.
The really cool feature now is, swapping the the content between both slots. In that way, you can assure a zero-downtime-deployment.
Go to Webapp –> Overview –> Swap
No choose two slots, you want to swap content between and hit OK.
Following, you see that the content has been swapped.
Note: This has been a extremly simple example, as it was only supposed to show the rough concept. In reallity, there are a lot of settings bound to each Slot, and not all of them swap. So chances are, that your app breaks after swapping, if you don’t keep an eye on them.
There are a lot of additional features to it, like multi-phase-swaps or auto-swap.