The database was live, traffic peaking, when the request came in: add a new column without downtime.
A new column sounds trivial. It isn’t. The wrong approach locks tables, slows queries, or takes the whole service offline. At scale, even a single ALTER TABLE can choke throughput. The challenge is to change the schema while keeping every API call fast and every user session intact.
The safest pattern is additive and non-blocking. First, create the new column with a NULL default. Do not apply constraints yet. Modern relational databases like PostgreSQL and MySQL can add such columns instantly if you avoid default value rewrites.
Next, backfill the data in controlled batches. Use small transactions to avoid overwhelming replication or caches. Monitor execution time and adjust batch size dynamically. Keep indexes off until the data load is complete to avoid the extra write overhead during backfill.