The table was growing, but the schema wasn’t ready. A new column had to land without breaking a single query. There was no room for downtime, no space for half-measures.
Adding a new column sounds simple. In production, it isn’t. Done wrong, it locks tables, slows queries, or causes unexpected nulls to surface in API responses. The key is knowing how to introduce a column without introducing risk.
First, define the column with precision. Use the correct data type from the start—migrations are cheap to write, expensive to run twice. Make sure defaults are set where appropriate, especially for not-null constraints. Plan for whether the column will hold historical data or start fresh.
In relational databases, the safest path is a two-step deploy. Deploy the schema change first, allowing the database to adapt. Backfill data in small batches to prevent table locks. Then update the application code to read and write the new column.
For distributed systems, coordinate migrations with feature flags. Write to the new column while still supporting old reads. Monitor replication lag and index build times before flipping traffic over.