Course contentsShow
← Software Engineering
Lesson 893 of 1,93327. Database Design in PracticeFree lesson

Zero-Downtime Schema Changes

Techniques for deploying schema changes without stopping the application, including additive changes and gradual rollout.

Zero-Downtime Schema Changes

You'll learn how to modify your database schema while keeping your application running continuously for users.

When your application serves live traffic, you can't just pause everything to alter your database schema. Zero-downtime deployments require coordination between database changes and application code so users never experience interruptions or errors.

The Core Challenge

Traditional schema changes—like dropping a column or renaming a table—break running application instances that still expect the old schema. If you deploy the schema change instantly, any code referencing old structures fails immediately.

Additive Changes: The Safe Foundation

Additive changes introduce new structures without removing or modifying existing ones:

  • Adding a new table
  • Adding a new column (nullable or with defaults)
  • Adding a new index

These are inherently safer because old application code continues working—it simply ignores the new structures. Deploy the schema change first, then deploy application code that uses the new structures.

Gradual Rollout Strategy

For non-additive changes (renames, deletions, type changes), use a phased approach:

  1. Expand: Add new structures alongside old ones (duplicate column, new table)
  2. Migrate: Write to both old and new; backfill existing data gradually
  3. Read from new: Deploy code that reads from new structures while still writing to both
  4. Contract: Once old structures are unused, remove them

This spreads the change across multiple deployments, ensuring backward and forward compatibility at each step.

Real-World Example Pattern

To rename email to email_address:

  • Deploy 1: Add email_address column
  • Deploy 2: Write to both columns, backfill data
  • Deploy 3: Read from email_address, still write to both
  • Deploy 4: Remove writes to email, then drop the column

Key Takeaway: Zero-downtime schema changes require breaking modifications into small, additive steps that maintain compatibility with all running application versions simultaneously.