Is it worth it using Rust+Axum for backend instead of Node.js? In which situations would you do so?

In practical perspectives, I’m mostly concerned about computer resources usage; I have computer resources constraints. So using Rust would benefit on that. But it is for a Web application backend. So, is it worth it having to learn Rust + Tokio + Axum, … in this specific situation? Also, that this is mostly for initially prototyping an application. Also considering if I add developers in the future, they would most likely not be familiar with Rust, but with more popular frameworks such as Node.

arc,

I think if you know Rust then I think Rust + async is going to perform better and consume less resources than NodeJS by a LOT. It should also work more reliably on embedded devices, or even docker containers because memory isn’t going up and down like a yoyo because of GC.

That said NodeJS is more immediate and might lend itself to better prototyping / RAD and you might not care enough about performance to justify using a compiled language. A lot of web servers aren’t doing enough that you would even notice a difference in performance.

Another reason for Rust might also be because it’s more energy efficient. I wish Amazon and other cloud services would put a heavier cost penalty on efficiency. I wonder how many cloud web apps are running bloated stacks to serve up content which could be done with a fraction of the energy.

ssokolow,
@ssokolow@lemmy.ml avatar

There was a post on Reddit from 2019 that I loved to link to which was about how the poster rewrote a NodeJS service into Rust.

The original was taken down in response to Reddit enshittifying, but it’s still up on the wayback machine and the graphs were hosted on Imgur, where they’re still up without needing the Wayback machine:

anlumo, (edited )

For prototyping, if you don’t already know Rust, it’s probably not worth it.

When you really know Rust it’s IMO easier to write a web server in Rust than node, but there is a long road to getting to that level.

fr33d0m3,

@anlumo @nyl you wouldn’t prototype a software using a tool that’s made for speed and memory safety. Rather aim for a tracing bullet. Prototypes are imho a waste of time

anlumo,

I think prototypes are fine to answer specific questions. However, I think it’s often the case that management doesn’t understand what a prototype is and thinks that this is just the alpha release of the real product.

Rule of thumb: if you don’t throw away all of the code after having answered that question you were writing it for, it’s not a prototype.

nous,

Because of that prototypes should be small - no more than a week or so worth of effort. Anything larger means it will take even longer to rewrite it from scratch which management will never like and is overall just a waste of time. Most of the time you don’t actually want a prototype - you want a MVP written in the language of the final project as it will become the final product.

Really the only time I would write a prototype in a different language then the final product is when you don’t yet know the language you want to (or more likely, need to) use or you know another language vastly more than the target language. The time saved by the language is often just not worth it overall when you are reasonably competent in both languages.

TehPers,

This highly depends on what it is you’re trying to build. If it’s a simple CRUD backend + database, then there’s really no reason to use Rust except if you just want to. If it’s doing heavy computation, then you’d want to benchmark both and see if any potential gains by writing it in Rust are worth the effort of using Rust over Node.js.

Practically speaking, it’s really uncommon to need to write a backend in Rust over something like JS or Python. Usually that’s only needed for high throughput services (like Cloudflare’s proxy service which handles trillions of daily requests), or ones performing computationally expensive work they can’t offload to another service (after benchmarking first of course).

crispy_kilt,

If it’s a simple CRUD backend + database, then there’s really no reason to use Rust except if you just want to.

I did this. Further reasons are: correctness and performance.

Rust is much faster while at the same time using a fraction of the resources the equivalent Spring Boot implementation would use. The type safety and being freed from runtime errors is awesome as well. Yes initial development takes longer, but I believe it is worth it. Most projects spend maybe 2% on initial development, 98% is bugfixing, troubleshooting, refactoring. I am confident Rust cuts down on bugfixing by 2/3, which means doubling the initial dev time is well worth it. And it doesn’t even take twice as long.

TehPers,

For very simple backends, it’s very unlikely you’ll get any significant number of bugs with an experienced team, and if performance isn’t really a concern, then Rust being faster isn’t really relevant. For anything more complex than a simple backend, I’d agree that Rust becomes a lot more appealing, but if you just need to throw together something that handles user profiles or something in a very simple manner, it really doesn’t make a difference what language you do it in as long as you write a few tests to make sure everything works.

crispy_kilt,

Agreed!

GissaMittJobb,

Consider the constraints and select technology accordingly. You mention being concerned about compute resources, try to elaborate on that.

Are you doing it for ideological purposes? Is your hardware exceptionally constrained? Economical limitations? You will necessarily spend a lot more time compiling when using Rust, so that might eat up any compute savings if the scale of the project is small enough.

If time is a concern at all, then learning a different stack is almost always going to be a losing proposition. Rust is also not the most prototyping-friendly language in my experience - hacking together stuff in Python is almost always going to be faster - but it’s by no means impossible.

If for educational purposes, then I recommend Rust, as it is fun and teaches you new ways of thinking about your code.

Finally, the fact that few people know Rust is a real underrated disadvantage you definitely want to consider.

Best of luck with your endeavor.

illectrility,
@illectrility@lemmy.world avatar

Learning Rust is probably always worth it. It’s more efficient, lasts longer and is safer, I would try it

Knusper,

I mean, what kind of resource constraints are we talking about? If it’s low-powered hardware that can’t run Node.js, then it’s obviously going to be worth it…

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • uselessserver093
  • Food
  • aaaaaaacccccccce
  • [email protected]
  • test
  • CafeMeta
  • testmag
  • MUD
  • RhythmGameZone
  • RSS
  • dabs
  • Socialism
  • KbinCafe
  • TheResearchGuardian
  • oklahoma
  • feritale
  • SuperSentai
  • KamenRider
  • All magazines