News for hackers. Stuff that matters.
Re:How Discord stores trillions of messages by cynicalpeace on Saturday September 28, 2024 @08:41PM (#41683920)
Is there a fundamental reason you wouldn't use postgres for something like this? Scale certainly wouldn't be it.
Re:How Discord stores trillions of messages by cowthulhu on Saturday September 28, 2024 @08:47PM (#41683941)
I’m not sure if Postgres would have enough horizontal scaling to accommodate the insane volume of reads and writes. I would be super interested to be proven wrong though… anyone know of a cluster being run at that scale?
Re:How Discord stores trillions of messages by justnoise on Saturday September 28, 2024 @09:38PM (#41684162)
I'd guess that Discord's storage systems lean towards processing a lot more writes than reads. Postgres and other databases that use B-tree indexing are ideally suited for read heavy workloads. LSM based databases like Cassandra/Scylla are designed for write intensive workloads and have very good horizontal scaling properties built into the system.
Re:How Discord stores trillions of messages by Aeolun on Saturday September 28, 2024 @11:45PM (#41684748)
Would you actually have more writes than reads? Are messages read by fewer people than post them?
Re:How Discord stores trillions of messages by sadeshmukh on Sunday September 29, 2024 @12:06AM (#41684820)
When you send a message, afaik it sends to all people looking at it at the time. So there is no read when in a conversation, and maybe the reads are batched when reading multiple.
Re:How Discord stores trillions of messages by jhgg on Sunday September 29, 2024 @02:55AM (#41685410)
Read traffic is much higher than write traffic due to mobile clients needing to sync chat history more often as their sessions are much shorter lived. Also search queries execute 1 query per result. And don't forget people doing GDPR data dump requests. It adds up.
Re:How Discord stores trillions of messages by riku_iki on Saturday September 28, 2024 @09:18PM (#41684074)
> Scale certainly wouldn't be it.

vanilla postgres can't scale to such size, you need some sharding solution on top, which likely will be much harder to maintain than ScyllaDB..

Re:How Discord stores trillions of messages by ericvolp12 on Sunday September 29, 2024 @12:46AM (#41684982)
ScyllaDB scales horizontally on a shard-per-core architecture with a ballpark throughput of 12,500 Reads and 12,500 Writes per second per shard. If you're running Scylla across a total of 64 cores (maybe on 4 VMs with 16 vCPUs each), you can get up to 800k Reads 800k Writes per sec of throughput with P99 writes of <500us and p99 reads of <2ms.

You will not be able to get that performance out of Postgres and the write scaling will also be impossible on a non-sharded DB.

If you're a company like Discord and are running dozens (70-something?) of ScyllaDB nodes, likely each with 32 or 64 vCPUs, you've got capacity for 50M+ reads/writes per second across the cluster assuming your read/write workloads are evenly balanced across shards.

Re:How Discord stores trillions of messages by jhgg on Sunday September 29, 2024 @02:42AM (#41685364)
Fwiw the benchmarked numbers are for writing very small rows. When doing the messages migration, with no read traffic, and the cluster/compaction settings tuned for writes we only managed approx 3m inserts/sec while fully saturating the Scylla cluster.
Re:How Discord stores trillions of messages by menaerus on Sunday September 29, 2024 @10:06AM (#41687514)
How about per-node memory pressure, did it change in favor of Scylla? I ask because I would legitimately expect that GC-based system would have a larger pressure on the memory subsystem.
Re:How Discord stores trillions of messages by jhgg on Sunday September 29, 2024 @12:38PM (#41688519)
Scylla just eats all the ram it can with cache. So it's hard to say really. On Cassandra we allocated half the ram to the JVM which it gladly used up and left the other half to the OS for disk cache. On Scylla, since it uses direct io, there is no need for OS disk cache.
Re:How Discord stores trillions of messages by ericvolp12 on Sunday September 29, 2024 @07:52PM (#41691992)
Interesting, we've got to 5M+ reads/sec in realistic simulated benchmarks and ~2M reads/sec of real-world-throughput on our clusters that are <10 nodes (though really high density). I don't think I've pushed writes beyond 1M QPS in real-world or simulated loads yet though. Thankfully our partitioning schemes are super well distributed though and our rows are very small (generally 1-5k) so I don't think we'd have a problem hitting some big numbers.
Re:How Discord stores trillions of messages by ryanjshaw on Sunday September 29, 2024 @02:22AM (#41685311)
Okay but this is where I get confused. Why does Discord need a single database system when discord servers are independent, right?

And the volume of traffic per Discord server must be human-processable or what would the point be? A Discord server doing 800k writes per second makes no sense.

So why not a RDBMS per Discord server, and if you want to ship all that out to a warehouse for analytics you do that as a separate problem?

Or is it that spinning up a Postgres instance per Discord server ends up being significantly more expensive than these mega distributed database systems?

Re:How Discord stores trillions of messages by jhgg on Sunday September 29, 2024 @02:45AM (#41685376)
There are ballpark of a few hundred million discord servers... do you really want to run that many Postgres instances? And even so what do you do about DM/GDMs? Easier to just run one big mega cluster for messages.
Re:How Discord stores trillions of messages by ryanjshaw on Sunday September 29, 2024 @02:59AM (#41685426)
Okay so the latter then - economies of scale. Surprised to hear that few hundred million figure - I thought it'd be 1/10th of that at most! Wow.

Although I did expect there'd be a very long tail, and you might choose to host a bunch of servers on a single RDBMS, at that scale yeah it wouldn't solve much.

Thanks for coming back to me, appreciate it.

Re:How Discord stores trillions of messages by Drew_ on Sunday September 29, 2024 @12:21PM (#41688412)
Apple kind of does something like this with iCloud however their per user "databases" are only virtual:

https://news.ycombinator.com/item?id=39028672

Re:How Discord stores trillions of messages by riku_iki on Sunday September 29, 2024 @01:18PM (#41688783)
> You will not be able to get that performance out of Postgres

if writes are batched, I get this and higher performance from postgres. If 800k on 64 cores is Scylla's best result, it is not that impressive.

But also you probably mean writes/reads to indexed table, then it is another story.