Skip to content

Database Schema Migrations Strategy for ECS Fargate Blue-Green Deployments with CodeDeploy

0

Hi AWS experts, can you help answer this for me? I am looking for guidance on implementing blue-green deployments for a containerized application using ECS Fargate with CodeDeploy, where the application requires database schema migrations during deployment.

I run a microservices architecture on ECS Fargate with RDS PostgreSQL and want to implement blue-green deployments using CodeDeploy, but face a challenge: their application requires database schema migrations (adding columns, indexes) during deployment. The concern is that running migrations during the blue-green switch could cause:

Downtime if migrations take too long, compatibility issues between old (blue) and new (green) task definitions accessing the same database, and rollback complications if the green environment fails after migrations are applied

What's the recommended approach for handling database migrations in ECS blue-green deployments?

2 Answers
1
Accepted Answer

Hello.

RDS also has features for performing Blue/Green deployments.
How about using this feature to perform migrations and tests in an RDS Green environment before deploying to ECS?
If there are no problems afterward, you can start the ECS deployment and switch the RDS to the Green environment while the ECS deployment is in progress to minimize downtime.
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/blue-green-deployments-overview.html

EXPERT
answered 2 months ago
EXPERT
reviewed 2 months ago
1

For handling database schema migrations in ECS Fargate blue-green deployments with CodeDeploy, the recommended approach is to decouple database schema changes from application code changes. This means treating the database as outside of the blue/green environment boundary, where it's shared between both the blue and green environments.

There are two primary strategies you can use, often in tandem:

Before Deployment (Additive Changes): Change the schema first, before the blue-green code deployment. This approach works well for additive modifications like adding new columns, fields, entities, or indexes. The critical requirement is that database schema changes must be backward compatible, meaning your old version of the application (blue environment) can still interact with the database without errors. Your application code should be developed following best practices to tolerate the presence of additional fields that it may not yet use.

After Deployment (Deletive Changes): Change the schema last, after the blue-green code deployment. This approach is used when you need to remove fields, entities, or relationships from the database. Here, your new application code changes must be backward compatible with the old schema, so the application can interact with both the previous and new version of the database schema during the transition. Note that after executing the schema change, the previous version of the application will no longer be operational, so this carries higher risk.

For your specific scenario with adding columns and indexes, you would typically use the "before deployment" approach. Run your migrations before initiating the blue-green deployment, ensuring that both your blue tasks and new green tasks can work with the updated schema. This prevents compatibility issues and allows for safer rollbacks since the blue environment remains functional throughout the process.

The key is ensuring your application code is designed to handle schema changes gracefully, and that you have strong testing and QA phases to validate compatibility before production deployment.
Sources
Best Practices for Managing Data Synchronization and Schema Changes - Blue/Green Deployments on AWS
Community | Levelling up Your Releases: Reduce Risk with Blue/Green Deployments
Community | Levelling up Your Releases: Reduce Risk with Blue/Green Deployments

answered 2 months ago
EXPERT
reviewed 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.