BeCuriouzLearn something new every day
How do you swap a database holding trillions of live messages?
💡 You migrate a live database by writing to both stores at once, then backfilling history until they converge — never by copying a moving target in one pass.
In 2022 Discord moved trillions of messages off Cassandra onto ScyllaDB — while the app kept running. You can't just copy a live database: the moment you finish, millions of new messages have already arrived and your copy is stale. So how do you migrate data that never stops changing?
The trick is dual writing. Before copying anything, the app starts writing every new message to both the old and the new database at once. Now the new store is always current for fresh traffic. Meanwhile a separate backfill job walks through the mountain of historical data and copies it across. When the backfill catches up, the two databases are in sync and you can cut over.
The last twist is speed. Discord's first migrator would have taken three months. By parallelizing the copy across the database's key ranges, they pushed it to 3.2 million messages per second and finished in just nine days — with users none the wiser.