Choosing tools to port web app to Rust

I am building a production web app, and started to build it in django. It was super easy, but kind of too easy. So I want to port it to rust. What web framework do you consider best for this? Rocket? Warp? Axum? A different one?

Further into this topic, what an ORM? I have heard about diesel, but is there a better one?

Even further into this topic, what about a database language? I'd def be find with sqlite or postgres, but is there one that can match either of these?

I really need all the tools suggested here to have an active development community and most of the features I would expect in django or, at the very least, flask.

Finally, would I be better off sticking with a programming language with a better developed ecosystem if I want a fully scalable, production-level web app?

Btw, sorry if I wake anyone up...late night work session. :smiley:

Thanks everyone!! gn...

Rust's ecosystem is developed just fine, thank you very much. The language is 17 years old. Nobody would have questioned in C in the late '80s or early '90s. Why would you question Rust in 2024?

It's unclear what you are asking for. Rust client libraries exist for all mainstream DB engines. This is unrelated to the "language" of RDBMSs, which is almost universally SQL.

It almost doesn't matter. Pick one that you like and is actively maintained. I'd personally tend to prefer the more minimalistic ones that provide you with HTTP serving boilerplate and basic JSON serialization primitives, but let you write the rest of your code however you please.

1 Like

You might be interested in some of the very high level web frameworks such as loco.rs which emulates ruby on rails.

I'm not aware of a Django flavoured one.

1 Like

How much/what kind of a challenge are you looking for?

There’s always the option of doing everything yourself based on low-level networking primitives like std::net, but I don’t know that I would recommend it for anything other than a learning experience.

1 Like

I've recently built (am still building) a small internal tool with actix-web and sqlx. It was pretty easy. The documentation for both is pretty extensive. There's lots of resources both official and in the QA form here and elsewhere.

Actix seems able to scale pretty well with its actor model.

1 Like

While I'd second that actix-web is a nice web framework, it should be noted that actix-web is not build on top of actors. It does integrate with the actors from the actix (without the -web) crate though (you have to if you want to handle websockets, for example).

Yes, that was what I meant though poorly worded. When/if I need to scale that small web API, the actors model seem quite capable.

I've settled on axum. I was sort of hanging between axtix and axum for a while. I was strongly against rocket from the beginning because I have recently had a very bad experience with it, and it does not seem like there is as strong a contributor community around it as the others. Axum excites me a lot more than the other options (for whatever reason), and the performance is apparently slightly better than actix. So, axum it is.

That's news to me. I remember when actix came out it was very impressive performance-wise and IIRC the fastest rust web framework (and among the fastest in any language). But lo and behold it is behind axum and other rust entries in the latest tech empower benchmark (October 2023).

Nice to see rust entries at the top :slight_smile:

May (of may_minihttp) has just caught my eye, hadn't noticed that before now.

1 Like

I think the author had a long hiatus but he came back about a year ago with v.0.5 - I found it easier to set up than Actix and Axum, which had out of date documentation and examples.

24k stars on github don't lie - Rocket is great :rocket:

4 Likes

Yes, rocket is definitely superior in terms of ease of use and documentation: I tried using the axum postgres-diesel example and ended up having to rewrite the whole thing. :smiley:

I wonder what the bad experience with Rocket was? I used Rocket without any problems with a Postgres database. At a time when I was still very new to Rust. I have not looked at any other Rust web servers so cannot make any comparisons but it all worked out as easily for me as using Express under node.js.

1 Like

For me, I disliked how opinionated the framework was. It took me a pretty long time to figure out how to disable the logging, which was pretty horrible and uncustomizable...Also, I had a lot of problems with the routing, which forced me to implement a manual route, which was not very pretty. As a rotten cherry on top, I had to jump through a lot of hoops just so I could send a file as a binary stream instead of txt, html, etc., etc. file.

It's been a while, so a lot of my problems have probably been fixed by now. Still, i like the more low-level approach that axum takes and probably won't be switching back.

You're not wrong about it being opinionated -- the idea is to optimize for the common case, and if you're not the common case then you might need to put a little more work in. Most of our web apps have been easily expressed using Rocket, but on the rare occasion we've had to implement some of the "we do not recommend that you implement this trait yourself" traits, which is less fun (but also not horrible, because the docs are so good).

To address some specifics:

  • Sending a file as a binary stream is trivial these days. Whatever limitation you ran into is likely gone today.
  • Logging is still an issue. There's long-standing issue about this. Basically, the current logging can be seen as a place-holder until a proper long-term solution can be found.
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.