CLOUD CONCEPT

Blue-Green Deployment

Blue-green deployment releases a new application version into a separate environment and then redirects production traffic from the current environment to the new one.

Cloud Concepts Hub →

What is Blue-Green Deployment

Two independently deployable environments allow engineers to validate a replacement release while the existing release continues serving users. Switching traffic rather than modifying the live environment reduces deployment disruption and can enable fast rollback, provided data and dependencies remain compatible.

Blue-green deployment separates preparing a release from exposing it to production traffic. The blue environment serves the current version while the green environment receives the replacement version. Engineers provision green, deploy the application and its configuration, validate readiness, and then redirect production traffic. The colors are labels rather than permanent roles: after a successful release, green becomes the active environment, and the previous environment can be retained temporarily or removed.

In the cloud, the environments might be separate groups of virtual machines, container task sets, or published serverless function versions. A load balancer, gateway, or function alias provides the traffic-switching mechanism. Infrastructure as code and versioned deployment artifacts help make the environments reproducible. This supports immutable infrastructure because engineers replace application instances rather than patching the running production fleet. However, blue-green deployment is a release strategy, while immutability is an infrastructure-management principle; neither automatically guarantees the other.

A practical web application release might create a replacement instance group from a new machine image, register it with a separate load-balancer target group, and run tests through a nonproduction listener. After checking authentication, dependency access, latency, and application behavior, the pipeline changes production routing. It drains existing connections where supported and retains the old group during an observation period. Long-lived connections, sticky sessions, caches, and DNS caching can delay complete transition, so a traffic switch is not necessarily instantaneous and does not guarantee zero downtime.

Database compatibility is often the most important rollback constraint. Both versions commonly share a production database, although separate databases are possible with a carefully designed synchronization strategy. Use backward-compatible schema changes, such as adding a nullable column before removing an old one in a later release. Returning traffic to blue does not undo writes, reverse external transactions, or restore deleted data. Session state should remain accessible to both versions, and background workers or scheduled jobs need coordination to avoid duplicate processing and incompatible writes.

CI/CD pipelines should automate environment creation, deployment, readiness checks, test execution, traffic switching, observation, and cleanup. Define rollback conditions using metrics such as error rate, latency, failed business transactions, or inference failures. A passing infrastructure health check is not proof of application correctness. Keep the old environment healthy and sufficiently provisioned during the rollback window, and confirm that rollback is actually possible after any data or configuration changes.

For AI and machine learning workloads, green can host a new model, inference container, or replacement AI platform integration. Validate input schemas, preprocessing, feature availability, representative datasets, output quality, inference latency, and cost per request before switching. Business continuity may require a fallback model or a manual process if the new system fails. Technical health alone cannot establish model quality; some business outcomes arrive too late for immediate automated rollback. Account for sensitive production data used in validation and for the temporary cost of duplicate inference capacity.

The main trade-offs are additional capacity, orchestration complexity, environmental parity, and state-management effort. Quotas must support overlapping environments, and green must handle expected production demand before cutover. Blue-green describes the coexistence of current and replacement environments; canary describes exposing a limited portion of traffic before broader rollout. They can be combined, although a classic blue-green cutover moves traffic in one step. Neither strategy replaces backups, multi-zone resilience, disaster recovery, or a tested operational recovery plan.

Key aspects of Blue-Green Deployment

Blue-green deployment combines isolated release preparation, controlled routing, production validation, and state-aware rollback at the cost of temporary duplicate capacity.

Separate current and replacement environments

Keep the active release available while preparing the replacement independently. Match relevant configuration, networking, permissions, and dependencies so validation reflects production behavior.

Controlled traffic cutover

Promote a release by changing routing rather than upgrading the live application in place. Plan connection draining, session handling, and propagation delays around the chosen routing mechanism.

Reproducible, immutable releases

Build environments from versioned artifacts and infrastructure definitions. Replacing application instances reduces configuration drift, but mutable shared dependencies still require explicit management.

Validated and observable promotion

Run readiness checks and representative application tests before cutover, then monitor technical and business indicators afterward. For AI workloads, include model quality, data compatibility, inference performance, and operational fallback criteria.

Rollback with state compatibility

Retain the previous environment for a defined rollback window and automate traffic restoration when appropriate. Ensure old code can still interpret current data because reversing routing does not reverse database changes or external side effects.

Temporary capacity and cost overhead

Budget for overlapping environments, including compute, model hosting, and supporting resources. Check service quotas and replacement capacity before deployment, then remove unused resources after the observation period.

Cloud services for Blue-Green Deployment

A deployment workflow prepares a replacement application or model environment, validates it, and changes the production routing target. CodeDeploy can coordinate supported deployments across EC2, ECS, and Lambda, while Elastic Load Balancing routes application traffic between fleets. Lambda aliases provide version-level routing for serverless releases. SageMaker AI deployment guardrails provide a comparable managed workflow for supported inference endpoint updates. CloudWatch supplies metrics and alarms for observation and rollback decisions. These services implement different parts of the pattern; they do not remove the need to design compatible database changes, representative tests, sufficient temporary capacity, and a clear rollback window.

AWS CodeDeploy image AWS CodeDeploy

Automates blue-green deployments for supported Amazon EC2, Amazon ECS, and AWS Lambda deployment scenarios. Traffic-shifting options differ by compute platform; deployment hooks and configured CloudWatch alarms can support validation and automatic rollback.

Open AWS CodeDeploy →
AWS Lambda image AWS Lambda

Published function versions provide immutable deployment artifacts, and an alias can direct invocations to the selected version. CodeDeploy can manage version traffic shifts and rollback; callers must use the deployment alias rather than bypassing it with direct version references.

Open AWS Lambda →
Amazon SageMaker image Amazon SageMaker

Deployment guardrails support blue-green updates for supported real-time inference endpoints using a replacement fleet. Traffic-shifting policies, a baking period, and configured CloudWatch alarms help validate a new deployment and trigger rollback when alarms indicate problems.

Open Amazon SageMaker →
Amazon CloudWatch image Amazon CloudWatch

Collects deployment health metrics, logs, and application signals used to evaluate the replacement environment. Alarms can participate in supported automated rollback workflows, but useful thresholds and business-level metrics must be explicitly configured.

Open Amazon CloudWatch →