Skip to content

Zero Downtime Deployment

xtreme-steve-elliott edited this page Jul 19, 2018 · 1 revision

Previous: Smoke Tests

When backend apps need to be upgraded, it would be disadvantageous for the server to be unavailable during this time. Users would be unable to access the app, which leads to less traffic and frustration for the website and the company. However there are ways around this, with the idea of zero downtime deployment.

In this section, we'll demonstrate a simple zero downtime deployment solution on our Concourse pipeline using the cf-resource.

First, we'll show what happens without the solution. We'll ping our server every 5 seconds and do a cf push in the mean time.

Install the watch program (alternatives can be found on Windows, either through Cygwin, or just a Powershell loop):

brew install watch

Now run the following:

watch -n 5 "curl -s https://notes.dev.cfdev.sh/api/notes"

This will print out something like:

Every 5.0s: curl -s https://notes.dev.cfdev.sh/api/notes

[]

Now in a separate terminal window, run:

fly -t ci trigger-job --job=pipeline/build-deploy

This will trigger the build-deploy job which will deploy the app again. While this is occurring, monitor the output of watch. You'll see a 404 indicating the app is not accessible during this time:

Every 5.0s: curl -s https://notes.dev.cfdev.sh/api/notes

404 Not Found: Requested route ('notes.dev.cfdev.sh') does not exist.

The cf resource has an optional current_app_name parameter which, if set, will do a zero-downtime deployment. In pipeline.yml on the bottom of the build-deploy job, as part of the params sectioon, add:

current_app_name: notes

Once the previous job is done, update the pipeline using fly and trigger the job again. As you monitor the output of watch this time, the app will continue to return the status code 200 with the empty array.

Git Tag: zero-downtime-deployment

Resources:
Blue-Green Deployment