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

Комментарии • 278

  • @jakeh5852
    @jakeh5852 Год назад +715

    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.

    • @core_dump
      @core_dump  Год назад +62

      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. 😜

    • @jakeh5852
      @jakeh5852 Год назад +121

      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.

    • @core_dump
      @core_dump  Год назад +43

      Pinning this comment so everyone gets some more insight on the topic.

    • @Asylum_M
      @Asylum_M Год назад +1

      Hey Jake, thanks for your work!
      Why did you opt out of just using C++ instead?

    • @IannoOfAlgodoo
      @IannoOfAlgodoo Год назад +6

      @@Asylum_M I would guess better DX and ease of managing memory. You write in a high level with near C++ preformance.

  • @mma93067
    @mma93067 Год назад +58

    Absolutely love the short dive into architecture and everyday tradeoffs of engineering.
    Feels refreshing compared to tons of beginner content and hour long videos.

  • @Roy-K
    @Roy-K Год назад +5

    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!

    • @core_dump
      @core_dump  Год назад

      Thanks!! Will keep making more videos like this. This particular video jst blew up 😅

  • @EjiDev
    @EjiDev Год назад +193

    I love how you explain it, it's like listening to my favorite teacher, very interesting, keep up your amazing work!

    • @core_dump
      @core_dump  Год назад +10

      Thanks! This means a lot.

    • @lix2146
      @lix2146 Год назад +5

      I had exactly the same thought! This video just popped up in my recommendations and it did not fail to deliver!

  • @huistelefoon5375
    @huistelefoon5375 Год назад +7

    I really like the format of these videos, thanks for the insightful information! This channel is way too underrated. Keep up the good work!

  • @shreyahehe
    @shreyahehe Год назад +29

    Love the changes you have made in your videos!! Keep em coming 😎

  • @seyeakintunde8225
    @seyeakintunde8225 Год назад +24

    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!!!

    • @core_dump
      @core_dump  Год назад +1

      Thankyou!! Super glad i could help ! ❤️

  • @tersamba9706
    @tersamba9706 Год назад +4

    Such a concise, well-explained walkthrough of a pretty complex engineering problem. Just earned a sub!

  • @pranavbadrinathan6693
    @pranavbadrinathan6693 Год назад +4

    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!

  • @guisaliba
    @guisaliba Год назад +2

    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!

    • @core_dump
      @core_dump  Год назад

      Thanks! Glad I could help

  • @jayjolupoi88891
    @jayjolupoi88891 Год назад +8

    what a way to explain it, crystal clear and on point, you just got yourself a new subscriber 👍

    • @core_dump
      @core_dump  Год назад +1

      Thanks!! Means a lot ❤️

  • @dera_ng
    @dera_ng Год назад +1

    Explanation is AMAZING! Instantly subscribed 🙂

    • @core_dump
      @core_dump  Год назад +1

      Thanks!! Means a lot ❤️

  • @fmkhandwala39
    @fmkhandwala39 Год назад +19

    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!

  • @SarkanyGergogaming
    @SarkanyGergogaming Год назад

    Amazing. Detailed yet concise and easy to understand.

  • @faisalhussain342
    @faisalhussain342 6 месяцев назад

    Hats off my friend. Just found your channel. This is how technical videos should be done.

    • @core_dump
      @core_dump  6 месяцев назад +1

      Welcome aboard!

  • @ValAllenSamonte
    @ValAllenSamonte Год назад

    didn't even listen and just turned the captions on. reading through it i knew you are very articulate. subbed!

  • @vfryhn2
    @vfryhn2 Год назад +6

    Such a great explanation, very detailed and understandable

  • @core_dump
    @core_dump  Год назад +12

    Connect with me on LinkedIn : www.linkedin.com/in/ankush-chatterjee-53695911b
    (I know LinkedIn is cringe, but its good for DMs)

  • @chrismuga
    @chrismuga Год назад

    Wow, I really enjoyed the explanation in this video, three cheers! You've got yourself a new subscriber.

    • @core_dump
      @core_dump  Год назад

      Thankyou! Means a lot ❤️

  • @myrem7635
    @myrem7635 Год назад

    Explanations are pretty clear, as well as drawings! Thank you very much, I understand all!

    • @core_dump
      @core_dump  Год назад

      Thanks! Glad I could help

  • @ibrahemtaha8177
    @ibrahemtaha8177 Год назад +1

    amazing video brother!!! many thanks for sharing, your explanation and slides are AMAZING!
    plz more videos like that!!

    • @core_dump
      @core_dump  Год назад +1

      Thanks!! ❤️❤️❤️

  • @ShoterOTP
    @ShoterOTP Год назад +11

    You are entertaining, keep producing videos!

    • @core_dump
      @core_dump  Год назад +1

      Thanks!! I will keep producing videos and making myself better for sure.

  • @ankurdubey8648
    @ankurdubey8648 Год назад +2

    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

  • @ajay.m6400
    @ajay.m6400 Год назад

    Amazing explanation for both the garbage collection and cache usage for discord.
    You got a subscriber

  • @szilagyimiklos4757
    @szilagyimiklos4757 Год назад +2

    Very insightful, Thank you!

  • @sofiaknyazeva
    @sofiaknyazeva Год назад

    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! :)

  • @timmyc2353
    @timmyc2353 Год назад

    Love the vid, really nice insight!

  • @elvispalace
    @elvispalace Год назад

    what a great channel. more complex videos like this

  • @wendellhatcher7011
    @wendellhatcher7011 Год назад

    Very good explanation on GC!

  • @ed6393
    @ed6393 Год назад +2

    Excellent video. Well balanced analysis of Go and Rust. In this instance I can see why they went with rust in this case.

    • @core_dump
      @core_dump  Год назад

      Thanks! Means a lot 🤓

  • @BABA-oi2cl
    @BABA-oi2cl Год назад +2

    First time on your channel
    Loved the way you explained everything
    Btw 2x is the best

    • @core_dump
      @core_dump  Год назад +1

      Thanks! Hope come back again.. there are some other cool videos on this channel too u can watch in 2x 😉

  • @n0kodoko143
    @n0kodoko143 Год назад +1

    Great video! Awesome coverage of Go's GC. I can't recall, does every mark sweep count as a "stop the world" event?

    • @punangai
      @punangai Год назад

      STW does not happen during mark/sweep, but there is one short stop before mark phase and one short stop after mark phase

  • @shazilsattar5165
    @shazilsattar5165 Год назад +1

    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

  • @Mrwiseguy101690
    @Mrwiseguy101690 Год назад +1

    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.

  • @gunahawk6893
    @gunahawk6893 Год назад

    Dude awesome video, so can we say go uses topology sorting to remove seen msgs?

  • @v0xl
    @v0xl Год назад +10

    this video feels... wholesome

    • @shreyahehe
      @shreyahehe Год назад +2

      Agreed.. he's like the one helpful guy who's always ready to help

    • @core_dump
      @core_dump  Год назад +2

      Thanks ❤️❤️

  • @кодикъ
    @кодикъ Год назад +1

    Your talking and explanation so interesting, really. Keep it up

  • @Duprious
    @Duprious Год назад +1

    Loved this video, thank you!

  • @flightman2870
    @flightman2870 Год назад

    Subbed hoping to see more rust,go videos

    • @core_dump
      @core_dump  Год назад +1

      Sure! They will keep coming (along with other cool engineering stuff) 🤓

  • @rich7e
    @rich7e Год назад +1

    This was very informative.

  • @Brynjar1
    @Brynjar1 Год назад

    I would love the switch their frontend from electron to another thing .

  • @NazarMalyy
    @NazarMalyy Год назад

    I like the way how you represent the information 👍

    • @core_dump
      @core_dump  Год назад +1

      Thanks! Means a lot ❤️

  • @LordErnie
    @LordErnie Год назад +1

    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.

    • @core_dump
      @core_dump  Год назад

      Thanks man!! ❤️❤️❤️

  • @Onkoe
    @Onkoe Год назад +1

    Great lecture, thanks! :)

    • @core_dump
      @core_dump  Год назад

      Thankyou..!
      Although, it's not a lecture, just a guy sharing what he learnt.

  • @Aragubas
    @Aragubas Год назад

    Amazing explanation 💙

  • @sr567
    @sr567 Год назад +2

    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.

  • @paschikshehu7988
    @paschikshehu7988 Год назад

    Just subbed for the interesting content!

    • @core_dump
      @core_dump  Год назад

      Thanks man.. hope i can be your dealer for cool engineering content 🤓

  • @igorthelight
    @igorthelight Год назад +3

    So... why GO doesn't use incremental GC?

  • @harshbhagat9394
    @harshbhagat9394 Год назад

    Great explanation understood everything!

    • @core_dump
      @core_dump  Год назад

      Thanks... Glad I could help

  • @njengathegeek
    @njengathegeek Год назад +1

    such an amazing explanation

  • @chicken6969
    @chicken6969 Год назад +3

    Amazing video. Very underated video

    • @core_dump
      @core_dump  Год назад +1

      Thanks.... Do share it with your peers!

  • @buildfromzero
    @buildfromzero Год назад

    But I read somewhere that, there is an option to disable gc. Any comments on this? Thanks

  • @leonvolq6179
    @leonvolq6179 Год назад +1

    Very good video! Would be nice for the volume to be a big higher :p, greetings!

    • @core_dump
      @core_dump  Год назад +2

      Yep... You are right, have to upgrade this mic at some point. Increasing the gain on this mic introduces a lot of noise

  • @vladimirsrednikh3023
    @vladimirsrednikh3023 Год назад

    It would be great to use more contrast colors to draw chart. For example, black and white on gray background. Or red and green

    • @core_dump
      @core_dump  Год назад

      Thanks for the feedback, I will keep this in mind.

  • @Rarchit
    @Rarchit Год назад +1

    Well explained thankyou!

  • @joshkjoby8400
    @joshkjoby8400 Год назад

    It felt like bubble sort with go's garbage collection

  • @bardus_hobus
    @bardus_hobus Год назад +10

    Great video. Quick question from a beginner: can’t you turn off GC in a Go environment variable?

    • @coffee-is-power
      @coffee-is-power Год назад

      thats literally shooting yourself in the foot.

    • @coffee-is-power
      @coffee-is-power Год назад +1

      btw ditch go

    • @core_dump
      @core_dump  Год назад +13

      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!! 🤓

    • @igorthelight
      @igorthelight Год назад +4

      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?

  • @salman0ansari
    @salman0ansari Год назад +3

    keep these video coming

    • @core_dump
      @core_dump  Год назад +1

      Thanks!! I will keep 'em coming

  • @Zzznmop
    @Zzznmop Год назад

    Great explanation of GC. If only it could clean itself! 😉

  • @jmann277
    @jmann277 Год назад

    Great video!

  • @wendellhatcher7011
    @wendellhatcher7011 Год назад

    This is was before GOGC off and limit correct?

  • @kemaleddinjohnson5391
    @kemaleddinjohnson5391 Год назад

    great video thanks a lot

  • @navicstein
    @navicstein Год назад +1

    You're a good teacher

  • @Verrisin
    @Verrisin Год назад +1

    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

  • @kamalmohamed6611
    @kamalmohamed6611 Год назад

    Could you please say what tool you use for the presentation

  • @shivankacker
    @shivankacker Год назад +2

    Great video 😄

  • @pompiuses
    @pompiuses Год назад +10

    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?

    • @noon8988
      @noon8988 Год назад +6

      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.

    • @pompiuses
      @pompiuses Год назад +8

      @@noon8988 Yes, but it would've been much easier to change/tune the GC than rewriting the entire application in a different language.

    • @darkcaster3619
      @darkcaster3619 Год назад +3

      @@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.

    • @baxiry.
      @baxiry. Год назад

      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

  • @decky1990
    @decky1990 Год назад

    Why was rust chosen over the likes of C or C++ if performance was the end goal?

  • @habibicoding
    @habibicoding Год назад

    good explanation!

  • @memebro3181
    @memebro3181 Год назад

    This is right usage of Rust. Performance critical service = Write in Rust

  • @abinavsriram
    @abinavsriram Год назад

    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✌️

  • @marikantitarun8071
    @marikantitarun8071 Год назад

    Nice explanation and great voice

  • @yoinkling
    @yoinkling Год назад

    great video

  • @kenshein9819
    @kenshein9819 Год назад

    Great explanation.

    • @core_dump
      @core_dump  Год назад +1

      Thanks!

    • @kenshein9819
      @kenshein9819 Год назад

      @@core_dump would love to see more videos like this.

  • @buildfromzero
    @buildfromzero Год назад

    Good information ❤

  • @Ravill
    @Ravill Год назад

    Nice explanation

  • @djuan33
    @djuan33 Год назад

    Amazing explanation.

  • @aarongarcia3296
    @aarongarcia3296 Год назад

    Entertaining and intriguing

  • @jungjunk1662
    @jungjunk1662 Год назад

    You could give some reference to the sources for some of the info you share.

    • @core_dump
      @core_dump  Год назад +1

      Thanks for the feedback, would be better to share more sources.

  • @kreavitawastaken
    @kreavitawastaken Год назад +3

    very interesting

  • @filip_wojda
    @filip_wojda Год назад

    wow very good video thank you

  • @oussamasethoum1665
    @oussamasethoum1665 Год назад +3

    Could be this intentional by Google to maximize your bill in their cloud x)?
    Joking xD

  • @soham7510
    @soham7510 Год назад +2

    A good programming channel, thats indian. 🤟

  • @joecan
    @joecan Год назад

    That's all fine and dandy, but seriously...How often should I be cleaning my ducts?

  • @chakravarthimedicharla4416
    @chakravarthimedicharla4416 Год назад

    have you ever worked with rust?

  • @goldenknowledge5914
    @goldenknowledge5914 Год назад

    They switched? No wonder its smoother now

  • @kwakubiney5175
    @kwakubiney5175 Год назад +3

    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.

    • @core_dump
      @core_dump  Год назад +1

      Yeah, the blog post is 2yr old.. so things might have changed.

  • @joshuafountain
    @joshuafountain Год назад

    Now they just need to fix their interface

  • @aryabp
    @aryabp Год назад +1

    Blanzingly Kitten

  • @atalhlla
    @atalhlla Год назад

    Huh, why might they have been having performance issues…
    1:37 Oh. Go’s garbage collector.

  • @paherbst524
    @paherbst524 Год назад

    Better question is why does anyone use Go?

  • @venkat4you1
    @venkat4you1 Год назад +1

    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?

  • @ayoomike
    @ayoomike Год назад

    yay

  • @retroplayyt
    @retroplayyt Год назад

    opti mi-zation brother

  • @AndrewTSq
    @AndrewTSq Год назад

    oh I always thought discord was some kind of javascript in electron cause how bad it is lol :) thanks for the video.

    • @im_tem
      @im_tem Год назад +8

      you're confusing client code with backend code, client is indeed javascript inside of electron

    • @AndrewTSq
      @AndrewTSq Год назад

      @@im_tem ah okie :)

  • @gsstargamer
    @gsstargamer Год назад

    God like

  • @ulterreloaded134
    @ulterreloaded134 Год назад

    Hopefully they can migrate from electron later

    • @core_dump
      @core_dump  Год назад

      Haha, i can see in the comments...not many electron fans 😅

  • @Manch271
    @Manch271 Год назад

    To GC or Not, is the question ! No easy answers...

    • @core_dump
      @core_dump  Год назад +1

      Ah... Title for a new video. 😂

  • @jefriaritambunan2796
    @jefriaritambunan2796 Год назад +1

    I thought Discord has used Elixir..

    • @core_dump
      @core_dump  Год назад

      Yes, you are right. For most services they use Elixir.

    • @jefriaritambunan2796
      @jefriaritambunan2796 Год назад

      @@core_dump So Discord used Elixir, Go & Also Rust ? I do not know at all..

    • @ccgarciab
      @ccgarciab Год назад

      @@jefriaritambunan2796 yes, they have used all three

  • @shaahkars
    @shaahkars Год назад +2

    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.

    • @core_dump
      @core_dump  Год назад

      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