DEV Community

Gleb Irovich
Gleb Irovich

Posted on

Go vs Rust for web dev

What is a more suitable language for web development Go or Rust? Which one is the best one to pick to work with web assembly?

Top comments (14)

Collapse
 
cdmistman profile image
Colton Donnelly

Late to the party, but came across this post just now.

The Go vs Rust debate is a long one. Both langs came out around the same time (Go was the first to reach stability, though). They both try to achieve 2 different things, but achieve them so differently that there's been a lot of debate.

As someone with experience with both, I personally find Rust better (I came across this post while looking for posts for This Week in Rust, haha).

Rust: Probably the safest language you can use. You'll find the majority of your bugs will be related to logic errors (as long as you abstain from unsafe usage). The ecosystem is full, and encourages use of others' libraries. If you aren't familiar with Rust, you'll find some difficulty in learning the language. However, I find Rust to be better-suited for flexible programming, allowing you to write more types of programs, safely. Another perk is the lack of a garbage collector, which tends to affect high-scale programs negatively.

Go: Probably one of the easiest languages to learn. Learning is quick, writing is quick, and compiling is quick. However, the biggest issue is that (in my experience), Go is really only a great language when you're doing networking programming (server-side).

Note that I said "great" in that last sentence: while Go's strongest suit is network programming, it shines best when you're prototyping the server app. Many companies including Discord have released blog posts saying that they implemented some of their backend using Go, but moved to Rust later on, since Go's garbage collector was causing latency issues or for some other reason.

For wasm, both are fine languages. While I don't have experience either for wasm, This Week in Rust usually has at least one article every week on a tutorial for using wasm with Rust, so I know there's plenty of resources for learning that.

Ultimately, it's up to you to choose which you want to use. I'll leave you with a piece of advice I came across recently: if you want to learn quickly, use Go. If you want to learn properly, use Rust.

Disclaimer: While I do have a bias for Rust in nearly everything, I do still use Go for some things. I'm currently working on an ssh server in Go, which I chose for two reasons: writing quickly, and the two main libraries I'd like to do (Docker provides an SDK for Go, and I found a nice SSH server library in Go that I liked)

Collapse
 
glebirovich profile image
Gleb Irovich

Hey Colton, thanks for the detailed explanation. In the end I decided to go with Rust. I was attracted by the fact that it imposes some challenges and has some concepts, which are new to me. I like pushing myself out of the comfort zone.
As you seem very experienced with Rust, could you suggest some learning resources? I completed a couple of Udemy tuts, but I would prefer doing something more hands on, where I could develop something meaningful along the way.

Collapse
 
cdmistman profile image
Colton Donnelly

Check out the Rustlings course! It's the RustBridge course managed by the Community Team, it's a great way to get practice with reading and writing Rust
github.com/rust-lang/rustlings

Collapse
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

You must use those languages for creating back-end (APIs), not for "web development" as is. (To clarify on web we use databases, html, css, js and the interface structure could be written directly on the javascript, or on html and adding a "passive" script for fetching data or printing the html, css and js directly from the server side programming language).

Giving that, it will depend on the logic and needs of your software piece. For some reason it could be better to write some given API with C#, other with Java, other with PHP, other with Python, or Go, or Rust or C++ or..........

For example if you need high decimal precision to perform a task, you will choose Java or C# instead PHP.

Each language has its implicit implementations for datatypes and runs different tasks better than others (or scale better, or its faster to develop something with or...).

Simplified/ TL; DR: There's no perfect language for a given generic context. Instead you have the best language for a given task, that's one of the points on developing a microservice architecture instead a monolith, because you can develop each micro-service with a different language 😄

Collapse
 
glebirovich profile image
Gleb Irovich

Thanks an elaborate response!

Collapse
 
subhanshuja profile image
Subhan Nooriansyah

I think web development for backend is Go better than Rust, it is to complex for only backend, but if you want to work for web assembly rust is better than Go.

In my opinion is depend on your purpose in first step for normally web development (Go) or progressive web development (Rust). Using Go for web development is easier than Rust that need a lot of stuff for do web development right now.

Collapse
 
fasani profile image
Michael Fasani

I feel like no one who commented answered your exact question ...

Rust is better for WebAssembly.

Collapse
 
glebirovich profile image
Gleb Irovich

Straight to the point, thanks!

Collapse
 
preslavrachev profile image
Preslav Rachev • Edited

I am biased towards Go. It's a much simpler language to start with. It also has a batteries-included standard library, having all that you need for setting up a Web service. Writing and maintaining small HTTP services in Go is simpler, because of the small overhead of having to deal with memory management.

Bear in mind that since Go bears a significant runtime, this will get reflected in the size of the wasm file one would have to fetch. If you do Electron apps, this won't matter, of course. If you want to distribute a tinier wasm file, you can check an alternative Go compiler called TinyGo which strips out some language features (from what I know), but offers a much smaller and thinner wasm output.

Of course, when memory safety is mission-critical (not the case for the vast majority of Web services, IMO), you can check out Rust. Be prepared for a lot of battles with the compiler though. Once you star getting a feel for Rust, you see how things start "clicking", but it's a very steep curve. I can suggest following this tutorial form start to end, and see for yourself if you like the experience or not.

Collapse
 
glebirovich profile image
Gleb Irovich

That was very insightful! Thanks 🙏

Collapse
 
der_gopher profile image
Alex Pliutau

We'll be publishing a post soon about comparing Rust and Go in 2024, stay tuned here - packagemain.tech/

Collapse
 
tmack8080 profile image
tmack8080

You can build a full-stack app with Go's standard library. Check out this tutorial:
calhoun.io/intro-to-templates-p1-c...

Collapse
 
glebirovich profile image
Gleb Irovich

👍👍👍

Collapse
 
der_gopher profile image
Alex Pliutau

Rust for Gophers with John Arundel packagemain.tech/p/rust-for-gophers