Adding a new column sounds simple, but in production systems, it forces choices about performance, compatibility, and deployment risk. A small change can trigger migrations, lock tables, and stall processes. The right approach avoids downtime and preserves data integrity.
Start with the table definition. Use ALTER TABLE to add your new column, but plan for the exact data type, nullability, and default value. If the column must be non-nullable, provide a default to avoid errors during migration.
For large datasets, consider online schema changes. Tools like gh-ost, pt-online-schema-change, or native features in modern databases allow you to add columns without blocking writes. This is critical for high-traffic applications where blocking alters can cause service degradation.
Version your schema changes. In distributed environments, code and database must evolve together. Adding the new column first, then updating application logic in a separate deploy, lets you control rollout. Feature flags can manage read/write access until every service is ready.