Codeplant IT Solution
Codeplant IT Solution
Custom Software & AI Engineering

Zero-Downtime Blue/Green Deployments with Docker, GitHub Actions and AWS ECS

Category: Cloud & DevOps | Reading Time: 2 min read

A step-by-step production blueprint for implementing zero-downtime Blue/Green deployments. Master AWS ECS Fargate, Application Load Balancers, automated database schema migrations, and instant rollbacks with GitHub Actions.

In modern 24/7 global software operations, scheduled maintenance windows and deployment downtime are relics of the past. Users expect platforms to remain fully operational while new features and bug fixes ship continuously to production.

However, naive deployment approaches—such as stopping a container and launching a replacement on the same port—drop active database transactions, terminate in-flight HTTP requests with 502 Bad Gateway errors, and create chaos when database schema migrations break backwards compatibility.

Achieving true zero-downtime deployments requires Blue/Green or Canary deployment topologies where an entirely new parallel environment is spun up, validated by health checks, and shifted to live traffic via load balancers without dropping a single packet.

1. Core Industry Challenges & Architectural Dilemmas

  • In-Flight Connection Dropping: Terminating older application instances before active client HTTP requests finish processing.
  • Database Schema Migration Deadlocks: Running an ALTER TABLE statement that locks critical production tables while older app versions still query legacy columns.
  • Failed Health Check Rollback Delays: Routing live customer traffic to a newly deployed container before verifying that external cache and database connections are operational.
  • Secret & Environment Drift: Discrepancies between staging and production environment variables causing runtime crashes immediately after deployment.

2. Technical Comparison & Architectural Trade-offs

Deployment StrategyDowntime RiskRollback SpeedResource CostRecommended For
Recreate (In-Place)High (30s - 2min downtime)Slow (Requires rebuild)Lowest (Single set of containers)Development / Internal Staging
Rolling UpdateZero (Gradual container replacement)Medium (Gradual revert)Low (+25% surge capacity)Standard API Microservices
Blue / GreenZero (Instant traffic switch)Instant (< 2 seconds switch)High (2x container fleet during deploy)Mission-Critical Enterprise Systems
Canary DeploymentZero (Traffic shifted 5% -> 100%)Fast (< 5 seconds revert)MediumHigh-Volume Global User Apps

3. Production Implementation Blueprint & Code Pattern

GitHub Actions workflow orchestrating automated Docker container builds, ECR push, and AWS ECS Blue/Green deployment:

name: Production Zero-Downtime Deployment
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4

      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-1

      - name: Build & Push Docker Image to ECR
        run: |
          docker build -t 123456789.dkr.ecr.us-east-1.amazonaws.com/codeplant-api:${{ github.sha }} .
          docker push 123456789.dkr.ecr.us-east-1.amazonaws.com/codeplant-api:${{ github.sha }}

      - name: Deploy to AWS ECS (Blue/Green)
        uses: aws-actions/amazon-ecs-deploy-task-definition@v2
        with:
          task-definition: task-def.json
          service: codeplant-prod-service
          cluster: codeplant-cluster
          wait-for-service-stability: true