Image
Build
Connect & operate
Design & teams
Start hereScope a build in one callBring a spec, a wireframe, or a paragraph. You leave with an architecture, a timeline, and a number.Request a scoping call
AI software
LLM & data systems
Vibe coding
Ready to ship?Put AI where the work isAgents, RAG, and private LLMs wired into the systems your team already uses — not a chatbot bolted to a homepage.Discuss an AI project
Domain firstWe learn your workflow before we model itRegulated, operational, or high-volume — the constraints belong in the schema, not in a training doc.Talk about your domain
Samuel Edwards
Author
Migrating a Production Postgres Database With CDC and Dual Writes — featured image
12/1/2026

Migrating a Production Postgres Database With CDC and Dual Writes

Cutting over a production Postgres cluster before reconciliation finishes is the mistake that pulls a replatforming project under, and unplanned outages during that window run roughly $14,056 per minute. The pattern that avoids it pairs change data capture with dual writes, in a specific order.

Logical replication goes up first. A snapshot backfills history, the application begins writing to both clusters, reconciliation runs until divergence is zero, then DNS flips. A rollback path stays open until the new primary has carried a full business cycle.

That order is the whole trick. CDC without dual writes leaves a widening replication lag during cutover; dual writes without CDC leave no safety net if one side drops a transaction. You need both.

The Pattern in One Paragraph

Call the current primary source and the target destination: a new major version, a cross-cloud replica, or a cluster with the schema you actually wanted. A replication slot on source streams the write-ahead log to a CDC consumer, which applies rows to destination. Once initial lag closes, the application starts writing to both clusters in the same transaction scope, with source as the authority. A reconciliation job compares row counts and checksums until they match. Read traffic shifts to destination. Writes shift. Dual writes stay on for one more business cycle as a reversible safety net, then come down.

The failure modes to design against are the usual ones: a dropped WAL segment, a schema change that replication silently ignored, and a dual-write that committed on one side and crashed before committing on the other.

Logical Replication Is the Prerequisite, Not the Plan

Postgres can stream row-level changes over logical replication, but the server has to be configured for it. wal_level must be set to logical, which is not the default and requires a restart. Plan the restart into the migration timeline before anything else, because on a busy OLTP system it is the one unavoidable blip the pattern cannot eliminate.

The documentation is explicit about what logical replication does not carry: DDL changes and incremental sequence updates are not replicated. That means schema migrations run on both clusters, in the same order, with the application tolerating either shape during the overlap. Sequences need a separate sync step at cutover or writes on destination collide with ids the source already used.

Databases Used by Professional Developers, 2024
Databases Used by Professional Developers, 2024PostgreSQL: 51.9%; MySQL: 39.4%; SQLite: 32.1%; SQL Server: 27.1%; MongoDB: 25.2%; Redis: 22.8%; MariaDB: 17.1%; Elasticsearch: 14.3%; Oracle: 10.3%; DynamoDB: 9.2%PostgreSQL51.9% · 21%MySQL39.4% · 16%SQLite32.1% · 13%SQL Server27.1% · 11%MongoDB25.2% · 10%Redis22.8% · 9%MariaDB17.1% · 7%Elasticsearch14.3% · 6%Oracle10.3% · 4%DynamoDB9.2% · 4%
Postgres sits at the top of the professional developer survey for the second straight year, which is why a clean migration playbook for it matters. Source: Stack Overflow Developer Survey, 2024

Debezium Does the Capture, Kafka Does the Durable Queue

For anything beyond a single-destination flip, the Debezium Postgres connector is the default tool. It takes a consistent initial snapshot of every selected schema, then continuously streams INSERT, UPDATE, and DELETE events into Kafka topics keyed by primary key. The snapshot and the streaming phase are a single logical operation from the consumer's point of view, which removes an entire class of ordering bugs.

Kafka earns its place here because it is the durable buffer that lets destination fall behind without losing events. If destination needs a replay, the consumer rewinds its offset. If destination is rebuilt from scratch mid-migration, the snapshot runs once more and the stream picks up where it was. AWS DMS covers the same pattern with a managed runtime and replication slots as the source, at the cost of less control over transformations.

A train crossing a set of switch points onto two parallel tracks at dusk.

Dual Writes Fix What CDC Alone Cannot

A pure CDC cutover has one weak moment: the instant the application starts writing to destination, source stops being authoritative, and any event still in flight from source has to drain before the switch is safe. Most teams underestimate how long that drain is under real load. Dual writes close that drain window by making the application the second source of truth during the overlap.

The hazard in dual writes is well documented. The dual-write problem is what happens when an application commits to two systems without a shared transaction boundary and one of them fails: the systems diverge and no one notices until a reconciliation job runs. Martin Kleppmann's argument that the log is the single source of truth is the right mental model here. Treat source's WAL as the authority, treat the application's write to destination as a hint that reconciliation will verify, and never let a user-facing path block on the destination write succeeding.

Backfill, Then Reconcile Row by Row

Debezium's initial snapshot handles the backfill for most tables. For very large tables, a parallel export-and-import outside the snapshot path is faster: pg_dump a consistent snapshot by LSN, restore to destination, then start the CDC stream from that same LSN. The Stripe engineering team's writeup of their zero-downtime data migrations describes the same backfill-plus-tail pattern against document stores, and the reasoning carries over to relational systems.

Reconciliation then runs on a schedule until the migration window closes:

  • Row counts per table, compared on a rolling window of the last N minutes and on the full table.
  • Checksums over ordered primary-key ranges, so a diff narrows to a specific slice rather than a whole table.
  • Business-key probes on the ten or so tables that drive revenue, run every minute, with a page on any delta.

Divergence on the hot tables is the signal that cutover is not safe yet. Teams that skip this step find out at 3 a.m. that a trigger on source was not recreated on destination, or that a sequence drifted by 400 and every new order is colliding on its primary key. Our walkthrough of monolith-to-microservices migration without downtime covers the same reconciliation discipline for service-level splits.

Stripe's Uptime During Zero-Downtime Migrations
Stripe's Uptime During Zero-Downtime MigrationsUptime maintained: 100%100%of 100%Uptime maintained
The uptime Stripe held in 2023 while running the backfill-plus-tail migrations described here — five nines, against a 100% ceiling. Source: Stripe Engineering, 2024

Cutover and the Rollback That Pays for Itself

The cutover itself is short. Pause writes at the application layer for a few seconds, drain in-flight CDC events, sync sequences, verify a final checksum on the hot tables, flip the write path to destination, resume. Reads can shift earlier, incrementally, behind a feature flag per endpoint.

The rollback path is where the pattern earns its money. Keep source receiving writes from destination via CDC in reverse for one full business cycle after cutover. PostgreSQL 16's bidirectional logical replication, released in September 2023, made this cleaner by preventing the loops that blocked earlier active-active attempts. If destination develops a problem, flipping writes back to source is a configuration change, not a restore from backup. The option itself is usually never exercised, which is exactly what you want from an insurance policy.

The pattern is not free. Dual writes add latency to every mutation during the overlap, CDC adds operational surface area, and reconciliation is a new job to monitor. Teams weighing the tradeoff against a simpler maintenance-window cut should run the numbers in our breakdown of legacy modernization cost. For most production systems carrying real transaction volume, the math lands on the CDC-plus-dual-writes side, and the API layer is where the dual-write logic lives, not the database.

2024 Unplanned Outage Impact Factors
2024 Unplanned Outage Impact FactorsYoY cost rise, all enterprises: 10%; YoY cost rise, 5,000+ employees: 20%; AIOps-driven outage reduction: 30%YoY cost rise, allenterprises10%YoY cost rise, 5,000+employees20%AIOps-driven outagereduction30%
An area shape read as cumulative outage spend was already refused on this page, so the closest honest shape here is a bar across the three figures EMA actually publishes. Source: EMA / BigPanda, 2024

What a Good Answer Sounds Like

Ask any vendor pitching a Postgres migration one question: show the reconciliation report from the last cutover they ran, and the rollback rehearsal that went with it. A good answer is a dashboard or a runbook with specific row counts, checksum diffs, and a documented LSN at which the rollback path was tested under load. A bad answer is a slide about CDC and a promise that nothing will go wrong. The difference between those two answers is the difference between a 90-second write pause and a weekend-long incident, and it is visible before any contract is signed.

Author
Samuel Edwards
Samuel Edwards is the Chief Marketing Officer at DEV.co, SEO.co, and Marketer.co, where he oversees all aspects of brand strategy, performance marketing, and cross-channel campaign execution. With 15+ years of experience in digital advertising, SEO, and conversion optimization, Samuel leads a data-driven team focused on generating measurable growth for clients across industries. Samuel has helped scale marketing programs for startups, eCommerce brands, and enterprise-level organizations, developing full-funnel strategies that integrate content, paid media, SEO, and automation. He is a frequent speaker and contributor on digital trends, with work featured in Entrepreneur, Inc., and MarketingProfs. Based in the greater Orlando area, Samuel brings an analytical, ROI-focused approach to marketing leadership.