Why discord switched from Go to Rust?
HTML-код
- Опубликовано: 2 авг 2024
- In this video, we learn why discord had to switch from Go to rust for one of its services. Along the way, we also learn how Garbage collection in Go works and what the cost of the abstraction Go provides us. We go over a case where rust became a better choice than Go in this competition of Go Vs Rust.
Original Blog: / discord
Background: www.freepik.com/premium-vecto...
#go #rust #discord
this showed up in my suggestions. i actually worked on this at discord. this blog post is a bit old. the garbage collection issue was a big one, but in retrospect, assuming the gc issues did not exist, rust is simply a better language, better at writing complicated thread safe services, of which we have many. we've been breaking out our python monolith into rust microservices for our core models and flows (read states, messaging, search, authentication, rate limiting, snowflakes, etc...). all of these things are super sensitive to runtime performance, and quite intricate in their function. rust allows us to write safe, maintainable, concurrent code that represents complicated programs in ways that go offers no equal. the garbage collector in go is probably better now, but the language is still very limited, and will eventually work against you in larger projects. you can't make as succinct abstractions in go, compared to rust, thanks to rust's more advanced type system, and novel ownership system.
Thanks for the insight Jake!! Great work on building such great stuff at Discord.
Also thanks for building great stuff so that freeloaders like me can make content out of it. 😜
reading the comments, i think that many people assume that the read states service was some complicated system that was a complex rewrite. it was not. it originally started as a thing that ran on redis with a few lua scripts that controlled state changes. this worked really well, but would not scale in the long run. we decided to rewrite that in go, which didn't take too long, and mostly worked. but rust was coming out, and we wanted to try it out as well, as an exploratory project. if it did not perform better, or the code wasn't cleaner, we would throw it away. rewriting it in rust, wasn't too difficult, but required a lot of other scaffolding, since we had our own rpc/service discovery system that we needed to rewrite in rust too. nowadays we just use a mix of grpc w/enovy and our own service discovery system as well.
anyways, we tried this thing out in rust, really vibed with the language, and have used it in a bunch of other places. we did not continue our adoption of go, after this. deciding to invest our efforts instead in building rust skills and a core set of libraries in rust to power our services. we've shifted and lifted critical functionality to rust services, with zero user-facing impact, and have even seen a great amount of stability improvements thanks to the architectural improvements we were able to make in the process, and the rock solid performance and reliability of programs you write in rust.
Pinning this comment so everyone gets some more insight on the topic.
Hey Jake, thanks for your work!
Why did you opt out of just using C++ instead?
@@Asylum_M I would guess better DX and ease of managing memory. You write in a high level with near C++ preformance.
Absolutely love the short dive into architecture and everyday tradeoffs of engineering.
Feels refreshing compared to tons of beginner content and hour long videos.
Thanks!! ❤️
Saw this video in my recommended feed - absolutely fantastic explanation, you did an amazing job breaking everything down into easy-to-understand chunks. Looking forwards to more videos like this!
Thanks!! Will keep making more videos like this. This particular video jst blew up 😅
I love how you explain it, it's like listening to my favorite teacher, very interesting, keep up your amazing work!
Thanks! This means a lot.
I had exactly the same thought! This video just popped up in my recommendations and it did not fail to deliver!
I really like the format of these videos, thanks for the insightful information! This channel is way too underrated. Keep up the good work!
Thanks!!
Love the changes you have made in your videos!! Keep em coming 😎
🤓❤️
I've heard about Discord moving a small part of their codebase to Rust. As a new software dev, I assumed it might just be a little to much for me to understand the details of such a decision. However, your video has done justice to the topic. Thanks a lot!!!
Thankyou!! Super glad i could help ! ❤️
Such a concise, well-explained walkthrough of a pretty complex engineering problem. Just earned a sub!
Thanks! ❤️
Wow, very succinct and insightful video. Thanks a lot for making this, it cleared some of the questions I had relating to GO's gc and rust's ownership idea in general. Thanks a ton!
Thanks!
this video showed up in my suggestions and i decided to watch it even tho i know nothing about Go and Rust. and yet i could understand everything (well, 95% of things i guess) about the cache, GC, CPU spikes and the reason behind their change from Go to Rust. i would like to thank you for this content and this very well done explanation that lead me, a guy who knew nothing about this matter, a little bit more taught about it. keep up your work!
Thanks! Glad I could help
what a way to explain it, crystal clear and on point, you just got yourself a new subscriber 👍
Thanks!! Means a lot ❤️
Explanation is AMAZING! Instantly subscribed 🙂
Thanks!! Means a lot ❤️
What an insightful and thorough breakdown of everything. Amazing analysis! +1 Sub
Edit: Also what an example of trade offs, A company or a Software Engineer, has to make in order to achieve the goal!
Thanks!
Amazing. Detailed yet concise and easy to understand.
Thanks! ❤️
Hats off my friend. Just found your channel. This is how technical videos should be done.
Welcome aboard!
didn't even listen and just turned the captions on. reading through it i knew you are very articulate. subbed!
Thanks!
Such a great explanation, very detailed and understandable
Thankyou!
Connect with me on LinkedIn : www.linkedin.com/in/ankush-chatterjee-53695911b
(I know LinkedIn is cringe, but its good for DMs)
pajeet my son
Wow, I really enjoyed the explanation in this video, three cheers! You've got yourself a new subscriber.
Thankyou! Means a lot ❤️
Explanations are pretty clear, as well as drawings! Thank you very much, I understand all!
Thanks! Glad I could help
amazing video brother!!! many thanks for sharing, your explanation and slides are AMAZING!
plz more videos like that!!
Thanks!! ❤️❤️❤️
You are entertaining, keep producing videos!
Thanks!! I will keep producing videos and making myself better for sure.
Great video, I'm curious as to what requirements discord had for which they had to write a custom cache service and not use something like redis
Amazing explanation for both the garbage collection and cache usage for discord.
You got a subscriber
Thanks!!
Very insightful, Thank you!
Thanks for watching!
Rust's ownership and borrowing pretty much under the hood of compiler (rustc) and a the user. Additional performance benefits Rust gets from LLVM which is used as the backend of Rust compiler. Though I'd say Rust is a bit more smart tool, by using its own generated IR code and then re-optimize to generate LLVM IR code and now LLVM will optimize that IR code to generate the output binary. It is where Rust also gets a plus point.
I loved your explanation, I subbed! :)
Love the vid, really nice insight!
Thanks!
what a great channel. more complex videos like this
Thanks!
Very good explanation on GC!
Excellent video. Well balanced analysis of Go and Rust. In this instance I can see why they went with rust in this case.
Thanks! Means a lot 🤓
First time on your channel
Loved the way you explained everything
Btw 2x is the best
Thanks! Hope come back again.. there are some other cool videos on this channel too u can watch in 2x 😉
Great video! Awesome coverage of Go's GC. I can't recall, does every mark sweep count as a "stop the world" event?
STW does not happen during mark/sweep, but there is one short stop before mark phase and one short stop after mark phase
I mean they could've updated the go's gc algo. But yeah that is an overhead and they might run into further issues which will be harder to spot. So i guess switching to rust would be a better decision
I'm really curious as to how exactly this service is used and deployed by Discord. The average response time metric shows about 2ms latency which is very impressive.
Dude awesome video, so can we say go uses topology sorting to remove seen msgs?
this video feels... wholesome
Agreed.. he's like the one helpful guy who's always ready to help
Thanks ❤️❤️
Your talking and explanation so interesting, really. Keep it up
Thanks!
Loved this video, thank you!
Thanks!
Subbed hoping to see more rust,go videos
Sure! They will keep coming (along with other cool engineering stuff) 🤓
This was very informative.
I would love the switch their frontend from electron to another thing .
I like the way how you represent the information 👍
Thanks! Means a lot ❤️
For someone with an asian background, you speak English really well and in an understandable way. Well done. Good vid on how gc can effect runtime performance, really interesting to see the concept of rust memory management be explained so easily.
Thanks man!! ❤️❤️❤️
Great lecture, thanks! :)
Thankyou..!
Although, it's not a lecture, just a guy sharing what he learnt.
Amazing explanation 💙
People say in the comment section that go is easier. If you need easier language and performance doesn't matter, why don't you choose python.
Just subbed for the interesting content!
Thanks man.. hope i can be your dealer for cool engineering content 🤓
So... why GO doesn't use incremental GC?
Great explanation understood everything!
Thanks... Glad I could help
such an amazing explanation
Amazing video. Very underated video
Thanks.... Do share it with your peers!
But I read somewhere that, there is an option to disable gc. Any comments on this? Thanks
Very good video! Would be nice for the volume to be a big higher :p, greetings!
Yep... You are right, have to upgrade this mic at some point. Increasing the gain on this mic introduces a lot of noise
It would be great to use more contrast colors to draw chart. For example, black and white on gray background. Or red and green
Thanks for the feedback, I will keep this in mind.
Well explained thankyou!
Thanks!
It felt like bubble sort with go's garbage collection
Great video. Quick question from a beginner: can’t you turn off GC in a Go environment variable?
thats literally shooting yourself in the foot.
btw ditch go
In almost all situations turning off GC is not a good idea. There will always be some objects which will need cleaning up and that would keep taking up memory over some period of time.
Hope this explanation helps!! 🤓
In many scripting languages you can disable GC (or switch it to manual mode). But then raises the question: why use that language in the first place? GC is still present in memory but does nothing. So isn't it better just to use a language without GC at that point?
keep these video coming
Thanks!! I will keep 'em coming
Great explanation of GC. If only it could clean itself! 😉
Great video!
Thankyou ❤️
This is was before GOGC off and limit correct?
great video thanks a lot
You're a good teacher
TLDR: answer to title is: GC Spikes
- everything else just re-explains what you should already know
- it should be titled: What is GC, why does it have spikes, and how does Rust do away without GC
Could you please say what tool you use for the presentation
Excalidraw
Great video 😄
Thanks!!
Why didn't they just change the GC algorithm? Or tune the current one? I've been programming in Java for a long time. From time to time we run into issues with GC like this. It easily solved by switching to a proper GC algorithm for the given scenario and tuning it. Maybe Go doesn't have the diversity in GC algorithms yet like e.g. Java does?
Because Rust doesn't use a GC, Rust handles all the memory management and safety during compile time using the ownership and borrow checker mechanism. While a GC is included into the binary itself to provide memory management during runtime, which results in a larger binary & less predictable memory management.
@@noon8988 Yes, but it would've been much easier to change/tune the GC than rewriting the entire application in a different language.
@@pompiuses I mean no matter what changes you make to the GC, there will always be some overhead. I think that rewriting the service in Rust was worth it for them.
you are right. Java Garbage Collector has taken time to improve. It provides multiple algorithms suitable for different cases.
Go runtime is still getting better. Team Go has done a lot since then.
The Future of runtime Languages. Because runtimes are getting better, processors are getting cheaper year after year. The only problem that has no solution is programmer's time. A language that does not care about programmer's time has no place in the future, despite the propaganda
Why was rust chosen over the likes of C or C++ if performance was the end goal?
good explanation!
Thanks!
This is right usage of Rust. Performance critical service = Write in Rust
The garbage is the main probs for memory address to go wrong we need to use polars a new library for python check it out it's awesome✌️
Nice explanation and great voice
Thanks!!!
great video
Great explanation.
Thanks!
@@core_dump would love to see more videos like this.
Good information ❤
Nice explanation
Thanks!!
Amazing explanation.
Thanks!
Entertaining and intriguing
Thanks!
You could give some reference to the sources for some of the info you share.
Thanks for the feedback, would be better to share more sources.
very interesting
Glad you think so!
wow very good video thank you
Thankyou for watching!
Could be this intentional by Google to maximize your bill in their cloud x)?
Joking xD
A good programming channel, thats indian. 🤟
That's all fine and dandy, but seriously...How often should I be cleaning my ducts?
have you ever worked with rust?
They switched? No wonder its smoother now
Those people who complained shouldn’t have used Go because most of the explanations I see are either due to usage of older versions of Go where the GC wasn’t as optimized as currently, or such applications are just better off handling memory management themselves.
Yeah, the blog post is 2yr old.. so things might have changed.
Now they just need to fix their interface
Blanzingly Kitten
Huh??
Huh, why might they have been having performance issues…
1:37 Oh. Go’s garbage collector.
Better question is why does anyone use Go?
if there is no Rust language how would they resolve the issue ? so if for every issue we face in the future, we need to introduce new language?
yay
opti mi-zation brother
oh I always thought discord was some kind of javascript in electron cause how bad it is lol :) thanks for the video.
you're confusing client code with backend code, client is indeed javascript inside of electron
@@im_tem ah okie :)
God like
Hopefully they can migrate from electron later
Haha, i can see in the comments...not many electron fans 😅
To GC or Not, is the question ! No easy answers...
Ah... Title for a new video. 😂
I thought Discord has used Elixir..
Yes, you are right. For most services they use Elixir.
@@core_dump So Discord used Elixir, Go & Also Rust ? I do not know at all..
@@jefriaritambunan2796 yes, they have used all three
With respect to Rust being complicated - I came across this brilliant video, that disagrees. ruclips.net/video/CJtvnepMVAU/видео.html
. The comment from Jake H was also quite a follow-up. Putting things in over all perspective. Great video you've put. Thanks.
Yeah, I perhaps need to spend more time with Rust to get at ease with it.
Have watched the video u linked, great video, highly recommended