November 21, 2024

Rethinking Blue-Green Deployments for Infrastructure

Table of Contents

Modern blue-green deployments transcend the traditional “mirror image” model, enabling organizations to safely test and implement infrastructure changes without risking production stability. By leveraging tools like Harness IaCM, teams can experiment with varying configurations, validate assumptions using real production traffic, and make informed, cost-effective decisions to evolve their infrastructure.

Ever tried to improve your application's infrastructure but felt stuck with your current setup? We were curious about how organizations handle infrastructure updates without risking their production environment, so we dug into a fascinating approach to blue-green deployments that challenges conventional wisdom.

The Evolution of Blue-Green Thinking

Traditional blue-green deployment documentation often presents an idealized scenario: two identical environments, perfectly mirrored, switching traffic back and forth. But in the real world, infrastructure needs to evolve. Perhaps your current environment isn't optimal, or you've discovered a more cost-effective configuration. This is where modern blue-green deployments truly shine.

Breaking Free from Mirror Images

Imagine this scenario: You're running a successful e-commerce platform on a set of `t3.large` instances with a specific auto-scaling configuration. Your monitoring suggests that switching to `t3.xlarge` instances with a different scaling pattern might improve performance during peak hours. But how do you test this theory without risking your current stable environment?

This is where the true power of blue-green deployments comes into play. Instead of creating an identical environment, you can:

  1. Keep your current "blue" environment running as-is
  2. Spin up a new "green" environment with your desired infrastructure changes
  3. Gradually route traffic to test your hypothesis
  4. Make a data-driven decision about which configuration serves your needs better

Here's how this might look in practice:

# Original Blue Environment (Current State)
resource "aws_launch_template" "blue" {
	name_prefix   = "blue-template"
    instance_type = "t3.large"
    
    user_data = base64encode(<<-EOF              
    	#!/bin/bash              
        echo "Original Configuration"              
        EOF  
    )
}‍

# New Green Environment (Experimental State)
resource "aws_launch_template" "green" {
	name_prefix = "green-template"
    instance_type = "t3.xlarge"    
    
    user_data = base64encode(<<-EOF              
   	 	#!/bin/bash
        echo "New Configuration with Enhanced Resources"
        EOF  
  	)
}

The Modern Approach to Infrastructure Evolution

Rather than maintaining two identical environments, this approach lets you:

  1. Experiment Safely: Test new infrastructure configurations without compromising your existing setup
  2. Validate Assumptions: Use real production traffic to verify if your new infrastructure performs better
  3. Roll Back Efficiently: If the new configuration doesn't meet expectations, return traffic to the original environment
  4. Optimize Costs: Only pay for the duplicate environment during the testing phase

Real-World Example: A Tale of Two States

Let's say you're using Harness to manage this process. Here's how a practical implementation might unfold:

  1. Initial State: Your application runs on a blue environment with standard configuration
  2. Hypothesis: Your team believes a different infrastructure state could improve performance
  3. Implementation: 
  • Deploy a green environment with the new configuration
  • Use Harness's traffic management features to gradually route requests
  • Monitor performance metrics in real-time
  1. Decision Point:
  •   If the new configuration proves better, maintain the green environment and decommission blue
  •   If not, route traffic back to blue and tear down green
# Example Kubernetes service for gradual traffic shifting
apiVersion: v1
kind: Service
metadata:  
  name: production  
  annotations:    
    harness.io/traffic-split: |      
	  {        
		"blue": 75,        
		"green": 25      
	  }
	spec:  
	  selector:    
		app: myapp  
	  ports:  
	  - protocol: TCP    
	  port: 80

Infrastructure as Code and Ephemeral Environments

The beauty of this approach lies in its flexibility. Using infrastructure as code tools like OpenTofu or platforms like Harness IaCM, you can:

  • Version control your infrastructure states
  • Automate the creation and destruction of environments
  • Compare performance metrics between different configurations
  • Make data-driven decisions about infrastructure changes

Monitoring and Decision Making

Success depends on careful monitoring. Key metrics to track when comparing environments:

  • Response times
  • Error rates
  • Resource utilization
  • Cost per transaction
  • User experience metrics

Best Practices for Different-State Deployments

Document Everything

  • Keep detailed records of configuration differences
  • Track performance metrics for both states
  • Document decision-making criteria

Plan for Data

  • Consider database schema compatibility
  • Plan for data synchronization between environments
  • Account for stateful services

Cost Management

Conclusion

Modern blue-green deployments aren’t just about maintaining identical environments – they’re about creating a safe space to evolve your infrastructure. By leveraging platforms like Harness Infrastructure as Code Management, you can seamlessly experiment with different infrastructure states while maintaining the safety net of your stable environment.

This method lets you move beyond the traditional “mirror image” approach to blue-green deployments, empowering true infrastructure evolution with minimal risk. Whether you’re optimizing for cost, performance, or both, Harness provides the tools you need to experiment confidently, track metrics in real-time, and make data-driven decisions about your infrastructure’s future.

Infrastructure as Code Management
Continuous Delivery & GitOps