March 22, 2021

Easy Blue-Green Deployments with Liquibase

Every release manager's dream is to easily achieve continuous delivery with zero downtime. Blue-green deployments are a popular technique teams use to make it a reality.

What is a blue-green deployment?

A blue-green deployment uses two production environments (known as Blue and Green) to provide reliable testing, continuous no-outage releases, and instant rollbacks.

At any given time, only one of the production environments is live. The Blue environment, for example, receives all user traffic while the clone (Green) remains idle. When a new version of the application is ready for release, it is deployed to the Green environment for testing. Once the release passes testing, the application traffic is routed from Blue to Green. The Green environment becomes the new production environment, and the Blue goes idle.

Blue-green deployment example

Databases add complexity

In its purest form, blue-green deployments expect every application resource to be duplicated. However, it doesn’t make sense to run two copies of the database. Users would be adding and updating records on both the blue and green databases requiring a complex data synchronization process. For that reason, blue-green deployments typically share a database.

Sharing a database with a blue-green deployment model

The shared database presents a challenge: two versions of the application code must be running at the same time, communicating with the same database. 

There are two requirements for implementing blue-green deployments using a shared database:

  1. Make all database changes backward compatible. 
    Any changes made to the database schema must not break the existing application. There are many techniques for making database changes backward compatible.
  2. Decouple database changes from application changes.
    Since all database changes are backward compatible, they do not have to be deployed at the same time as the application changes. The database changes can be made ahead of time so that the database can serve either Blue or Green environments.

Solving the database issue with Liquibase

Deploying changes to the shared database requires a coordinated and gradual approach. The database state is migrated with many small steps to the new state without any downtime. This process requires a level of precision and control that is difficult to achieve by manually deploying scripts. 

By using Liquibase, you can precisely track and control the database changes deployed to each environment. If we want to change the schema, we create a new SQL script and add it to the Liquibase changelog. Then the CI/CD automation process can run Liquibase to deploy the changes without manual intervention.

An example

Let’s look at a specific example. We want to rename a column from ZIP_CODE to POSTAL_CODE to accommodate our international customers.  Assume that “Blue” is currently online.

  1. DB Change 1: Use Liquibase to deploy a script to add the column POSTAL_CODE
  2. App Change 1: Update Green with an application version that reads ZIP_CODE and writes to both ZIP_CODE and POSTAL_CODE.
  3. Router Change 1: Green goes online. 
  4. DB Change 2:  Use Liquibase to deploy a script to transfer all values from ZIP_CODE to POSTAL_CODE.
  5. App Change 2: Update Blue with an application version that reads and writes only the new column POSTAL_CODE.
  6. Router Change 2: Blue goes online. Now only the new column POSTAL_CODE is used.
  7. DB Change 3: Use Liquibase to deploy a script to remove the old column ZIP_CODE from the table.

As you can see, implementing a blue-green release process requires precise control and coordination of database and application releases. It also requires the right alignment of architecture, infrastructure, and tooling.  Liquibase provides the precision and control to automate database changes throughout the blue-green release cycle.

Best way to get started with blue-green deployments

Process changes are often disruptive. Since the database layer can be the most challenging part of blue-green deployments, consider making process changes in smaller steps. You can start with the goal of minimizing downtime. For example, create a pre-migration changelog. This changelog contains database migration scripts that can be run online before the maintenance window. The purpose is to reduce the amount of offline time. New objects like tables, indexes, and views are good candidates to be created early. Next, add a post-migration changelog. Over time, all changes will be performed in the pre- and post-migration phases eliminating the need for a downtime window.

Summing it up

Implementing a blue-green release approach has many advantages including:

  • No downtime
  • Reduced risk
  • Instant rollback

However, blue-green releases require a coordinated, incremental approach to database change which can only be achieved through a managed and automated database release process and that's where Liquibase can help in multiple ways. Liquibase is designed to help your team automate database schema changes and also enable and support your team to update processes so that you can code at full speed and continuously deliver with full confidence. Contact us and let us know how we can help your team get started.

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Block quote

Ordered list

  1. Item 1
  2. Item 2
  3. Item 3

Unordered list

  • Item A
  • Item B
  • Item C

Text link

Bold text

Emphasis

Superscript

Subscript

Martha Bohls
Martha Bohls
Share on: