Database Migrations Without Downtime

·1 min read·

Deploying a schema change to 50 million rows is not the same as 50,000. Here is the discipline that keeps production healthy.

The naive approach: write your ALTER TABLE statement, run it in production, hope the table lock resolves before monitoring alerts fire. For small tables, this works. For a table with 50 million rows, ALTER TABLE can lock for minutes.

The professional approach: deploy code handling both old and new schemas simultaneously. Run the migration using online schema change tools (gh-ost for MySQL, pg_repack for PostgreSQL) that build the new table in the background. Verify data integrity. Remove the backwards-compatibility code.

This is slower. It requires more discipline. And it keeps your production system healthy.

Schema changes are not deployments. They are operations. Treat them accordingly.

— Dick Bassey | DevDick | 2023

Share this article
← Back to all writing