TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why Discord is switching from Go to Rust (2020)

232 pointsby harporoederabout 4 years ago

32 comments

reikonomushaabout 4 years ago
Meta-comment, and I’m <i>not</i> claiming this is what’s true about Discord.<p>Every time I see a company post about how they’re changing programming languages, I tend to believe it <i>actually</i> happened because engineers with enough political clout decided they wanted everybody to change to their preferred language, not truly because of technical reasons, but because they just wanted to be paid to write in a cool language. But, of course, you’d be lambasted by your colleagues if you <i>didn’t</i> provide technical reasons, so you go and hunt for technical reasons that seem insurmountable and build a case for it, turning a blind eye to perhaps less exciting solutions that don’t require a programming language change.<p>(It’s sort of like how a cop in America can find you doing something illegal in any circumstance if they look hard enough. Except in this case, it’s a matter of finding technical deficiencies.)<p>This strategy highly depends on clout though, which is why I think technical arguments are frequently really a façade. If, say, a junior programmer doesn’t have clout, even presenting an equivalent technical argument won’t lead to a change in programming language, especially if it’s the senior’s favorite. I’m sorry to say, but most tech organizations aren’t meritocratic or egalitarian in this way (and perhaps they shouldn’t be).<p>As it pertains to the article—which again I don’t claim is all “fake” politicking (I don’t know anything about or anyone at Discord)—they mostly ripped on garbage collection. They specifically talked about how GC was bad because their LRU cache had to be scanned, which was part of why they observed spikes in their metrics. I wonder why they didn’t try doing things like putting the LRU cache into foreign, unmanaged memory to avoid garbage collecting it. Easier said than done, but why not?<p>I think using <i>any</i> language with any serious and large project will find deficiencies in the language. At some point in a product lifecycle it’s more profitable to just work with and ameliorate those deficiencies than do rewrites where the <i>new</i> deficiencies will be completely unknown.
评论 #26228741 未加载
评论 #26230229 未加载
评论 #26229867 未加载
评论 #26231671 未加载
评论 #26230469 未加载
评论 #26228660 未加载
评论 #26228897 未加载
评论 #26229396 未加载
评论 #26228858 未加载
评论 #26228986 未加载
评论 #26228722 未加载
评论 #26230537 未加载
jjjeii3about 4 years ago
GO promised to be very fast, but if you check the actual benchmarks:<p><a href="https:&#x2F;&#x2F;www.techempower.com&#x2F;benchmarks&#x2F;#section=test&amp;runid=8ca46892-e46c-4088-9443-05722ad6f7fb&amp;hw=ph&amp;test=plaintext" rel="nofollow">https:&#x2F;&#x2F;www.techempower.com&#x2F;benchmarks&#x2F;#section=test&amp;runid=8...</a><p>High-level C# (asp.net) is almost twice as fast as GO in the benchmark... Rust is also in the top 3.<p>So, why should I use GO instead of C#, if ASP.NET&#x2F;C# is so blazing fast and requires a lot less lines of code to achieve the same? -&gt; It makes absolutely sense to switch to C# or Rust.
评论 #26228399 未加载
评论 #26228452 未加载
评论 #26229470 未加载
评论 #26228460 未加载
评论 #26228638 未加载
评论 #26228676 未加载
评论 #26228556 未加载
评论 #26228735 未加载
评论 #26228438 未加载
评论 #26228550 未加载
评论 #26228298 未加载
steveklabnikabout 4 years ago
This was covered a year ago, and is literally the most popular post for &quot;Rust&quot; ever on this site <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22238335" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22238335</a>
评论 #26233389 未加载
评论 #26228259 未加载
Sikulabout 4 years ago
Original author here. Cool to see it posted again.<p>We&#x27;re still using and investing in rust at Discord. For example, in the past year we successfully pulled part of the core messaging system out of python and into a rust service. Rust has been a boon for developer productivity and correctness of code.<p>We&#x27;ve also been very happy with the way the rust ecosystem is evolving and the amount of adoption the language has seen.<p>I&#x27;m happy to answer questions here.<p>P.S. We&#x27;re still growing and hiring (including remotely). You can find my email in my profile.
评论 #26232327 未加载
评论 #26229460 未加载
评论 #26234108 未加载
评论 #26235173 未加载
评论 #26229899 未加载
tschellenbachabout 4 years ago
2021 will be about them switching back. All jokes aside, it&#x27;s really common for engineers to randomly switch between solutions incurring huge costs for the companies they work for. Often as it is in this case with no gain for the company, other than some resume building for the involved team members. We use Go here at Stream and power activity feeds and chat for a billion end users. Works perfectly.<p>Cockroach also wrote about GC optimization: <a href="https:&#x2F;&#x2F;www.cockroachlabs.com&#x2F;blog&#x2F;how-to-optimize-garbage-collection-in-go&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.cockroachlabs.com&#x2F;blog&#x2F;how-to-optimize-garbage-c...</a><p>For caching specifically there is this library as well: <a href="https:&#x2F;&#x2F;dgraph.io&#x2F;blog&#x2F;post&#x2F;introducing-ristretto-high-perf-go-cache&#x2F;" rel="nofollow">https:&#x2F;&#x2F;dgraph.io&#x2F;blog&#x2F;post&#x2F;introducing-ristretto-high-perf-...</a><p>Nothing wrong with Rust, exciting project, but personally think Go is better for building performant micro services like this. Rust seems more suited for building browsers, drivers etc. Rust&#x27;s performance is slightly better, but it&#x27;s not as refined around go routines and developer productivity.<p>Edit: On the other hand, Discord could have made the very valid decision that they have an easier time recruiting for Rust than for Go. Which is in fact a good reason to switch.
评论 #26228798 未加载
评论 #26228663 未加载
评论 #26229117 未加载
评论 #26236479 未加载
评论 #26230641 未加载
cforsabout 4 years ago
Sounds like Discord was running gigantic in memory Go caches.<p>Not that it&#x27;s the wrong approach, but this is a very real-time system-y problem that Rust is designed for. So I understand why this made sense.<p>Obviously rewriting in Rust worked for them, but I&#x27;m curious if they tried the Ballast[0] approach, along with smaller cache&#x27;s per service. That would make the GC scan on the cache smaller while still avoiding some of the Go startup heap issues. I&#x27;m not sure if the target heap size ever was accepted by the Go team, but it may have been easier than a full rewrite.<p>[0] <a href="https:&#x2F;&#x2F;blog.twitch.tv&#x2F;en&#x2F;2019&#x2F;04&#x2F;10&#x2F;go-memory-ballast-how-i-learnt-to-stop-worrying-and-love-the-heap-26c2462549a2&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.twitch.tv&#x2F;en&#x2F;2019&#x2F;04&#x2F;10&#x2F;go-memory-ballast-how-i...</a>
评论 #26228665 未加载
评论 #26228687 未加载
评论 #26228780 未加载
AlchemistCampabout 4 years ago
In its early days, this forum was full of excited young devs who had read PG&#x27;s old essays and we&#x27;re actively <i>looking</i> for technologies that would give them a competitive edge.<p>Now, it&#x27;s completely the opposite.<p>Now, when a company successfully leverages technologies as a competitive edge and becomes a multi-billion dollar success, the thread is dominated by stodgy criticism for not picking the absolute most mainstream technologies possible.
评论 #26233009 未加载
rvzabout 4 years ago
&gt; When starting a new project or software component, we consider using Rust. Of course, we only use it where it makes sense.<p>Big takeaway here for those who are married to their tools. Rust happens to be just another tool for this company, and it works well for them; where it makes sense of course.
评论 #26229461 未加载
评论 #26228563 未加载
评论 #26230712 未加载
评论 #26228177 未加载
CobsterLockabout 4 years ago
Off-topic: who is in charge of choosing colors for graphs? Being red-green colorblind, choosing blue and purple is makes it impossible for me to read the charts. I know its stylish, but every time i make a graph i choose very high contrast colors. Another point: is it just being color blind or do other people struggle in charts&#x2F;maps that have shades of a color? like different shades of blue represent different rates of covid deaths across a map. just curious if anyone else struggles with this
评论 #26228483 未加载
评论 #26228890 未加载
评论 #26229140 未加载
kbar13about 4 years ago
i&#x27;m curious if allocating a memory ballast would have helped discord in this case?<p>a one line patch in main() with something like<p>ballast := make([]byte, 10&lt;&lt;30)<p>might help their GC spikes, since garbage collection would only trigger when the heap size reaches 20GB, at which point the heap will be reduced back down to 10GB or so.<p><a href="https:&#x2F;&#x2F;blog.twitch.tv&#x2F;en&#x2F;2019&#x2F;04&#x2F;10&#x2F;go-memory-ballast-how-i-learnt-to-stop-worrying-and-love-the-heap-26c2462549a2&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.twitch.tv&#x2F;en&#x2F;2019&#x2F;04&#x2F;10&#x2F;go-memory-ballast-how-i...</a>
评论 #26228596 未加载
评论 #26228865 未加载
mamcxabout 4 years ago
Switching languages is THE most efficient way to refactor a messy codebase.<p>The past color the idea that a language switch is a waste of time, because in the past the choice of languages was from <i>worse to bad</i> or for <i>same to same-ish</i>.<p>But MODERN languages have something that make this compelling: Actual good practiques baked in the language, as defaults.<p>---<p>So, if a codebase is in trouble you can:<p>- Try to refactor it with &quot;better&quot; idioms...<p>but if this is not the norm in the language&#x2F;ecosystem you depend in discipline, and that have proved to fail at scale.<p>- Change to &quot;shinny lang&quot; where do the right thing is the default...<p>And now if the developers try to do wrong, them will fight against the current.<p>---<p>Switch to Go is a great way to solve a project with concurrency issues: Go is good at that, and make a compelling case of build good concurrency apps. Similar if switch to Elixir&#x2F;Erlang.<p>The case of Rust is similar: it make the &quot;best&quot; practiques the <i>default</i>, and <i>very painful to do wrong</i> (and sometimes to do right, but this is not the focus here :) ).<p>So, a language switch is the ultimate clean up for a project.<p>I have done several in the past (I&#x27;m contractor) and let me tell you: Any codebase I get is in deeeeeep trouble.<p>The best results have been a language switch, when I move from &quot;bad&quot; to &quot;better&quot;. Just the fact the new language have something that is truly better make the move great.<p>Now, the opposite is true: If you are switching and NOT because the new language have that something that is truly in need or worse, is a language with the need of a LOT of discipline (like C, PHP, JS,...) then yeah, is doomed...
tbodtabout 4 years ago
I&#x27;ve never seen anyone look into just <i>why</i> Go forces a GC on 2 minute intervals. The code originally appeared in <a href="https:&#x2F;&#x2F;codereview.appspot.com&#x2F;5451057" rel="nofollow">https:&#x2F;&#x2F;codereview.appspot.com&#x2F;5451057</a> and there&#x27;s a bit of discussion on <a href="https:&#x2F;&#x2F;groups.google.com&#x2F;g&#x2F;golang-nuts&#x2F;c&#x2F;WBlJjT-zu7E" rel="nofollow">https:&#x2F;&#x2F;groups.google.com&#x2F;g&#x2F;golang-nuts&#x2F;c&#x2F;WBlJjT-zu7E</a>.<p>After reading this, I still don&#x27;t understand. But I find <a href="https:&#x2F;&#x2F;codereview.appspot.com&#x2F;5451057#msg38" rel="nofollow">https:&#x2F;&#x2F;codereview.appspot.com&#x2F;5451057#msg38</a> particularly entertaining: there was going to be an environment variable to control the interval, which might have allowed Discord to keep using Go, but Russ Cox shot it down.
geodelabout 4 years ago
Ah Discord, that provides electron based chat client. I am sure they can write efficient software when its their money.
评论 #26228841 未加载
sgtabout 4 years ago
I wouldn&#x27;t mind looking into Rust to eventually replace our Java and Python based stacks, but every time I look at it, I tend to give some thought to the difficulty of writing Rust as opposed to reading&#x2F;writing&#x2F;maintaining Java for an entire team. Frankly I&#x27;m worried that not all team members will become good Rust developers, and the codebase will develop serious rot over time. Any experiences with this?
评论 #26230676 未加载
评论 #26228762 未加载
评论 #26229816 未加载
jeffbeeabout 4 years ago
Feels like there might have been a middle ground short of a scratch rewrite. LRU caches are always suspect. LRU is pretty much the worst replacement policy you can choose. I wonder if a smaller cache with a better replacement policy (2Q, ARC, ...) would have solved this specific problem.<p>Another approach I&#x27;ve used with caches in Go is to just use a huge byte slice as the cache without any pointers, so the GC can ignore it.
评论 #26228609 未加载
swyxabout 4 years ago
&gt; Discord has never been afraid of embracing new technologies that look promising. For example, we were early adopters of Elixir, React, React Native, and Scylla. If a piece of technology is promising and gives us an advantage, we do not mind dealing with the inherent difficulties and instability of the bleeding edge. This is one of the ways we’ve quickly reached 250+ million users with less than 50 engineers.<p>this sounds like a recipe for disaster in every other company i have worked with. are Discord&#x27;s engineers just THAT good or is there something else going on here?
rufusroflpunchabout 4 years ago
These threads are always full of people criticizing these moves by companies. But nothing is gained of nothing is risked, right? Sometimes these things pay off, and we would never know without early adopters.
评论 #26233950 未加载
dangabout 4 years ago
Discussed at the time:<p><i>Why Discord is switching from Go to Rust</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22238335" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22238335</a> - Feb 2020 (640 comments)<p>also <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=23874336" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=23874336</a> - July 2020 (7 comments)
strangelove026about 4 years ago
I really enjoyed reading this article last time it was posted. I particularly like it because it shows evidence that current tooling wasn&#x27;t doing the job. I believe I remember seeing some comments on how Discord was on an old version of go that wasn&#x27;t receiving the benefit around gc collections, but we&#x27;ll never know if that would&#x27;ve been a solution.<p>That all said, I&#x27;ve noticed that people here are really off golang in favor of rust. I believe I sort of understand. I&#x27;ve recently switched from python to go at work, and I frequently bring up why I like it so much (caveat I&#x27;m overly enthusiastic about the things I like related to my work). But again, that all said, at the end of the day, both Python and golang will definitely get the job done.
silentsea90about 4 years ago
Incredibly brave of them to go with nightly build of Rust for async functionality. Not as in the weeds, but I would have been afraid of release being delayed forever and being stuck with the nightly release for a long time.
ufmaceabout 4 years ago
This post is getting a bit long in the tooth, at least regarding relatively new and fast-moving ecosystems like Go and Rust. I wonder if the Go team has determined any way to mitigate these long-running GC pauses for apps that don&#x27;t allocate often since this article was published.<p>I also wonder how well Rust has continued to work for Discord, if it&#x27;s been a problem to keep up with the rapid movement particularly in the async ecosystem in the last year or so.
评论 #26230169 未加载
lraeabout 4 years ago
(Feb 4, 2020)
KuhlMenschabout 4 years ago
Note: this is an account of using Rust in a single service<p>&gt; The service we switched from Go to Rust is the “Read States” service.<p>And the conclusion doesn&#x27;t indicate &quot;switching&quot;, but rather Rust is an &quot;option&quot; for Discord, and already used in the stack:<p>&gt; When starting a new project or software component, we consider using Rust. Of course, we only use it where it makes sense.
cheaprentalyetiabout 4 years ago
I didn&#x27;t know Discord was written in Go to begin with. I thought it was written using electron or something like that.
评论 #26228038 未加载
评论 #26227471 未加载
评论 #26228255 未加载
janckerabout 4 years ago
I think the response time &#x2F; latency to use Cassandra on the &quot;read state&quot; will be higher, and mind you cassandra is written in java (JVM) and has more garbage collection magic and latency than Go. From my point of view, it&#x27;s not the language, it&#x27;s your data store.
sandGorgonabout 4 years ago
How timely!<p><a href="https:&#x2F;&#x2F;stackoverflow.blog&#x2F;2021&#x2F;02&#x2F;22&#x2F;choosing-java-instead-of-c-for-low-latency-systems&#x2F;" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.blog&#x2F;2021&#x2F;02&#x2F;22&#x2F;choosing-java-instead-...</a><p>I do believe that there is nothing better tuned for performance vs developer productivity than the JVM.<p>The language semantics may be a question for personal distaste..but then you do have Kotlin (<a href="https:&#x2F;&#x2F;jooby.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jooby.io&#x2F;</a> ) which ranks fairly near the top on techempower benchmarks <a href="https:&#x2F;&#x2F;www.techempower.com&#x2F;benchmarks&#x2F;#section=data-r20&amp;hw=ph&amp;test=composite&amp;l=wqmbun-sf" rel="nofollow">https:&#x2F;&#x2F;www.techempower.com&#x2F;benchmarks&#x2F;#section=data-r20&amp;hw=...</a>
caffeineabout 4 years ago
Very misleading title makes it sound like they are rewriting all code wholesale - in fact it&#x27;s a targeted performance rewrite of a smallish component.
ibraheemdevabout 4 years ago
previous discussion: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22238335" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22238335</a>
hpenabout 4 years ago
Could something like Discord be written in Swift?
swileyabout 4 years ago
The main thing that bothers me about rust is that there is one complete implementation of the language (and one or two very incomplete implementations) and the singular complete one isn&#x27;t even self hosting.<p>Coming from scheme where everyone and their dog has an R5RS compatible REPL that&#x27;s pretty disturbing.
评论 #26229062 未加载
评论 #26229036 未加载
mraza007about 4 years ago
I&#x27;m just curious why can&#x27;t they use C or C++ instead of Rust
评论 #26228672 未加载
评论 #26228816 未加载
评论 #26228597 未加载
评论 #26228850 未加载
评论 #26229593 未加载
评论 #26228658 未加载
dvfjsdhgfvabout 4 years ago
In other words, they solved the problem they wouldn&#x27;t have if they had stuck to C in the first place.
评论 #26228349 未加载
评论 #26228585 未加载