Skip to content

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

Klarna Engineering 18 min read Case study mediumAdept

The fellowship of the forgotten

Klarna migrated KRED, a 2004-era Erlang servicing system backed by a ~15 TB Mnesia database (1.3 TB in memory) replicated across 7 nodes, to Postgres with zero downtime. The approach kept the internal kdb wrapper as a compatibility layer, inferred column types by scanning every record and widening types (including normalizing Erlang's inconsistent null representations), and built bidirectional Mnesia↔Postgres replication so leadership could switch back and forth. A pipelined, batched replication worker with high-throughput and low-latency modes and Erlang-side record locks kept a Postgres follower within about 20 ms of the leader. The plan was broken into small epics, each valuable on its own, with a single point of no return at the end.

Related posts

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

    Datadog Engineering mediumAdept

    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.

  • How we migrated Clera’s 500 GB production database to ClickHouse Managed Postgres overnight

    ClickHouse mediumAdept

    Clera moved a 500 GB, 500+ table production Postgres database from the EU to the US overnight onto ClickHouse Managed Postgres, with production traffic still running, using two parallel ClickPipes pipelines. The vendor choice followed a replay of their real workload (hot reads, point lookups, background analytics) on Supabase, Neon, PlanetScale and ClickHouse, plus sysbench TPC-C at 8–128 threads. Local NVMe storage beat network-attached storage, with 16–42% higher TPS than PlanetScale out of the box, and CPU fell from days at 100% to 10–20%. The hard parts were extension portability, restoring triggers, rebuilding indexes, resequencing tables, and doing parity checks before cutover.

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

  • Making large Postgres migrations practical: 1TB in 2 hours with PeerDB

    ClickHouse mediumAdept

    PeerDB migrated a 1TB, 3.6-billion-row Postgres table in about 1 hour 50 minutes with 8 threads, compared with 8 hours 40 minutes for native logical replication and 17 hours for pg_dump/pg_restore. The speedup comes from parallel snapshotting. A consistent snapshot is exported via pg_export_snapshot, the table is split into CTID ranges, and each range is streamed with binary COPY, with per-partition retries and progress visibility. Past a certain level of parallelism the source RDS network bandwidth becomes the limit, so 16 threads were no faster than 8 at 1TB. For CDC, PeerDB keeps the replication slot consumed independently of destination writes. It also reconstructs unchanged TOAST columns from batch caches and MERGE against the target, so REPLICA IDENTITY FULL is not needed.

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

The quest for software engineering knowledge.

Look:
Layout: