The query was slow, and the table had grown beyond control. You needed a new column, and you needed it without downtime.
Adding a new column in production sounds simple, but at scale it’s a tightrope. Schema changes can lock tables, block writes, and stall critical systems. The right approach depends on database type, workload, and tolerance for risk.
In PostgreSQL, ALTER TABLE ADD COLUMN runs fast when adding a nullable column without a default. This is metadata-only, avoiding a full table rewrite. But adding a column with a default value before PostgreSQL 11 rewrites the table, which can freeze large datasets. In MySQL, adding columns can cause a table copy unless you use an engine and options that support ALGORITHM=INPLACE or INSTANT.
For distributed databases, think ahead. New columns can affect replication lag, serialization formats, and backward compatibility. Rolling out a schema change alongside application changes must be done in phases. Deploy first with the column optional and unused, then backfill data in small batches, and only then update the app to depend on it.