Urgent.News

What's breaking now, across thousands of outlets.

Tech

Zero-Downtime Database Migrations: A Practical Guide

Every growing product eventually hits the same wall: the schema that got you to your first thousand customers can’t support the next hundred thousand. A column needs to change type, a table needs to split, an index needs to be added to a table that’s grown too large to lock. And the business keeps running while you do it — for teams handling millions of daily users, taking the application offline…

This guide outlines a practical approach to performing zero-downtime database migrations, crucial for growing products with ever-expanding schemas. The key principle is never to introduce changes that both old and new application versions cannot handle simultaneously. By breaking the migration into three phases - expand, backfill, and cutover - each step can be safely deployed and rolled back independently.

In the first phase, the schema is expanded without altering existing structures. New columns are added as nullable first, followed by backfilling data into them. Indexes should also be added concurrently to avoid blocking hot tables. Renaming structures should be postponed until the final contract phase.

The backfill phase involves incrementally updating large tables, row by row, to incorporate new columns or tables. This process generates minimal locks and replication lag, ensuring uninterrupted production traffic. It's essential to validate the backfill results before proceeding to avoid data integrity issues.

The cutover phase is where the application starts using the newly expanded schema. This is done through dual writes behind a feature flag, allowing simultaneous writes to both old and new structures while reads continue from the old one. Once the dual-write path is stable, reads are gradually switched to the new structure in a controlled manner, similar to canary deployments. The old structures are then removed after a full deprecation window, providing a safety net in case any issues arise during the transition.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Preserving Citations in Publishing Pipelines

How can an automated publishing pipeline preserve citations from source input through the live article? When an automated workflow ingests research, the final published page often loses its source…

You can buy attendance, You can buy hours, But the feeling that "this system is mine" is Not for Sale!

The night an entire cloud region went down under us, I watched something that no on call policy can produce. Engineers joining the incident bridge who were not on call, had not been paged, and had…

  • Engineers worked 30 hours without being summoned, treating systems as their own
  • Ownership earned through daily practices, respect, and cross-training
  • Feeling of ownership not for sale, crucial for accountability and trust

Read replicas and data synchronization: how to prevent your website from crashing due to your own success

If your business has grown, you've probably noticed that your website or app starts to slow down when more people are connected at the same time.

  • Réplicas de lectura distribuyen carga de tráfico de consultas de solo visualización.
  • Copia sincronizada de base de datos principal para leer, no escribir.
  • Mejora rendimiento de web al separar tráfico público de operaciones críticas.

More from Wednesday 30 September →