An organization is designing a deployment strategy for a critical, high-volume payment processing application hosted on AWS Fargate behind an Application Load Balancer (ALB). The backend database is an Amazon Aurora PostgreSQL cluster. A new release requires updating the Fargate task definition and applying a database schema modification that introduces a new column. The deployment must guarantee zero downtime, support automatic rollback within 5 minutes based on synthetic transaction errors, and ensure that if a rollback occurs, the database remains in a consistent state without losing any transaction data captured during the deployment window. Which deployment strategy meets these requirements with the least operational complexity?
- Implement a two-phase database schema change (Expand/Contract). First, deploy a database migration that adds the new column as nullable. Use AWS CodePipeline with AWS CodeDeploy to perform a blue/green deployment of the Fargate service. Configure a CodeDeploy AppSpec hook at AfterAllowTestTraffic to trigger an AWS Lambda function that runs synthetic test transactions against the green target group. If the tests fail, CodeDeploy rolls back traffic automatically. Once the deployment is successfully completed, execute a second database migration to enforce the non-null constraint on the column.Answer
- BConfigure AWS CodeDeploy to perform a linear deployment on the Fargate service. Run the database migration script within the Fargate container startup task to automatically update the schema. Use Amazon Route 53 DNS failover to route traffic back to the old environment if CloudWatch Alarms detect errors. Restore a database snapshot taken immediately before the deployment to reverse the schema changes in the event of a rollback.
- CDeploy a duplicate Aurora PostgreSQL database cluster for the green environment. Use AWS CodeDeploy to perform a blue/green deployment for the Fargate tasks, targeting the new database cluster. Configure an AWS Lambda function in the BeforeAllowTraffic hook to synchronize transactions from the blue database to the green database. In case of rollback, swap the Fargate tasks back to the blue environment and terminate the green database cluster.
- DUse an AWS CloudFormation template to perform a rolling update of the Fargate service by updating the task definition, setting the minimum healthy percent to 50% and maximum percent to 200%. Run the database schema migration as a CloudFormation Custom Resource before updating the ECS service. If the deployment fails, trigger a CloudFormation rollback which automatically runs a custom resource script to drop the new database column.
Answer
Implement a two-phase database schema change (Expand/Contract). First, deploy a database migration that adds the new column as nullable. Use AWS CodePipeline with AWS CodeDeploy to perform a blue/green deployment of the Fargate service. Configure a CodeDeploy AppSpec hook at AfterAllowTestTraffic to trigger an AWS Lambda function that runs synthetic test transactions against the green target group. If the tests fail, CodeDeploy rolls back traffic automatically. Once the deployment is successfully completed, execute a second database migration to enforce the non-null constraint on the column.
The correct strategy implements the Expand/Contract database migration pattern combined with AWS CodeDeploy blue/green deployment. Creating the new column as nullable first keeps the schema backward-compatible with active production tasks. The AfterAllowTestTraffic hook runs validation tests on the green target group using a separate test port before any production traffic is routed. If the tests fail, CodeDeploy rolls back the application version automatically, preserving all database writes. Once the new application version is successfully serving all production traffic, a final migration applies the non-null constraint.
Step-by-Step Solution
Key Concept
The Expand/Contract pattern combined with CodeDeploy blue/green hooks enables zero-downtime application deployments and safe rollbacks when schema changes are required.