Adding a new column to a live database is common, but it can break queries, APIs, and downstream jobs if done without a clear plan. The goal is zero downtime and no data loss. This requires precise steps:
First, define the column in your migration script with safe defaults. For large tables, avoid adding NOT NULL constraints immediately. Write the alter table add column statement in a way that works with your database’s locking behavior. Test the migration on a staging database with production-scale data.
Second, deploy application changes in two phases. In phase one, the code should be able to read from both the old schema and the schema with the new column. In phase two, after the migration completes and data is backfilled, you can switch to requiring the column in code.
For backfilling, batch updates to prevent load spikes. Use indexed writes where possible, and monitor replication lag if you run read replicas. Be ready to throttle or pause if latency rises.