September 27, 2024
Blue-green deployment: What it is, when to do it, and how to handle database changes
See Liquibase in Action
Accelerate database changes, reduce failures, and enforce governance across your pipelines.
Every release manager aims to achieve seamless continuous delivery with zero downtime, ensuring smooth transitions between software versions. However, deploying code can often introduce risks such as downtime, bugs, or failures if not carefully managed.
This is where blue-green deployments come into play: a proven strategy designed to minimize risks, offering a safer, more controlled transition between environments.
This guide explores blue-green deployments’ advantages, drawbacks, and popular use cases, as well as how to apply them to database pipelines that support application development and data journeys.
What is a blue-green deployment?
Blue-green deployment is an application release strategy that uses two identical production environments — referred to as “blue” (live) and “green” (standby) — to achieve reliable testing, zero-downtime releases, and instant rollbacks. At any given time, only one of these environments is live.
For example, the blue environment handles all live production traffic while the green environment remains idle. When a new application version is ready, it is deployed to the green environment for testing. Once the release passes testing, traffic is seamlessly rerouted from blue to green.
At this point, the green environment becomes the new live production environment, and the blue environment goes idle. This deployment strategy ensures that any issues that arise during or after the transition can be easily mitigated by reverting traffic back to the previous (blue) version.
As a fail-safe mechanism, this allows for uninterrupted service, making blue-green deployments a powerful approach to minimize risks during software updates. Teams choose a blue-green deployment strategy because it helps maintain smooth transitions between application versions, enhancing both system reliability and the user experience during updates.
In the context of CI/CD…
Martin Fowler popularized blue-green deployment in the early 2000s as part of the continuous delivery movement. It emerged as a solution for reducing the risks associated with software updates, providing a safer method to roll out new features without disrupting the end-user experience.
With continuous integration/continuous delivery (CI/CD) taking hold across developer teams, blue-green deployment fits the needs well due to its ability to deliver fast, no-downtime deployments. DevOps philosophy encourages smaller, more frequent deployments, and the blue-green method adds an additional layer of safety. The shift to hybrid and cloud environments also benefits from blue-green deployments, since it helps minimize risk and improve reliability for better developer and user experiences during migrations and deployments.
When to use the blue-green deployment method
Are blue-green deployments always the way to go? Maybe not – but especially in these scenarios, it’s a best practice to ensure integrity, reliability, and security. This method is recommended, if not required, for fast, efficient, and safe:
- Rollbacks
- Feature rollout and A/B testing
- CI/CD pipelines
- Load balancing
- Disaster recovery and failover
Rollbacks
One of the most valuable features of blue-green deployments is the ability to quickly roll back to a stable version of the software if issues arise. If a deployment introduces bugs or performance problems, traffic can easily be rerouted to the previous environment, ensuring minimal disruption.
Feature rollout and A/B testing
For organizations relying on A/B testing or gradual feature rollouts, blue-green deployments provide a controlled environment for experimentation. New features can be deployed to the green environment, allowing teams to monitor performance and user feedback. If the feature underperforms, it’s easy to revert traffic to the blue environment.
CI/CD pipelines
Teams utilizing CI/CD pipelines often deploy code multiple times a day. Blue-green deployments fit seamlessly into this process by allowing rapid and automated deployments with thorough testing before new code is exposed to live traffic. This reduces the risk of production issues and ensures the reliability of frequent updates.
Load balancing
When blue-green deployments are used with environments hosted on separate servers, traffic can be balanced between both environments. Since the blue and green environments are functionally identical, routers can direct traffic as needed, optimizing resource usage and availability.
Disaster recovery and failover
In disaster recovery planning, blue-green deployments play a crucial role by maintaining two identical environments. In the event of a system failure, traffic can be instantly rerouted to the green environment, minimizing downtime and ensuring quick recovery without extensive reconfiguration.
All these scenarios considered, the value of blue-green deployment becomes clear.
Primary benefits of blue-green deployments
For teams who want zero-downtime releases, easy rollbacks, better testing, reduced risk, and simplified database integration, blue-green deployment is the way to go.
Zero downtime
Blue-green deployments enable zero-downtime updates by instantly switching traffic between two identical environments. This is critical for high-traffic applications, where even brief downtime can result in lost revenue or damage to user trust.
Easier, low-risk rollbacks
If a new deployment causes issues, traffic can be easily redirected to the previous version. This provides a quick rollback mechanism, minimizing the impact of deployment failures and ensuring service continuity.
Better, faster, stronger testing
The green environment serves as a staging area where new versions can be thoroughly tested under real-world conditions without affecting live users. This allows teams to perform comprehensive testing—such as performance monitoring and user acceptance testing—ensuring that any issues are caught before the new version goes live.
Reduced risk
With blue-green deployments, the risk associated with new releases is significantly reduced. Rollbacks are fast and seamless, and testing environments are kept separate from production, allowing for careful validation before switching.
Simplified database change management
Blue-green deployments also simplify database changes by separating the environments, allowing for more controlled database migration processes. By decoupling application and database changes, teams can implement database updates safely without affecting the production environment.
However, integrating database change can also be a struggle for teams that lack database deployment automation capabilities.
Challenges of shifting to blue-green deployment
Bringing database changes in line with the blue-green deployment workflow is a challenge for sure, but one that can be easily overcome with a database DevSecOps solution like Liquibase. That’s not the only thing to worry about, though. Your teams will also need to plan for:
- Infrastructure and upgrade costs
- Complexity
- Load balancing
Infrastructure costs
Maintaining two identical environments demands twice the resources, which can be costly, particularly for large-scale applications. Organizations must provision and manage separate environments for blue and green, effectively doubling their infrastructure needs.
Additionally, the setup of two parallel environments requires extra configuration, monitoring, and maintenance, all of which contribute to operational overhead. Since the green environment often remains idle between deployments, the ongoing costs of maintaining unused resources can quickly add up, making this approach expensive for long-term use.
Complexity
Ensuring that both environments remain identical in configuration, dependencies, and data is complex. Any differences between blue and green could result in deployment issues, requiring meticulous management and automation to maintain consistency.
This complexity increases in DataOps or AI/ML environments, where data pipelines, machine learning models, and large datasets are in play. The need to keep massive, sprawling datasets synchronized across both environments can lead to data inconsistencies. Managing real-time data streams, training models, and orchestrating data workflows adds an extra layer of challenge, particularly for AI-driven or big data applications where discrepancies can affect model accuracy or data quality. This requires advanced tooling, automation, and rigorous planning to maintain data integrity and avoid deployment errors.
Load balancing
Configuring load balancers to seamlessly switch traffic between environments without disrupting user sessions or transactions can be challenging. This requires precise configuration and thorough testing to ensure smooth transitions.
Workflow observability is critical when managing load balancing for blue-green deployments, as well as real-time traffic flow and session integrity. Effective observability helps identify bottlenecks, track user behavior during transitions, and ensure that traffic routing between environments is seamless. Tools that monitor and provide visibility into both application and infrastructure performance can help teams detect issues early — whether it’s failed traffic switching, dropped sessions, or misconfigurations — enabling faster resolution and smoother transitions during deployments.
Database schema migrations (change management)
Unlike application code, databases often contain stateful data, making it harder to switch between environments. If schema changes are required, they must be carefully managed to avoid data corruption or loss. Techniques like backward-compatible schema changes or two-phase commits are essential but add complexity.
Below, you’ll learn how to automate database change management to support blue-green deployment without overburdening DBAs or adding a bottleneck to the pipeline. But first, consider a few alternatives to blue-green deployment before fully committing to the practice.
Alternatives to blue-green deployment
While blue-green deployments are effective, other strategies might be better suited depending on the organization’s needs and constraints, such as:
- Canary releases
- Rolling deployments
- Feature flags
- Dark launches
What is a canary release?
A canary release involves rolling out a new version of an application to a small, select group of users before making it available to everyone.
This gradual release allows teams to monitor performance, collect feedback, and address issues without affecting the entire user base. Canary releases provide a more controlled and granular approach compared to blue-green deployments, reducing risk while gaining real-world insights before full deployment.
What is a rolling deployment?
In rolling deployments, updates are applied incrementally, replacing instances of the old version with the new one, one at a time.
This ensures that only part of the system is updated at any given time, mitigating the risk of total failure. Rolling deployments are particularly useful for large, distributed systems where a full environment switch would be too disruptive. This method requires careful monitoring to ensure consistency across all updated instances.
What is a feature flag?
Feature flags (also called feature toggles) allow developers to turn specific features on or off in an application without deploying new code.
This decouples feature releases from the deployment process, enabling teams to deploy code to production with features disabled and gradually activate them for different groups. Feature flags allow safe experimentation and gradual rollouts, but they add complexity and require careful management to avoid technical debt.
What is a dark launch?
A dark launch is when new features are deployed to production without making them visible to users immediately. This lets the development team test the features in a live environment, ensuring they perform well under production conditions before being exposed to users.
Dark launches often work alongside feature flags or canary releases to provide extra control. This approach minimizes risk by verifying feature readiness in production before the full rollout, but requires robust testing and monitoring for success.
Tackling the database challenge in blue-green deployment
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.
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:
- 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. - 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.
Liquibase integrates database changes with blue-green deployment workflows
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.
- DB Change 1: Use Liquibase to deploy a script to add the column POSTAL_CODE
- App Change 1: Update Green with an application version that reads ZIP_CODE and writes to both ZIP_CODE and POSTAL_CODE.
- Router Change 1: Green goes online.
- DB Change 2: Use Liquibase to deploy a script to transfer all values from ZIP_CODE to POSTAL_CODE.
- App Change 2: Update Blue with an application version that reads and writes only the new column POSTAL_CODE.
- Router Change 2: Blue goes online. Now only the new column POSTAL_CODE is used.
- 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.
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.
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.
Check out an on-demand demo of Liquibase to understand how it automates, integrates, and streamlines your pipeline.