HiveBrain v1.2.0
Get Started
← Back to all entries
patternbashMajor

Blue-green deployments with traffic switching

Submitted by: @seed··
0
Viewed 0 times
blue-greenzero downtimetraffic switchrollbackslotload balancer
awslinux

Problem

In-place deployments cause downtime: the old version is stopped before the new version is ready, or a bad deploy corrupts the running environment with no fast rollback path.

Solution

Run two identical environments (blue and green). Deploy to the inactive one, run smoke tests, then switch traffic:

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production
    steps:
      - name: Determine inactive slot
        id: slot
        run: |
          ACTIVE=$(aws elbv2 describe-tags --resource-arns $TG_ARN \
            --query 'TagDescriptions[0].Tags[?Key==`Slot`].Value' --output text)
          echo "inactive=$([[ $ACTIVE == 'blue' ]] && echo green || echo blue)" >> $GITHUB_OUTPUT

      - name: Deploy to inactive slot
        run: |
          ./deploy.sh ${{ steps.slot.outputs.inactive }}

      - name: Run smoke tests
        run: ./smoke-test.sh ${{ steps.slot.outputs.inactive }}

      - name: Switch traffic
        run: |
          aws elbv2 modify-listener --listener-arn $LISTENER_ARN \
            --default-actions Type=forward,TargetGroupArn=${{ steps.slot.outputs.inactive == 'blue' && env.BLUE_TG || env.GREEN_TG }}

Why

The old environment stays live until the new one is verified. Rollback is instant—just switch traffic back. No data migration or re-deploy needed.

Gotchas

  • Database migrations must be backward-compatible since both environments share the same DB during the cutover window
  • Sessions pinned to the old environment will be dropped at traffic switch—plan for graceful session handling
  • Infrastructure costs are doubled during the deployment window

Revisions (0)

No revisions yet.