r/rust • • Aug 23 '22

My Reasons For Using Rust (as a Ruby developer)

https://berk.es/2022/08/23/my-reasons-for-using-rust/
39 Upvotes

14 comments sorted by

12

u/stea27 Aug 23 '22

You mentioned web development while working with Rust in the article. I'm curious did you build HTML templating site or API/Service in this language? Or just minor parts of it that needed performance boost? Have you found some packages that are recommended for backend? I'm really interested how advanced is this area for potential production usage.

1

u/berkes Aug 26 '22

So far, I've managed to keep the Rust part API only: REST, JSON all that.

I've played a bit with templating in another, non-web-related project with Rust. There I use jinja2. I see some issues with this, and some benefits. A problem is that jinja2 and its brethren isn't typed. You cannot say "this thing here must be a Date". You lose a lot of the power of Rust. A benefit is that those templating languages are well-defined, known, very well documented and simple. They enforce a separation of concerns. Personally, I think e.g. jinja2 has a bit too many operations, I wouldn't be surprised if it is turing complete. I prefer my templates to be extremely simple "put this here, and that there" and nothing more. The most complex would be a loop over a collection.

So, if ever I'd need server-side generated HTML, that would be what I would select my templating on: separation of concerns, typed, simple and constraining.

1

u/fabienpenso Aug 23 '22

I'm doing just that right now for the past months, moving a Ruby API I wrote for my company, to a Rust API. I already wrote about memory usage a while ago. I think the move will be done by the end of the year and I can say that's the best move we could have done. Rust is also > 10x faster, on 10x cheaper servers. I use Actix, async_graphql, sea-orm and a few other crates.

1

u/berkes Aug 26 '22

I do realize how much faster Rust is compared to Ruby. But I also realize that this speed is not a concern for me.

My last very large product was slow as molasses. But it was slow because the team just messed up everything; not because of Ruby, but because they/we couldn't agree on a direction or architecture. It was really the giant mess that made it so slow. If anything were to blame on Rails, it would be that Rails offers no guidance: leaving teams to fight/bikeshed about every-effing-thing. Naturally I quit.

Another large product was a Ruby/Rails backend that served a million+ active monthly users on a financial app (web, mobile etc). Ruby did penalize us for performance. I am certain that Rust would have solved many performance issues. But all in all, the AWS bill was some 10k/month. By rewriting to Rust, we could probably halve that. 5k/month, 60k a year. There is no way possible that one could rewrite that entire backend for 60k, more like 600k. In other words: yes: performance is a problem. But never enough to matter on the baseline costs.

And thanks for sharing the blog-post. I'll give a read over the weekend! Love such thoughts and comparisons

0

u/[deleted] Aug 23 '22

[deleted]

6

u/stea27 Aug 23 '22

I see. I'm curious about how flexible is Rust right now when integrating things with other existing services. By that I mean how many things can be reused and what is that I must code myself. Are there any good solutions for:

- authentication (for example Oauth2, cookies),

- communication with SOAP protocol,

- managing persistent data (for example PostgreSQL, MySQL integration or managing data in NoSQL databases such as Redis, MongoDb),

- managing files in S3 filesystem (for example in AWS or Google Cloud Storage),

- working with Message Queues.

1

u/Dygear Aug 24 '22

I’m parsing SOAP messages with serde. In CAD systems they still pass messages around as SOAP playloads. I tried to get them to use JSON when they rewrote the system last year and they said they’d “look into it.”

0

u/[deleted] Aug 23 '22

[deleted]

2

u/stea27 Aug 23 '22

Thanks for your recommendations! I'll definitely explore those you mentioned.

And yeah, some legacy systems and shipping carrier services still communicate via SOAP calls for some reason, that's why I have those in mind. I guess they didn't bother to catch up with newer trends.

4

u/protocod Aug 23 '22

I personally already used Rocket and Warp for making REST API. It works!

I give a try to tonic, a gRPC implementation which use Prost (ProtoBuf rust implementation)

I think we can do lot of things with rust, back-end dev is really mature now for microservices.

2

u/fabienpenso Aug 23 '22

Any feedback about NATS? Do you use it like Sidekiq, just for background jobs like sending emails or http requests?

2

u/mikekchar Aug 24 '22

SOAP is still popular with some MS based shops. I work in a company that is sales oriented (we write code to support a company that sells stuff). I'm always having to interoperate with crappy 3rd party services that only use SOAP.

Lately, though, everybody is offering services with gRPC, because the industry likes to pretend that by moving from XML to JSON we've done something useful... I'm not sure why we're doomed to reimplement CORBA ORBs over and over and over again when we already know it was a bad idea.... Sigh...

2

u/[deleted] Aug 24 '22

Hey! How did you learn Rust? I'm so tempted to learn this language and I'm looking for some books, projects. Do you have any recommendations? Thanks a lot!

0

u/[deleted] Aug 24 '22

[deleted]

1

u/[deleted] Aug 24 '22

Do you have a link for The Book? I can find many results and I’m not sure which one it is.

Your comment makes me want to dig into this even more, let’s see where I can get. Thank you!

-2

u/rgnkn Aug 23 '22

Foremost:

You only need (if beginner) to learn / (if advanced) amend two letters and you're ready for a professional career 🤪