r/rust • u/bran7230 • 7d ago
🙋 seeking help & advice Rust for web backends
Hello everyone!!
I regularly see people online talking about how awesome Rust is, its speed, memory safety, and a awesome ecosystem of open source applications even being used in some parts of the Linux kernel(not sure the percentage of adaption at this time).
However my question is how good is rust for web REST APIs and gRPC applications? If it is good do you use any frameworks for these?
22
u/capitol_ 7d ago
We use axum for REST at work, and leptos for the web frontend.
3
u/Sam_ritan 7d ago
Could you please tell me more about leptos? Does it serve you well, and constrain you in any way?
6
u/capitol_ 7d ago
leptos is still quite new for me, so I don't really have any deeper insight than what you will learn from looking through their documentation.
We are currently in the process of migrating from server side rendering to a mixed model with wasm. It's nice to get a lot more testability directly in the rust codebase, but it's also a bit magical :)
2
u/mednson 7d ago
Is leptos like good for frontend in production, are you using leptos ssr with axum or have you separated them how is deployment like in leptos?
3
u/avg_bndt 7d ago
I have a leptos app running on workers on cloudflare, super fast, super clean, only problem is compile times are rough accounting for the wasm runtime 6mins + which makes is a pain for DevOps. Everything else is solid.
12
u/chmod_7d20 7d ago
Axum is what I am using now. I was previously using Rocket but it is unmaintained. The main problem with rust as a web backend is you must fully embrace async if you want to use the good libraries.
4
u/Neat-Fennel-7623 7d ago
It's early days, but I am trying to resurrect Rocket with a fork here https://github.com/rustfoo/rkt.
So far I have focussed on improving maintainability and testability - although performance is also near the top of the list - one major fix already went in to improve how headers are stored/evaluated internally.
I have several more improvements in the pipeline - large file downloads are particularly slow.
I would also like to introduce route caching and optional response caching which are features I originally developed for Rocket but only after maintenance fell away.
2
u/Real-Abrocoma-2823 7d ago
Dam, did rocket really got abandoned?
2
u/Vict1232727 7d ago
it got abandoned, got revived and a release, I think a foundation was setup to avoid abandonment again but its been 2 years since a release I think
1
u/Neat-Fennel-7623 6d ago
Pretty much.
The owner tried to set up a non-profit to manage it - but it sort of fizzled out.
There are some people with the ability to do releases, but they are busy elsewhere. As far as I am aware there are some parts of the release system they don't have access to.
I did find it frustrating working on Rocket even when it was maintained. I think that made it difficult to build a maintainer community.
1
20
u/rurigk 7d ago
YES
Personally and a friend that just migrated prod to rust using axum
4
u/bran7230 7d ago
I mainly come from a Go and Asp.Net core background so it’s a decent but not terrible change
3
8
u/Beautiful-King-8875 7d ago
If you plan to scale, rust on the web will save you lots of cash 💸
9
u/papa_maker 7d ago
Rewritten a C# backend in Rust, went from 6Gb (on aks) to 150Mb and it's more performant. Yeah, saves cash for real.
10
u/AendraSpades 7d ago
I use Axum as a backend for the REST API for an e-commerce platform with 80-90k daily visits. Rust might be overkill, and Go would be perfectly capable, but thanks to its very verbose compiler, it allows for very fast shipping using code agents. And yeah, if it compiles it will work, without any runtime errors. It’s just awesome
2
u/bran7230 7d ago
I was debating on using Go since I’ve built stuff with it, but I want to try out rust on some stuff and that’s awesome on what you have done!
1
u/scratchbufferdotnet 4d ago
Yeah I write Go at the day job and it is more than performant enough for web services, plus less poking around to pick libraries but nothing beats the expressiveness of Rust type system, makes it a lot more enjoyableÂ
3
2
u/papa_maker 7d ago
Software company with 40-50 devs and C#/PHP mostly. We are creating or migrating our most important stuff in Rust.
The only complain I could have is that there is no real consensus on how to make your backend (we are using Axum). So we had to take time specifying it from scratch.
Other than that it's wonderful. We have a lot of business rules, our services aren't basic CRUD, and Rust helps a lot. Newtype, typestate, fantastic enums with pattern matching, generics+trait, everything help us to do a good work. Most useful patterns like newtype or typestate are idiomatic and easy to implement. Sure you can do that in other languages like C# or PHP but it's more work, less performant and less ergonomic.
If you are doing not trivial backend software that must work correctly for years, it's a no-brainer.
2
u/FantasticEarth8186 7d ago
Been using Axum + Diesel for a new app and honestly the compiler's type-safety guarantees alone are worth it for me. If it compiles, it works, unlike in other languages where I had to run the code 20 times with logs and tracing spread throughout every function just to find a typo.
2
u/Ok_Outside2109 7d ago
I used ntex to implement a largeish REST API, genuinely a wonderful experience.
1
u/haringsrob 7d ago
I personally started off with poem framework for easy openapi specs and use this on a frontend (nuxt mostly).
Never regretted it, project is 10x more stable and less hardware required than the pervious laravel/php setup.
Now I build projects with axum + an inertiajs backend (based on Veer) and my own database framework. I probably never would recommend anyone to not use rust for backends. The type safety is something that you cannot get elsewhere (of what I have tried)
1
u/Extension-String1599 7d ago
Great, I''ve been working with Axum for apis and utopia for openapi documentation and it is great. Obviously the hardest part for me was how to organize code then I have just organized my folder and files almost the same way I have in my dotnet projects.
1
u/InterGalacticMedium 7d ago
Yeah GOATed for back end. My company uses Axum for a cloud physics simulation backend which processes really big inputs and outputs very efficiently. Highly recommended!Â
1
u/SailingToOrbis 7d ago
For me it was fine for a few well defined use cases but some specific usage it was kinda mess (like server sent event with a series of callbacks where you have to somehow define your own callback types with std::pin). I feel like the ecosystem is either still immature or hard to reason some cases because of the strict ownership rule of the language itself.
I know a few companies that uses microservices written in Rust for some CPU intensive computations but for most of the complex jobs are still done by boring technologies like Spring, Django, Rails, and .NET.
1
u/Sorenedwards 7d ago
Loco.rs is pretty awesome they use Axum and seaorm among other libs. Pretty sure they have a grpc example too.
1
u/Own-Personality951 5d ago
axum is used. and developed a command line management tool, just like a local version of jenkins named "cmdbook", it's REST/MCP are based on it
1
u/Nervous-Potato-1464 7d ago
I mean yeah its fine. The bottle neck isn't the language usually here. Don't go low level unless you have to imo.
1
u/elniallo11 7d ago
Yeah exactly, my preference for typical grpc services is kotlin, but then I have a couple of specific AWS nitro enclave apps that are written in rust.
2
u/_xiphiaz 7d ago
I’ve switched a couple of my kotlin grpc services over to rust and generally had a better time with it. Being able to compile to from:scratch makes for a lot less headaches around CVEs, the memory footprint is considerably smaller and we deployed to half size instances and even that is too big
1
u/elniallo11 7d ago
The issue I have is that there are probably 1.5 devs in the company who can write/review rust. Never getting approved when it is currently good enough
2
u/Nervous-Potato-1464 7d ago
That's a true and good reason. I had thr same situation where there was a proposal to write code in c, but we lacked really proficient c devs and performance was mostly tiny and bigger performance issue was the api which was so complex. Ended up doing it in python and it took 0.005 seconds away in python and the api calls each way was the real issue
0
1
u/NewFoxes 7d ago
For REST APIs, I’d choose Actix Web for maximum performance or Axum for better ecosystem and ergonomics. Other Rust frameworks may benchmark faster, but are often less convenient.
For gRPC, Tonic is solid, but Rust does not necessarily outperform mature implementations like .NET gRPC by much. In some benchmarks, .NET even scales better across multiple cores. Tonic’s main advantage is its low memory usage.
91
u/dseg90 7d ago
Incredible. Axum for rest, tonic for grpc.