InsightsCloud4 min read

Keeping Database Changes Compatible During Blue-Green Deploys

Blue-green deployment makes application traffic easy to switch, but the database remains shared, stateful, and continuously changing. The hard part is ensuring both versions can read and write safely throughout overlap, migration, and rollback.

Applications Can Switch Instantly; Database State Cannot

In a typical blue-green deployment, blue keeps serving production traffic while green is deployed and verified. A load balancer then redirects requests to green. This works well for stateless services, but when both versions share a database, its schema and contents become a common dependency. Orders, status changes, and events created after the switch do not disappear when traffic returns to blue, so rollback cannot mean merely changing a routing rule.

Before designing a migration, define the required compatibility window. Can the old application run against the expanded schema? Can the new application read records that have not been migrated yet? If traffic returns to blue, can it interpret data written by green? If any answer is no, the schema operation and traffic switch should not be treated as one atomic release step.

Split Breaking Changes into Expand, Migrate, and Contract

The most dependable pattern is to turn one apparently simple schema change into several releases. During expansion, add compatible structures such as nullable columns, tables, or indexes without removing existing fields or changing their meaning. Next, deploy code that understands both representations and migrate historical data gradually. Contract the schema only after the old version can no longer return, backfill is complete, and production observation shows that nothing depends on the old representation.

Suppose customer_name must become given_name and family_name. Do not rename or delete the original column in the first release. Add the new nullable columns, have the new application prefer them while falling back to customer_name, and select a controlled write strategy. It may temporarily write both formats, or keep the old column authoritative while a background process derives the new values. After backfill and verification, a later release can stop dual writes and eventually remove the old column.

  • Expand: Add structures only; avoid renames, narrower types, immediate non-null constraints, and column removal.
  • Migrate: Support old and new representations, then backfill with resumable and idempotent jobs.
  • Verify: Compare representations, monitor missing values and write failures, and identify every remaining consumer.
  • Contract: Remove compatibility code, obsolete columns, and temporary synchronization only after the rollback window closes.

Dual Writes, Backfills, and Constraints Carry Hidden Costs

Dual writing preserves both models but introduces partial-failure risk: one update may succeed while the other fails. When both writes are in one database, a transaction can usually protect consistency. Across databases or external systems, use an outbox, idempotent event consumers, and explicit compensation instead of assuming distributed writes will complete together. Define one authoritative representation as well; otherwise retries and manual corrections can make the two values overwrite each other unpredictably.

Do not attach a large historical backfill to the deployment as one long transaction. Process small batches, persist a cursor or primary-key range, throttle load, and make every batch safe to repeat. Avoid queries that hold locks for long periods, and use online or concurrent index creation where the database supports it. Before adding non-null, unique, or foreign-key constraints, inspect existing data and use staged validation when available. An apparently harmless constraint can otherwise trigger a table scan or block production writes.

Type and enum changes deserve the same caution. Green may write a status value that blue does not recognize even though the physical schema is unchanged. Either make the older reader tolerate unknown values before introducing them, or prevent green from emitting the new meaning while rollback remains possible. If a business workflow cannot be reversed once the new status is used, treat the release as an irreversible product transition rather than an ordinary application deployment.

Make Compatibility a Release Gate

Test at least four combinations against production-like data: old code with the old schema, new code with the expanded schema, old code with the expanded schema, and new code reading records that have not been backfilled. Versioned schema migrations should have a durable execution history and run once, while data backfills should be idempotent and restartable. A safe sequence is usually to apply the compatible expansion first, deploy green, run health checks and shadow reads, and only then move traffic.

After the switch, application error rates are not enough. Watch lock waits, slow queries, connection-pool pressure, backfill progress, differences between old and new fields, and occurrences of unknown values. The rollback runbook should distinguish failures fixed by routing traffic back from those requiring a feature freeze or compensating data operation. If that distinction is missing, the team has an application rollback procedure, not a complete data recovery strategy.

Good blue-green delivery does not force every change into one release. It reduces risk through observable steps that can be paused independently. When the database also feeds ERP, CRM, LINE, analytics, or event-driven integrations, the compatibility window must cover those consumers too. A joint review by application, database, and integration engineers is often more valuable than any deployment switch.

This article was written automatically by AI from a topic planned by Sainso Technology. It is general guidance — assess against your own situation or talk to us before implementing.

Get started

Have a project like this?

Tell us your industry, current systems and budget range. We reply within two working days and offer a free 30-minute consultation.