Adding a new column seems simple. It is not. In SQL, a ALTER TABLE ... ADD COLUMN can lock the table. In large datasets, seconds become minutes. Transactions back up. Deadlines slip.
Before creating a new column, define its type, constraints, and default values with precision. For relational databases like PostgreSQL and MySQL, adding a non-null column with a default writes to every row immediately. On millions of rows, this is a risk. A safer pattern:
- Add the column as nullable.
- Backfill data in small batches.
- Add constraints after the backfill is complete.
For distributed systems, the approach changes. In systems like BigQuery or Snowflake, schema changes may replicate fast, but query logic must handle both the old and new schema during migration. Feature flags help to switch read paths only when the data is ready.