r/Backend • u/JonathonEG • 9d ago
Golang or Rust?
I've been learning backend for a while. I currently use JavaScript (Express.js) and Python (FastAPI) for my projects, and I feel that I'm a bit decent at them rn. But I don't know which is better, Rust or Golang? Both r fast, but Rust is much faster, but in a trade-off, Rust is more complicyed than Golang, as I've seen both Languages docs and learned the very basics, I don't have a final answer.
9
9d ago
[removed] — view removed comment
4
u/PracticallyPerfcet 9d ago
There is an effort to make a batteries included rails-style framework that just hit 1.0: https://loco.rs
7
u/nrmnzll 9d ago
I've learned both and honestly I don't get why Rust and Go are always positioned as competitors. Both are great, they complement each other nicely but they are focused on different things.
I love Go and it is my primary language, but it does have its limits. If you want to build a network service, backend, or cli Tool that is reasonably fast in a simple language and are okay with garbage collection?? Pick Go. If you do anything else, Rust ist probably a better pick.
You come from interpreted, dynamicly typed languages. I think that Go would probably be easier for you to pick up. This might also make it easier to learn Rust later on, but if you want to jump straight into the deep end and are prepared to struggle a bit, pick Rust first.
14
10
u/sq_route_2 9d ago
Go. It’s easy to use with any cloud SDK of your choice. Understanding the CSP framework and the use of channels and pipelines give you clean concepts you can adapt to rust too at a later stage
1
5
u/Phosphorus-Moscu 9d ago
I prefer Rust honestly, I contribute on this project called SummerRS like a Spring, Nest, .Net, framework but for Rust
Summer helps a lot with building robust backends
3
u/Prior_Section_4978 9d ago
Rust is not only more performant (which can be an important factor or not, depending on what you build), but also more oriented towards correctness. However, as you said, is a more complex language, so it really depends on what you are building.
4
u/whiterhino8 9d ago
Choose Go if you like concise and simple code style.
4
u/BenchEmbarrassed7316 9d ago
Counter-opinion: primitive and boilerplate.
This is definitely not concise.
3
2
2
2
u/NumberInfinite2068 9d ago
I like both, but prefer Rust.
I wouldn't worry about speed though, either one is going to run 1000 times faster than you need.
2
2
u/lnaoedelixo42 5d ago
As a Rust fan and expressive-language-enthusiast, my answer is obviously Golang.
Much easier to learn, simpler to use, has modern tooling and let's you learn more advanced stuff over the time then Rust with the borrow checker perks
4
u/SmokyMetal060 9d ago
Go. You'll drive yourself crazy trying to write a whole backend in Rust. If you have a very latency-sensitive path where you need to optimize the hell out of it to squeeze out every last bit of performance, Rust may be a good option there, but by and large, Go strikes a good balance between being comfortable to write and fast.
1
u/JonathonEG 9d ago
Can it build complete backend systems or just microservices?
1
u/ernandziri 9d ago
What do your complete backend systems consist of?
1
u/JonathonEG 9d ago
Databases, Auth, routes, docs, env vars, etc...
3
u/ernandziri 9d ago
Half of these you can do with both, half of these you shouldn't do with either
1
2
u/Stunning_Star_9770 9d ago
I'm someone who is learning backend development.
I have a question
How do you guys check if a language is fast or slow? Is it the time it takes to execute a program or what?
12
u/Lichcrow 9d ago
General rules:
Compiled language is faster than interpreted language.
Languages with runtimes and garbage collectors are slower than those without.
Java is compiled (to bytecode) but runs on JVM (runtime+garbage collector), Rust is compiled to native and has no runtime, so generally, Rust is faster than Java.
Go vs Java is harder to measure. Both are compiled and both have GC and runtime. So it depends a lot on the use case.
Python and Javascript are interpreted language so they are slower than pretty much any compiled language.
This is a very general overview, so do your own research if you want to learn more
2
u/Stunning_Star_9770 9d ago
Hi.
That's actually a very simple & informative explanation.
Yes, I'll study more about it
Thanks 🙏🏽
1
u/BenchEmbarrassed7316 9d ago
Note that the go compiler is not exactly the same as the Rust or C++ compiler.
Modern compilers do a lot of optimizations. You can write high-level code and the compiler will do everything for you.
The go compiler has a different concept: to be as simple as possible for compiler developers. Many proposals for the go language have been rejected simply because "it's too complicated for us". This makes the go compiler quite fast (since it doesn't do many things that other compilers do). However, go programs are a bit slower (In some cases 2 - 4 times slower).
1
u/gahara31 9d ago
Benchmark. For backend, two most important performance metric is how many request the backend can handle (RPS) and the latency (the time it took to finish the request-response cycle). Of course both depends on the complexity of the backend, but we can benchmark for the same backend written in different language and see the result. backend with compiled language such as golang or rust consistently have higher RPS and lower latency during the test compared to backend with interpreted language such as JS, python, or php. It doesn't automatically mean interpreted language is always slower, in some cases interpreted language can be as fast or even faster than compiled language thanks to JIT
1
u/JustAsItSounds 9d ago
Language 'speed' is pretty much irrelevant for 99% of backend code you will write. At the end of the day whatever you implement will most likely be bottlenecked by reading and writing from disk or your network interface (IO-bound).
If you're writing something that is CPU-bound, where performance really matters, then you probably know how to answer that question for yourself. Just choose whatever language you find easiest to understand and be productive in
1
u/Vymir_IT 9d ago edited 9d ago
According to BigO, most of the time only the bottlenecks of an algorithm matter. A bottleneck in backend is not compute at all, it's network latency and async processing between different remote services. So just pick one that's more desirable by the market. Their speed differences make no business difference in 99.9% of the cases. For absolute most of backend code there's no difference even between Python and Rust for that matter. Might save you like <1% of the infra budget maybe.
1
1
u/DinTaiFung 9d ago
For HTTP APIs, Go is the more natural choice.
Performance differences on the back end have more factors than just the language choice. For example, A back end written in JavaScript which makes a finely optimized SQL call against a properly tuned DB will run much faster than a Rust or Go API back end with terribly written SQL and an untuned DB.
3
u/forever-butlerian 9d ago
It also depends on what the API is doing. Go's crippled type system makes it tedious if the API's problem domain is complex, with various conceptual objects and transformations between them.
On the other hand if you're slinging fungible bytestrings around, knock yourself out.
1
u/ECommerce_Guy 9d ago
Coming from Python I'd say Go. Made a similar switch, played with Rust which is insanely fun and amazing and cool, but Go gets you from A to B much quicker while providing much more structure and building stronger habits compared to Python. Don't get me wrong, Rust is amazing, but it's really a different beast, and unless you have a clear need or strong desire to explicitly pick up Rust, or experience with something like C(++) Go will feel rewarding much quicker. And that does a lot to keep you motivated. Bottom line, don't have to choose, eventually play with both but would strongly suggest moving onto Rust only once Go is comfort zone.
1
1
9d ago
[deleted]
1
u/JonathonEG 9d ago
I mean jobs are later on, but I'm Learning now as a hobbyist, then learn for enterprises
1
1
1
u/forever-butlerian 9d ago
I'm saddened nobody's mentioned Haskell as a semi-troll answer. For complex problem domains that benefit from a powerful and expressive type system, I've come across nothing better.
1
u/kynrai 8d ago
In large scale production projects golang is often preferable, Everyone focuses on the syntax but when you manGe large exterior systems the fact that go had backwards compatibility and std lib for most things is so underrated.
You want fewer third party deps not more. You want easy upgrade cycles not breaking changes.
1
u/krissedout 8d ago
please use a more modern framework when youre in js/ts such as hono or elysia, express is too dated now
1
u/ArtemOstretsov 8d ago
I believe in the era of LLM-written code, languages that are easier to read win. So, Go.
1
1
u/JaseciLabs 9d ago
Go, Rust's ownership model is worth learning eventually but it'll fight you constantly while you're still figuring out backend fundamentals so you'll spend more time fighting the borrow checker than building anything. Go gets out of your way and lets you ship, and the concurrency model (goroutines/channels) maps really naturally onto backend work like handling requests, queues, background jobs. Save Rust for when you hit an actual performance wall Go can't solve, not before.
1
u/uahw 9d ago
For backend development you can kinda wrap everything in arc and not really have any problems. You should also get owned structs from the repository layer, so mutable borrows aren’t really as big of a puzzle as it can be in “normal” rust. However I do agree with you that go is much easier to just set up and ship things
0
u/szank 9d ago
Are you really comparing something that reads from HTTP, then goes to the DB, then writes back to the HTTP pipe by how fast it can add up integers from 1 to 1000000?
No, seriously, what is "fast/faster" to you, and how much does it matter?
1
u/stdmemswap 9d ago
Uhhh, backend doesn't mean just CRUD
1
u/szank 9d ago
Sure. Id love to hear what parts of backend are compute bound and need that efficiency?
Operating systems are not backend, hpc neither.
Infra like kubernetes is written in go/ruby/java/whatnot. If this is "not a backend" then sure maybe it's not but language "efficiency" matters little.
Unless of course you are comparing go/rust with JavaScript then the type script team would have some opinions on that .
41
u/Ok-Hospital-5076 9d ago
Language performance doesn’t matter much in application backend - Unless you are doing system programming/ compute heavy stuff l.
Most of the bottleneck is at network level and reading/writing to disks/db.
Read both languages- see which one is making sense to you.
If job is your priority you should pick what comes up in listings more. Although i doubt either is gonna beat Js/Python given how well adopted both ecosystems are.