How do you migrate a legacy database without downtime?
The Core Strategy: Parallel Run, Not Big Bang
A 'big bang' cutover — taking the system offline, migrating everything, and bringing it back up — is the simplest approach but creates a maintenance window that can last hours. For any system handling live transactions, that is unacceptable. The alternative is to treat migration as an ongoing synchronization problem, not a one-time event.
Step-by-Step: The Expand-Contract Pattern
- Set up the target database. Provision the new database (new schema, new engine, or new cloud instance) alongside the existing one. Do not touch production yet.
- Establish continuous replication. Use Change Data Capture (CDC) tools — Debezium, AWS DMS, Striim, or native replication — to stream every write from the old database to the new one in near real time. Let it catch up to a lag under a few seconds.
- Enable dual writes at the application layer. Update the application to write to both databases simultaneously. Reads still go to the old system. This ensures the new database stays current even after CDC is turned off.
- Validate data consistency. Run automated reconciliation scripts that compare row counts, checksums, and spot-check business-critical records between both systems. Fix any discrepancies before proceeding.
- Shift reads incrementally. Route a small percentage of read traffic (say 5%) to the new database using a feature flag or a read-replica proxy. Monitor latency, error rates, and query plans. Scale up gradually — 10%, 25%, 50%, 100%.
- Cut over writes. Once reads are fully on the new system and stable, stop dual writes and point all write traffic at the new database. Keep the old database in read-only mode for 24–72 hours as a safety net.
- Decommission the old system. After confirming no application is hitting the old database, take it offline.
Key Tools by Migration Type
| Scenario | Common Tools |
|---|---|
| MySQL → MySQL / Aurora | AWS DMS, Percona XtraBackup, pt-online-schema-change |
| Oracle → PostgreSQL | AWS SCT + DMS, pgloader, Debezium |
| MongoDB → MongoDB Atlas | mongomirror, Atlas Live Migration |
| On-prem SQL → Cloud warehouse | Fivetran, Airbyte, Striim |
Honest Tradeoffs
- Dual writes add complexity. Your application must handle partial failures gracefully — if write A succeeds on the old DB but fails on the new one, you need a reconciliation path.
- Schema differences complicate CDC. If the new schema is structurally different, you need a transformation layer between the replication stream and the target, which is the hardest part to get right.
- Longer total migration time. This approach can take days or weeks end-to-end compared to a weekend cutover, but that time is spread across working hours with no customer impact.
Where to Get Help
If your legacy system has years of undocumented schema debt, mixed data quality, or tightly coupled application logic, the data transformation layer is where migrations typically fail. Studios like CodeNicely have run this process for clients modernizing fintech and logistics platforms — the work is methodical but high-stakes. That said, cloud vendors (AWS, GCP, Azure) also offer managed migration services worth evaluating depending on your stack.
Related questions
What is Change Data Capture (CDC) and why does it matter for migrations?
CDC monitors a database's transaction log and streams every insert, update, and delete to another system in near real time. For zero-downtime migrations, it closes the gap between your initial data snapshot and live production traffic so the new database stays current without halting writes.
Can you migrate a database without changing the application code?
Sometimes — if the new database is schema-compatible and you're only moving infrastructure, a proxy or DNS cutover can handle the switch transparently. But if the schema or query dialect changes (e.g., Oracle to PostgreSQL), application-layer changes are unavoidable.
How do you handle sequences, auto-increments, and ID collisions during dual writes?
The safest approach is to pause ID generation on one system and use a shared sequence service or UUID-based IDs during the migration window. Collisions are a real risk with numeric auto-increments; auditing and reconciliation scripts must catch them before cutover.
How long does a zero-downtime database migration typically take?
It varies widely based on data volume, schema complexity, number of dependent services, and how clean the existing data is. Simple lift-and-shift migrations can complete in days; complex cross-engine migrations with schema redesign can take weeks or months. Contact a migration specialist for a scoped estimate.
Want a direct answer for your project?
CodeNicely builds AI products, MVPs, and custom software for founders and teams worldwide. Tell us what you're building.
Talk to our team_1751731246795-BygAaJJK.png)