Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Squarespace Engineering 6 min read Case study mediumAdept

Leveraging Change Data Capture For Database Migrations At Scale

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.

Assumes: PostgreSQL logical replicationKafka basicsforeign key constraints

Related posts

  • Change Data Capture (CDC) with PostgreSQL and ClickHouse - Part 2

    ClickHouse mediumAdept

    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. Key configuration choices include REPLICA IDENTITY FULL (required for delete support), the pgoutput logical decoding plugin, per-row ordering via a single or hash-partitioned Kafka topic, and version/deleted columns in the ReplacingMergeTree engine. The ORDER BY is chosen for analytical access patterns, with the Postgres id appended last for uniqueness. The initial load uses the postgresql table function via INSERT INTO SELECT, which loads all 28M rows in about 80 seconds without tuning but requires pausing writes; Debezium's consistent snapshot is the alternative.

  • Scaling SaaS security: Reco’s migration from Postgres to ClickHouse Cloud

    ClickHouse mediumAdept

    Reco, a SaaS security platform ingesting 10-12 billion JSON events weekly, moved over 90% of its workload from Postgres to ClickHouse Cloud. Running both databases synced via CDC had made schema migrations, updates, deletes and VACUUM painful. Reco replaced RDBMS features with ReplacingMergeTree and CollapsingMergeTree for upserts and deletes, idempotency and eventual consistency instead of transactions, and tenant-level atomic materialized view refreshes via REPLACE PARTITION. Further gains came from compute-compute separation, spill-to-disk settings, parallel_distributed_insert_select=2 (cutting resource needs by a third) and data-skipping indexes, plus using the EmbeddedRocksDB engine as a streaming state store in place of Spark state and Redis.

  • Change Data Capture (CDC) with PostgreSQL and ClickHouse - Part 1

    ClickHouse mediumAdept

    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. Updates and deletes become immutable inserts carrying a version column and a deleted flag, and background merges collapse duplicates. Correct results before a merge require FINAL at query time. Consumers must tolerate duplicate events after restarts, and deleted rows are only purged when clean_deleted_rows is set to Always, a setting with a known bug as of 23.5. The post also compares pull-based and push-based CDC and explains why a Kafka queue protects the Postgres WAL from growing when ClickHouse is unavailable.

  • How we migrated a live routing system using AI-assisted refactoring

    Datadog Engineering mediumAdept

    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. PostgreSQL backs the write path and DuckDB the in-memory read path. The KV model forced the app to rebuild relationships in-process and hit transaction size limits, and simply swapping in Postgres with the same access patterns was estimated at 45 minutes for the heaviest operations. The team designed the schema by hand, then used Claude and Cursor in a tightly scoped, test-driven loop: map the intent of the old code into markdown docs, stub one Controller method, feed in the failing end-to-end tests, and iterate until they pass. A blue/green validator compared live responses every 30 seconds for weeks before cutover. The models produced correct but suboptimal SQL, so batching, UNNEST and CTE optimizations needed human input, and broad prompts performed poorly. The project went from design to production in about 3 months.

  • How we migrate TBs from Heroku without logical replication

    PlanetScale mediumAdept

    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. Version 2.0 fixes failures seen on large migrations. Bucardo's single-transaction initial copy restarted from zero after any interruption, so the migrator now drops secondary indexes before the copy and rebuilds them in parallel afterwards, raising throughput from about 60 to nearly 300 GB/h. It also disables transaction_timeout on Bucardo's connections, sets TCP keepalives so silently dropped long-lived connections fail within about a minute, and tunes host TCP buffers. A discovery CLI and the Liftoff assessment flag tables without primary keys, incompatible extensions and sizing before the migration starts.

The quest for software engineering knowledge.

Look:
Layout: