---
title: "The fellowship of the forgotten"
description: "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."
url: "https://swe.quest/articles/the-fellowship-of-the-forgotten-ac797a95f97a91ed"
canonical: "https://engineering.klarna.com/the-fellowship-of-the-forgotten-d341045a6123"
source: "Klarna Engineering"
published: "2025-02-26"
difficulty: "medium"
kind: "Case study"
reading_minutes: 18
tags: ["postgres","elixir-erlang","replication","schema-migrations","databases"]
---

# The fellowship of the forgotten

A post on [Klarna Engineering](https://swe.quest/sources/klarna.md), published 2025-02-26, 18 min read, Case study. Original: [https://engineering.klarna.com/the-fellowship-of-the-forgotten-d341045a6123](https://engineering.klarna.com/the-fellowship-of-the-forgotten-d341045a6123)

## Summary

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.

Written by swe.quest, not by the author.

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

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Elixir & Erlang](https://swe.quest/tags/elixir-erlang.md) (Languages)
- [Replication](https://swe.quest/tags/replication.md) (Distributed systems)
- [Schema migrations](https://swe.quest/tags/schema-migrations.md) (Data & databases)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)

## Prerequisites

- Erlang/OTP basics ([easy posts on Elixir & Erlang](https://swe.quest/tags/elixir-erlang.md?difficulty=easy))
- leader-follower replication ([easy posts on Replication](https://swe.quest/tags/replication.md?difficulty=easy))
- Postgres transactions ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))

## Keywords

Mnesia, PostgreSQL, Erlang, KRED, Klarna, mnesia\_eleveldb, epgsql, LevelDB

## Related posts

- [Breaking up a monolith: How we’re unwinding a shared database at scale](https://swe.quest/articles/breaking-up-a-monolith-how-we-re-unwinding-a-shared-database-at-scale-4f34dacf50e040a9.md): Datadog Engineering · 2025-06-17 · Medium · 20 min read · PostgreSQL, Schema migrations, Refactoring & migrations, Microservices, Replication
  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.
- [How we migrated Clera’s 500 GB production database to ClickHouse Managed Postgres overnight](https://swe.quest/articles/how-we-migrated-clera-s-500-gb-production-database-to-clickhouse-managed-f4ed327a88d71cd7.md): ClickHouse · 2026-10-08 · Medium · 8 min read · PostgreSQL, Databases, Performance engineering, Schema migrations, Storage systems
  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.
- [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.
- [Making large Postgres migrations practical: 1TB in 2 hours with PeerDB](https://swe.quest/articles/making-large-postgres-migrations-practical-1tb-in-2-hours-with-peerdb-cc7872fe91229eda.md): ClickHouse · 2026-02-19 · Medium · 13 min read · PostgreSQL, Replication, Schema migrations, Performance engineering, Data pipelines
  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.
- [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.

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)
