Back to all posts
Backend8 min read·November 8, 2026

Database Migrations Without Downtime, Explained for Founders

TB
ThynkBlox Team
Engineering

You can usually change a live product's database without taking it offline. The method is to split one risky change into several small, safe ones. First add the new structure next to the old one. Then move the data across gradually while old and new code both keep working. Remove the old structure only once nothing depends on it. Engineers call this the expand, migrate, contract pattern. With a tested backup and a rollback plan, it lets most schema changes go out while customers keep using the product.

Why can a database change take a live product offline?

The database holds your product's records in tables, and the schema is the layout of those tables: which columns exist, what type of data each one holds and how the tables relate to each other. Changing the schema means changing that layout while the application is still reading from it and writing to it.

Some schema changes make the database lock a table, which means it briefly stops other work from reading or writing that table so the structure can change safely. On a small table the lock may last a moment. On a large, busy table the database may have to rewrite or check every row, and the lock can last long enough for requests to pile up behind it. To a customer, a save that hangs, then times out, looks the same as an outage.

The lock an operation needs depends on the operation and on the database engine. PostgreSQL's ALTER TABLE documentation, for example, notes that the lock level can differ for each kind of change, and that most take the strictest lock unless stated otherwise. That uncertainty is one reason teams rehearse migrations instead of assuming they will be quick.

The second risk is a mismatch. Releases rarely switch every server over at the same instant. If the new code expects a column that is not there yet, or the old code still writes to a column that has just been removed, requests fail even with no lock involved.

What is the expand, migrate, contract pattern?

It replaces one breaking change with a sequence of changes that are each compatible with the code running alongside them.

  • Expand: add the new columns or tables without removing or renaming anything. Existing code ignores the additions and carries on working.
  • Migrate: release code that writes to both the old and the new structure, copy existing data across in batches, then move reads over to the new structure.
  • Contract: once everything runs on the new structure, and you have confirmed nothing still uses the old one, remove the old columns or tables.

Take an illustrative example: you want to split a single "customer name" field into "first name" and "last name". Renaming or deleting the old field in one step would break any server still running the previous release. Using the pattern, the team adds the two new fields, updates the code to fill all three, copies historical names across, switches the screens to read the new fields and, in a later release, retires the old one.

What are the steps, in order?

StepWhat happensCustomer impact if done wellHow to undo it
1. Back up and verifyTake a fresh backup and confirm it can be restoredNoneNot applicable
2. Expand the schemaAdd new columns or tables; change nothing that existing code usesNoneDrop the unused additions
3. Dual-write releaseCode writes to old and new structures, still reads the old oneNoneRedeploy the previous release
4. Backfill in batchesCopy existing records to the new structure in small chunksNone, or slightly slower responsesPause the job; the old data is untouched
5. Verify the dataCompare old and new values and fix any differencesNoneRe-run the backfill for the affected records
6. Switch readsCode reads from the new structure, often behind a feature flagNoneTurn the flag off
7. Stop old writesCode stops writing to the old structureNoneRe-enable dual writes
8. ContractRemove the old structure after an agreed waiting periodNoneRestore from backup, so this is the step to be most careful with

Up to step 7, every step can be reversed quickly because the old data is still there. The final step is the only one-way door, which is why it should happen later and on purpose, not in the same release.

Why do backups come first?

Every migration plan should start by answering one question: if this goes wrong, how do we get the data back? A backup only counts if someone has restored it recently and confirmed the result works. Ask how long a restore takes and how much recent data would be lost, because those two answers tell you what a worst case would actually cost. Our guide on testing software backup restoration explains what evidence to ask for.

Take a fresh backup immediately before the expand step and again before the contract step.

Why must old and new code run together?

During a rollout, some servers or app installations will run the previous version for a while. Mobile apps make this worse, because some users do not update for a long time. Each schema step therefore has to work with both the current release and the one before it.

That is also what makes rollback cheap. If the new release misbehaves, the team can redeploy the previous one and the database will still suit it. Feature flags help by separating "the code is deployed" from "the new behaviour is switched on". See feature flags explained for founders and the wider software deployment rollback plan.

How does backfilling in batches avoid slowdowns?

Copying millions of rows in one operation can hold locks, fill logs and compete with customer traffic. A batched backfill handles a limited number of records at a time, pauses between batches and records its progress so it can resume after an interruption. It can be slowed down or stopped if response times rise.

Ask the team to watch error rates and response times while the backfill runs, and to schedule it for quieter periods where that is practical. Software monitoring after launch covers the signals worth watching.

How does rollback work at each stage?

Rollback is simple while both structures exist. You redeploy the previous code, turn off a flag or pause a job. Once the old structure is removed, the only way back is restoring from a backup, which may lose recent data and takes time. Before you approve the contract step, ask the team to confirm:

  • The new structure has been the only source for reads for an agreed period
  • Logs or queries show nothing still uses the old structure, including reports, exports and integrations
  • A fresh, verified backup exists
  • Someone is named to respond if problems appear afterwards

When is planned downtime acceptable?

Zero downtime takes more steps and more engineering time. Sometimes a short, announced maintenance window is the more sensible choice. It can be reasonable when:

  • The product has natural quiet periods, such as a business tool used only during office hours
  • The tables involved are small and a rehearsal shows the change completes quickly
  • The change is too complex to keep old and new code compatible, for example when moving to a different database engine
  • The product is pre-launch or used only internally
  • Your support agreement already allows scheduled maintenance windows
  • The cost of the extra engineering outweighs a brief, communicated pause

Avoid downtime when customers rely on the product around the clock, when it handles payments or bookings in progress, or when your contracts promise continuous availability. Whichever way you decide, write the decision down. For larger moves between systems, see the data migration plan for replacing business software.

What common mistakes should founders watch for?

Bundling expand and contract into one release. That removes the safety net. Ask for them to be shipped separately.

Rehearsing on tiny test data. A change that is instant on a few hundred rows can lock a large production table. Rehearse in a staging environment with realistic data volumes; see dev, staging and production environments explained.

Forgetting other readers of the data. Reports, exports, integrations and analytics jobs may still use the old column after the app has moved on.

Treating an untested backup as a plan. Ask when it was last restored.

Never doing the contract step. Leaving old columns behind forever adds confusion and becomes technical debt. Put the cleanup on the plan with a target release.

Frequently asked questions

Does every database change need this pattern?

No. Adding a new optional column or a new table is usually safe on its own. The pattern matters for renames, removals, type changes and anything that touches large, busy tables.

Does it make a release take longer?

Yes. One change becomes several releases, but each is smaller and easier to reverse. For most live products, that trade is worth it.

What should I ask before approving a migration?

Ask which step this release covers, whether the previous release still works with it, how it will be undone, when the backup was last restored and who is watching during the rollout.

Does the choice of database matter?

Engines handle locks and schema changes differently, so the exact technique varies. The expand, migrate, contract principle applies to both relational and document databases. Our comparison of PostgreSQL and MongoDB covers the wider trade-offs.


*Planning a database change on a live product? Start a conversation →*

Ready to build?

Let's turn these ideas into your next product.

Start your project