Live data from Hacker News

Rust needs a web framework

ntietz.com

51–60 of 395 posts

Re: Rust needs a web framework

#51
I consider myself a lazy developer: I like to write code that minimises the amount of code I'll need to write to incorporate new features in the future.

Laziness isn't necessarily a bad thing, depending on how it's implemented.

Re: Rust needs a web framework

#52
It really doesn't, actix is already there. Recently built my startup code over the past couple years with Actix and it had literally everything we needed easily. We just need more documentation and reference code bases demonstrating how to do these things. Rust devs tend to be fairly advanced and seemingly don't write enough docs or shares.

>Routing/handlers

Actix has it.

>Templates

Minijinja or liquid-rust[1]

>Static file serving

actix-files[2]

>Logins

Actix with oidccore is fantastic and easy[3]

>Permissions

Actix FromRequest is literally perfect. We have perm levels (admin, owner) and per-route perms for more fine-grained control.[4]

> Database interface

Diesel with diesel_async for connection pooling has been flawless at scale.

> Admin tooling

We didn't do this, but it would be simple with a bin/load-data.rs file that runs via a docker start command or tmuxp pane.

> Hot reloading

Cargo watch is getting deprecated, but was great. Bacon and and Watchexec are fully qualified successors. CSS watch systems work with the templates already same way as they do for SPAs.

> Background tasks

Make a bin/worker.ts file which defines a single binary and then use redis or another queing sytem to communicate between the worker and core server. We loaded all of HN (40M docs) into a search index with this approach and it was easy.

> Monitoring/observability

There's a decent story here with structured logging. Zero to production in Rust has a good chapter on it (2020) [5]. Lots of progress has been made since and exposing prom metrics endpoint is straightforward [6]. Sentry support is also decent and they sponsor actix.

> Caching

Imo, the story with Redis + actix is fine. We do this with our auth middleware to reduce latency on that operation since it happens with every route and I think it's smooth with FromRequest.

> Emails and other notifications

What's wrong with SMTP? Plus, Keycloak will handle your password reset infra out of the box. SDKs here could be better, but the APIs are fine and not too bad to do with Reqwest yourself.

> Deployment tooling + CSS/JS bundling

Imo, both of these things are the same as with other languages. Rust could use more documentation, but I don't think there's anything making it particularly hard to use.

[1]: https://github.com/devflowinc/hn-search-RAG/blob/main/actix-...

[2]: https://github.com/devflowinc/hn-search-RAG/blob/main/actix-...

[3]: https://github.com/devflowinc/trieve/blob/main/server/src/ha...

[4]: https://github.com/devflowinc/trieve/blob/main/server/src/ha...

[5]: https://www.lpalmieri.com/posts/2020-09-27-zero-to-productio...

[6]: https://romankudryashov.com/blog/2021/11/monitoring-rust-web...

Re: Rust needs a web framework

#53
post #36

Rust has some great and useful web frameworks that are a joy to use, once you understand what is going on. For example, in Axum, they use traits cleverly to allow you to use dependency injection the same way that fastapi uses it. But at least when I started using it, that wasn’t an insight made bluntly clear with tutorials as good as tiangolo’s. Instead, I had to piece it together via examples in the axum repo as wel…

>once you understand what is going on

I think this is the big issue. We as members of the Rust community should be doing more to explain all the patterns for webservers in particular.

Support is there, but it's non-obvious.

Re: Rust needs a web framework

#54

Earlier quoted context omitted.

1. Lots of dead ends. Fetch cache limit for example. Cant replicate prod page caching behaviour in dev. Etc. Many issues with 100 thumbs get abandoned. 2. NodeJS. Not everyone likes it. 3. It is slow. Yes it is! Try to get good web metrics with Next I dare you! 4. Premature release of App Router. Will they do something like that again.

I appreciate that you’re getting to the crux of the matter instead of downvoting. In our experience elevating the web metrics in Next.js takes the same expertise as doing it in any other framework. Our experience with Vertx and Microsoft’s dotnet web frameworks have been good, but Next.js got us to a fast, featureful, performant website sooner and with more flexibility around requirements. I won’t pass judgement on r…

Ok I will bite. How did you manage to get scripts to defer?

Re: Rust needs a web framework

#55
Just use Phoenix and live view.

Prototype is easy and fast. Scales well to very large user base on a single node. Interactive client side without even writing JS.

I love rust, I really do, I use it for all kind of things. But for web app, the Erlang architecture is so well designed and mature you cannot compete.

Also we use rust and zig from Erlang with native modules for video processing and AI, the elixir/Erlang "skin" gives you immense flexibility and productivity with almost no performance hit.

Re: Rust needs a web framework

#56

I wish the author success in their endeavor, but Rust is pretty far down the stack of languages I'd use to deliver a webserver. I look at Rust for serving web-traffic and I see: dreadful concurrency model (I will never voluntarily go back to async/await after working in Golang), weak client library stories (if I'm writing a service layer for a db, etc.), high barrier to entry, thin overlap with the core Rust value pr…

> dreadful concurrency model (I will never voluntarily go back to async/await after working in Golang),

Rust supports golang style message-passing concurrency if you want it[1]. I'd argue Rust mpsc channels are actually more powerful than Golang's and add richness to message-passing concurrency modeling.

[1]: https://doc.rust-lang.org/book/ch16-02-message-passing.html

Re: Rust needs a web framework

#57
post #10

> I like to make silly things, and I also like to put in minimal effort for those silly things. I also like to make things in Rust… I think this part is perhaps the silliest part of a very silly article. If you really like to put in a minimal effort then why on earth would you use Rust? If you want efficiency, memory management and a compiled modern language just use Go. Then you won’t even need anything but the stan…

This is definetly something the article should have drilled down on. Why Rust? I'm sure everyone's tired of hearing why rust is an excellent alternative to c/c++ for new projects, but as an alternative against Python it gets muddier. Rust has a clear advantage in performance and memory footprint and a much better multithreading story, but those are things that aren't high priorities for 95% of web development. That b…

The answer for why folks are so inclined towards doing high-level tasks in Rust... is the type system. Its sensibilities are in a sweet spot that makes it very easy to pull off huge refactors. It was also a lot of people's first introduction to algebraic data types being used in nearly all error handling (its usage of `Result where E implements Error` and lack of nulls or exceptions). It makes a lot of progress towards the goal of "make invalid states unrepresentable", which could be really useful for web apps.

Re: Rust needs a web framework

#58
post #10

> I like to make silly things, and I also like to put in minimal effort for those silly things. I also like to make things in Rust… I think this part is perhaps the silliest part of a very silly article. If you really like to put in a minimal effort then why on earth would you use Rust? If you want efficiency, memory management and a compiled modern language just use Go. Then you won’t even need anything but the stan…

Yes the intersection of compiled performant and web is mostly filled by Go.

Re: Rust needs a web framework

#59
post #43
post #10

> I like to make silly things, and I also like to put in minimal effort for those silly things. I also like to make things in Rust… I think this part is perhaps the silliest part of a very silly article. If you really like to put in a minimal effort then why on earth would you use Rust? If you want efficiency, memory management and a compiled modern language just use Go. Then you won’t even need anything but the stan…

It could beat using C/C++ for using an embedded web server. I remember I tried that once and a lot of the work was using aho-corasick for working with paths, handling cookies and dealing with a bunch of nasty error handling all of which in theory would be easier in rust. My problem wasn't so much dealing with memory management, but trying to put an upper bound on memory usage and failing nicely when that upper bound…

https://github.com/BurntSushi/aho-corasick

I've had a lot of fun playing with it, it was very nice & simple to use. It's also foundational in the Rust ecosystem, so it's well maintained.

Re: Rust needs a web framework

#60
The author is I think conflating laziness for joy. We don’t care to be lazy because that won’t do it. But we do want to have a language that we like to use. To look at, to play with, to understand and to rally behind.

There is no one web framework that will satisfy all criteria and all layers of what a web framework needs. Every so often we have to migrate as technology catches up and changes the ecosystem, like wasm did with Blazor.

I’d rather have a language that programming is a joy in. The laziness is a nice side benefit. I can adapt such a language to changing landscape any day. I know Ruby is such a language, and hence Rails adopts it’s joyful mentality. But is Rust a joy to program for? That I can’t say for sure.

Post reply on HN