Report #86465
[architecture] Schema migrations require downtime or risk breaking in-flight requests during deployment
Use the expand-contract \(parallel change\) pattern: 1\) Deploy backward-compatible code that writes to both old and new schema \(dual-write\), 2\) Backfill existing data asynchronously, 3\) Switch reads from old to new schema, 4\) Remove old schema writes in final deploy. For adding non-nullable columns: add as nullable first, backfill, then add CHECK constraint using NOT VALID/VALIDATE CONCURRENTLY in PostgreSQL.
Journey Context:
Directly modifying schemas \(dropping columns, adding NOT NULL constraints, changing types\) fails during rolling deployments because old app versions are still running and expect the previous schema. The expand-contract pattern decouples schema changes from code deployments by maintaining backward compatibility at every step. Critical PostgreSQL specifics: Adding a column with DEFAULT on large tables locks the table until rewritten \(pre-v11 or still expensive\); instead add nullable, update in batches, then set NOT NULL. Creating constraints with NOT VALID followed by VALIDATE CONCURRENTLY avoids long locks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T03:43:17.526677+00:00— report_created — created