Skip to content

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

Datadog Engineering 20 min read Case study mediumAdept

Breaking up a monolith: How we’re unwinding a shared database at scale

Datadog is splitting its large shared Postgres database into independently owned instances through a three-phase plan: logical separation into per-domain private schemas with explicit ACLs, access reduction so only owning teams query their tables directly, and physical separation onto managed OrgStore instances. Domain boundaries came from clustering Database Monitoring query samples and validating them with 30+ teams. Inter-domain foreign keys were replaced with CDC or Postgres replication. A homegrown PG Proxy lets teams migrate at their own pace and makes cutover a dynamic config change, with write downtime under five seconds and reverse replication kept for rollback. The platform investments that made this feasible, the Rapid service framework, OrgStore and PG Proxy, are presented as prerequisites, and each phase has concrete progress metrics.

Related posts

  • The growing pains of database architecture

    Figma mediumAdept

    Facing ~3x annual database traffic growth and 65% peak CPU on a single Amazon RDS Postgres instance, Figma chose vertical partitioning (moving groups of tables to their own databases) over horizontal sharding, NewSQL, or self-hosting. Candidate tables were picked by measuring average active sessions from pg_stat_activity sampling and by tracing ActiveRecord queries into Snowflake to find isolated table groups. Migration used logical replication, with destination indexes dropped and rebuilt to cut initial copy from weeks to hours. Cutover went through a two-phase PgBouncer split, a brief pause with query cancellation, LSN-based sync checks, and reverse replication for rollback, keeping availability impact under a minute.

  • 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.

  • How to Keep Staging in Sync with Production in Postgres

    Neon mediumAdept

    Postgres staging environments drift from production, and the traditional fixes each fall short. pg_dump/pg_restore gives a clean copy but takes staging offline and runs for hours on large databases. Logical replication and AWS DMS keep rows in sync but not schema or configuration, and they add load to production. All three copy PII as-is. Database branching with copy-on-write storage, as in Neon, makes staging an instantly resettable branch of production, and an intermediate anonymized branch masks sensitive columns before staging and dev branches are derived from it.

  • Promoting Postgres Changes Safely From Multiple Environments to Production

    Neon mediumAdept

    A snapshot-based workflow for promoting Postgres schema and data changes uses two isolated root branches, prod and dev, linked only through Neon snapshots. Features and previews live on short-lived child branches, and validated changes are applied back to dev with migrations. Promotion means snapshotting prod for rollback and then restoring a dev snapshot onto prod. Endpoints stay the same and connections drop only for milliseconds, but any prod writes made after the snapshot are lost, so production must be read-only or reconciled at the application level. Rollback and dev refresh use the same restore operation, and costs stay manageable through logical-size billing, snapshot retention policies and branch TTLs.

  • Why Your Staging Database Never Matches Production

    Neon mediumAdept

    Staging databases drift from production continuously in three ways: data drift (stale dumps, sequence values that diverge so the same ID points to different records), schema drift (hotfixes, skipped migrations, mismatched indexes and extensions causing query plan divergence), and transformation drift (anonymization that breaks uniqueness, referential integrity and determinism). Scheduled pg_dump refreshes only cap staleness while adding lock windows and slow restores at scale, and logical replication doesn't carry DDL. The proposed fix is ephemeral copy-on-write database branches created at test time, inheriting production schema, data and sequences, with optional per-column masking, as offered by Neon.

The quest for software engineering knowledge.

Look:
Layout: