The Imperative for Zero-Downtime Deployments
In high-concurrency production architectures, even a 30-second restart window or dropped TCP socket can result in thousands of severed user connections and transaction failures. Traditional rolling updates, while simple, often introduce subtle transient errors during API schema migrations or dependency mismatch periods.
To eliminate this volatility, we architected an automated **Blue/Green deployment topology** on AWS Elastic Container Service (Amazon ECS) managed entirely via declarative Terraform modules.
Architectural Design: The Two-Target-Group Model
The core of our immutable deployment strategy relies on AWS Application Load Balancer (ALB) paired with AWS CodeDeploy for container traffic shifting:
[ Global Clients ]
│ (HTTPS / TLS 1.3)
▼
[ Application Load Balancer (Port 443) ]
│
┌────┴─────────────────────────┐
│ Production Listener │ Test / Verification Listener
▼ (Port 443) ▼ (Port 8443)
[ Blue Target Group (Active) ] [ Green Target Group (Candidate) ]
│ (Tasks v1.4.0) │ (Tasks v1.4.1)
▼ ▼
[ ECS Fargate Tasks ] [ ECS Fargate Tasks ]Terraform Implementation Snippet
Below is the core Terraform configuration establishing the ECS service with the `CODE_DEPLOY` deployment controller:
resource "aws_ecs_service" "api_service" {
name = "production-core-api"
cluster = aws_ecs_cluster.main.id
task_definition = aws_ecs_task_definition.app.arn
desired_count = 6
launch_type = "FARGATE"
deployment_controller {
type = "CODE_DEPLOY"
}
network_configuration {
subnets = module.vpc.private_subnets
security_groups = [aws_security_group.ecs_tasks.id]
assign_public_ip = false
}
load_balancer {
target_group_arn = aws_lb_target_group.blue.arn
container_name = "core-api"
container_port = 8080
}
lifecycle {
ignore_changes = [
task_definition,
load_balancer
]
}
}