The database table was live in production when the request came in: add a new column without downtime.
A new column sounds simple until it’s running against millions of rows. Schema changes can lock writes, block reads, or grind services to a halt. The challenge is executing an ALTER TABLE with precision, speed, and no impact on user experience.
First, determine the column type and default value. For large datasets, avoid defaults that cause a full table rewrite. Instead, add the column as nullable, then backfill in controlled batches. This reduces locks and keeps transaction logs from bloating.
In MySQL, online DDL can be enabled for some operations with ALGORITHM=INPLACE or ALGORITHM=INSTANT. In PostgreSQL, adding a nullable column without a default is fast, but setting a default forces a rewrite unless applied in a separate step. Use ADD COLUMN with care, then migrate data in small increments.