{
  "id": 22999458,
  "title": "Zero-Downtime Database Migration Playbook",
  "url": "https://urgent.news/2026/12/01/zero-downtime-database-migration-playbook",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-12-01T19:27:16.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/samaythakkar/zero-downtime-database-migration-playbook-2g6l"
  },
  "original_language": null,
  "account": "Performing a database migration without any downtime requires careful planning and execution. The key is to keep the old database live as the source of truth while copying the existing data to the new store. Every new change must be streamed to the new store and continuously compared to ensure they match until they agree.\n\nThe copy process involves taking a consistent snapshot of the old database and simultaneously loading it into the new store. At the same time, all changes made since the snapshot must be captured and replayed until the new store has caught up. This is achieved through a technique called change data capture (CDC).\n\nThe migration process can be broken down into three main phases. First, a full load of existing data is performed. Next, the changes cached during the load are applied. Finally, ongoing replication ensures that the new store remains up-to-date with the latest changes from the old database. This is accomplished by collecting changes from the database logs through the engine's own interface.\n\nTo keep the backfill process safe, it is important to record the log position before the snapshot. This ensures that no changes fall into the gap between the copy and the stream. The copy should be done in throttled batches to prevent slowing down the production database that users still depend on. Additionally, every write should be idempotent, meaning that a batch that runs twice will produce the same result. Transformations should also be handled in the pipeline rather than manually, with the mapping kept in version-controlled code with tests.\n\nDuring the migration, the application should not be aware that a migration is happening. It is crucial to serve all reads from the old database, even as writes are being performed on both the old and new databases simultaneously. This approach, known as CDC, is preferred over dual writes whenever possible. Dual writes should only be used when CDC cannot do the job, such as when the new data model can only be produced by application logic or when the old database's change log cannot be read.\n\nTo reconcile any differences between the old and new stores, they must be continuously checked against each other at multiple levels of detail. This includes checking row counts per table or tenant, missing or duplicated batches (every few minutes), checksums per key range (hourly or nightly), field-level diffs on samples (daily), and shadow reads (continuously during the read stage). Shadow reads involve querying production queries to the new store and comparing the results, without users seeing the new store's answer.\n\nThe migration process should be moved in stages, starting with moving reads first, a slice at a time, behind a feature flag. Writes should only be moved once the new store is serving all reads correctly. Shadow reads can be used to compare results, with users only seeing the old store. Read ramp-ups involve serving real reads from the new store for a limited number of internal tenants, gradually increasing the percentage of traffic until all traffic is served by the new store. At each step, error rates and latency must match the baseline, and users should be kept on one store at all times.",
  "summary": "To move a database without downtime, keep the old database live as the source of truth. Copy the existing data, stream every new change to the new store and check that the two match until they agree. Then move reads and writes over in small steps you can undo. Retire the old database only after the new one has run alone, with no problems, for an agreed period. Why do database migrations cause…",
  "summary_source": "publisher",
  "key_points": [
    "Perform zero-downtime migration by keeping old database live as source of truth",
    "Use change data capture (CDC) to stream new changes to new store continuously",
    "Break migration into three phases: full load, apply cached changes, ongoing replication"
  ],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}