Soru

Zorluk: Çok zorDeployment Strategy Design

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?

  1. 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.Cevap
  2. B
    Configure 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.
  3. C
    Deploy 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.
  4. D
    Use 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.

Cevap

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.

Adım Adım Çözüm

1
Analyze the database schema change and deployment constraints.
Identify that adding a non-null column directly violates backward compatibility, as older application tasks still serving traffic will not write to this column, causing database constraint failures.
Ensures the application can maintain zero downtime during the deployment phase.
2
Adopt the Expand/Contract database design pattern.
The new column is first created as nullable (expand phase) so both older (blue) and newer (green) tasks can write to the database. The non-null constraint is deferred until after the blue tasks are fully decommissioned (contract phase).
Allows safe rollback without dropping the database column or losing data from newly routed writes.
3
Configure the blue/green deployment pipeline using AWS CodeDeploy.
Fargate tasks are updated using a CodeDeploy blue/green deployment pattern. The AfterAllowTestTraffic hook triggers an AWS Lambda function to run synthetic transaction tests against the green environment via a test listener.
Provides a safe mechanism to validate the green application version using actual database connections before switching production traffic.
4
Validate the rollback mechanism.
If validation fails, CodeDeploy automatically redirects traffic back to the blue environment. Because the database was not modified in a breaking way, the old application tasks can immediately continue serving traffic, and database records written during the test window are preserved.
Guarantees zero data loss and fits the 5-minute rollback requirement.

Anahtar Kavram

The Expand/Contract pattern combined with CodeDeploy blue/green hooks enables zero-downtime application deployments and safe rollbacks when schema changes are required.
Bu soruyu puanla