14 Mar

ABN Techweek – How Discord Stores Trillions Of Messages?

ABN Tech Week trains engineers on the most important issues in building highly scalable software systems. The topic today is: How Discord Stores Trillions Of Messages?

HOW DISCORD STORES TRILLIONS OF MESSAGES

THE DIAGRAM BELOW SHOWS THE EVOLUTION OF MESSAGE STORAGE AT DISCORD:

MONGODB ➡️ CASSANDRA ➡️ SCYLLADB

IN 2015, THE FIRST VERSION OF DISCORD WAS BUILT ON TOP OF A SINGLE MONGODB REPLICA. AROUND NOV 2015, MONGODB STORED 100 MILLION MESSAGES AND THE RAM COULDN’T HOLD THE DATA AND INDEX ANY LONGER. THE LATENCY BECAME UNPREDICTABLE. MESSAGE STORAGE NEEDS TO BE MOVED TO ANOTHER DATABASE. CASSANDRA WAS CHOSEN.

IN 2017, DISCORD HAD 12 CASSANDRA NODES AND STORED BILLIONS OF MESSAGES.

AT THE BEGINNING OF 2022, IT HAD 177 NODES WITH TRILLIONS OF MESSAGES. AT THIS POINT, LATENCY WAS UNPREDICTABLE, AND MAINTENANCE OPERATIONS BECAME TOO EXPENSIVE TO RUN.

THEN COME SCYLLADB.

IN 2015, THE FIRST VERSION OF DISCORD WAS BUILT ON TOP OF A SINGLE MONGODB REPLICA. AROUND NOV 2015, MONGODB STORED 100 MILLION MESSAGES AND THE RAM COULDN’T HOLD THE DATA AND INDEX ANY LONGER. THE LATENCY BECAME UNPREDICTABLE. MESSAGE STORAGE NEEDS TO BE MOVED TO ANOTHER DATABASE. CASSANDRA WAS CHOSEN.

IN 2017, DISCORD HAD 12 CASSANDRA NODES AND STORED BILLIONS OF MESSAGES.

AT THE BEGINNING OF 2022, IT HAD 177 NODES WITH TRILLIONS OF MESSAGES. AT THIS POINT, LATENCY WAS UNPREDICTABLE, AND MAINTENANCE OPERATIONS BECAME TOO EXPENSIVE TO RUN.

THERE ARE SEVERAL REASONS FOR THE ISSUE:

– CASSANDRA USES THE LSM TREE FOR THE INTERNAL DATA STRUCTURE. THE READS ARE MORE EXPENSIVE THAN THE WRITES. THERE CAN BE MANY CONCURRENT READS ON A SERVER WITH HUNDREDS OF USERS, RESULTING IN HOTSPOTS.

– MAINTAINING CLUSTERS, SUCH AS COMPACTING SSTABLES, IMPACTS PERFORMANCE.

– GARBAGE COLLECTION PAUSES WOULD CAUSE SIGNIFICANT LATENCY SPIKES

SCYLLADB IS CASSANDRA COMPATIBLE DATABASE WRITTEN IN C++. DISCORD REDESIGNED ITS ARCHITECTURE TO HAVE A MONOLITHIC API, A DATA SERVICE WRITTEN IN RUST, AND SCYLLADB-BASED STORAGE.

THE P99 READ LATENCY IN SCYLLADB IS 15MS COMPARED TO 40-125MS IN CASSANDRA. THE P99 WRITE LATENCY IS 5MS COMPARED TO 5-70MS IN CASSANDRA.

AbnAsia.org Software. Faster. Better. More Reliable. +84945924877 (Asia# Mobile, WhatsApp, Telegram, Viber, Zalo); +16699996606 (US# Mobile, WhatsApp, Telegram) [email protected]

Call Now Button