---
title: "Leveraging Change Data Capture For Database Migrations At Scale"
description: "Squarespace migrated many PostgreSQL databases to CockroachDB without write downtime by streaming changes through a CDC pipeline: pgoutput logical decoding feeds per-table Debezium connectors into Kafka (Avro), and per-table Apache Beam pipelines on Dataflow upsert batched events into CRDB with checkpointing and backpressure."
url: "https://swe.quest/articles/leveraging-change-data-capture-for-database-migrations-at-scale-c10095cde295b15f"
canonical: "https://engineering.squarespace.com/blog/2025/leveraging-change-data-capture-for-database-migrations-at-scale"
source: "Squarespace Engineering"
published: "2025-05-13"
difficulty: "medium"
kind: "Case study"
reading_minutes: 6
tags: ["schema-migrations","event-driven","postgres","distributed-databases","stream-processing"]
---

# Leveraging Change Data Capture For Database Migrations At Scale

A post on [Squarespace Engineering](https://swe.quest/sources/squarespace.md), published 2025-05-13, 6 min read, Case study. Original: [https://engineering.squarespace.com/blog/2025/leveraging-change-data-capture-for-database-migrations-at-scale](https://engineering.squarespace.com/blog/2025/leveraging-change-data-capture-for-database-migrations-at-scale)

## Summary

Squarespace migrated many PostgreSQL databases to CockroachDB without write downtime by streaming changes through a CDC pipeline: pgoutput logical decoding feeds per-table Debezium connectors into Kafka (Avro), and per-table Apache Beam pipelines on Dataflow upsert batched events into CRDB with checkpointing and backpressure. A reverse changefeed into a separate Kafka queue gave a rollback path to Postgres, and a homegrown diffing tool validated data before cutting over via a proxy. Snapshots reached about 60k rows/s and most systems were over 99.99% fresh at cutover, though some needed brief write pauses. Foreign-key failures across independent per-table writers, including cyclic constraints CRDB can't defer, were handled by disabling constraints during the isolated migration and restoring them before cutover.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Schema migrations](https://swe.quest/tags/schema-migrations.md) (Data & databases)
- [Event-driven architecture](https://swe.quest/tags/event-driven.md) (Backend & APIs)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Distributed databases](https://swe.quest/tags/distributed-databases.md) (Data & databases)
- [Stream processing](https://swe.quest/tags/stream-processing.md) (Data & databases)

## Prerequisites

- PostgreSQL logical replication ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- Kafka basics ([easy posts on Queues & messaging](https://swe.quest/tags/messaging.md?difficulty=easy))
- foreign key constraints

## Keywords

CockroachDB, PostgreSQL, Debezium, Kafka, Apache Beam, Google Cloud Dataflow, pgoutput, MOLT Fetch

## Related posts

- [Change Data Capture (CDC) with PostgreSQL and ClickHouse - Part 2](https://swe.quest/articles/change-data-capture-cdc-with-postgresql-and-clickhouse-part-2-2123f803752f2e9d.md): ClickHouse · 2023-06-15 · Medium · 22 min read · Event-driven architecture, PostgreSQL, Analytics & OLAP, Data pipelines, Replication
  A Postgres-to-ClickHouse CDC pipeline is built with Debezium, Kafka Connect and a ClickHouse materialized view, keeping a ReplacingMergeTree table in sync with the 28M-row UK property price dataset under a mix of inserts, updates and deletes.
- [Scaling SaaS security: Reco’s migration from Postgres to ClickHouse Cloud](https://swe.quest/articles/scaling-saas-security-reco-s-migration-from-postgres-to-clickhouse-cloud-644c039f853be147.md): ClickHouse · 2025-11-17 · Medium · 6 min read · Analytics & OLAP, PostgreSQL, Stream processing, Performance engineering, Cost optimization
  Reco, a SaaS security platform ingesting 10-12 billion JSON events weekly, moved over 90% of its workload from Postgres to ClickHouse Cloud.
- [Change Data Capture (CDC) with PostgreSQL and ClickHouse - Part 1](https://swe.quest/articles/change-data-capture-cdc-with-postgresql-and-clickhouse-part-1-10e3d601e2748dab.md): ClickHouse · 2023-06-15 · Medium · 23 min read · Event-driven architecture, PostgreSQL, Analytics & OLAP, Replication, Queues & messaging
  Postgres-to-ClickHouse CDC can be built by streaming row changes from Postgres logical decoding (pgoutput plugin, replication slots, LSN ordering) through Debezium and Kafka, then applying them in ClickHouse with the ReplacingMergeTree engine.
- [How we migrated a live routing system using AI-assisted refactoring](https://swe.quest/articles/how-we-migrated-a-live-routing-system-using-ai-assisted-refactoring-db938ac15eae4cef.md): Datadog Engineering · 2026-06-23 · Medium · 13 min read · Refactoring & migrations, AI for coding, PostgreSQL, Schema migrations, Testing
  Datadog migrated Stream Router, the control plane that tells metrics producers and queriers which Kafka cluster, topic and partitions to use, from a FoundationDB key-value model to a relational schema.
- [How we migrate TBs from Heroku without logical replication](https://swe.quest/articles/how-we-migrate-tbs-from-heroku-without-logical-replication-e0568c616a878849.md): PlanetScale · 2026-11-11 · Medium · 12 min read · PostgreSQL, Schema migrations, Replication, Networking
  PlanetScale's open-source Heroku Migrator moves multi-terabyte Postgres databases off Heroku standard plans, which lack WAL access and logical replication, by using Bucardo trigger-based replication: triggers record changes in delta tables, a one-time COPY loads existing data, and a worker replays the backlog before a controlled switchover with verification.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
