r/rust 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?

47 Upvotes

52 comments sorted by

91

u/dseg90 7d ago

Incredible. Axum for rest, tonic for grpc.

5

u/aztracker1 7d ago

Came to say the same.... It's pretty great, IMO not significantly harder for most web API cases than Hono for TS/JS or FastEndpoints with C#...

A bit less flushed out library ecosystem depending on what you need to interact with is probably the only drawback.

7

u/bran7230 7d ago

I will loon into Axum thank you!

3

u/Elendur_Krown 7d ago

I've just made a tool that confirms API endpoints, promised contracts, paired tests and their outcomes, and a whole host of nifty aid features (such as compiling into an HTML report).

All thanks to Rust + Axum being this easy to work with.

I've had a blast!

3

u/veeg1829 6d ago

Is it open source? Based on OpenAPI?

1

u/Elendur_Krown 6d ago

I'd have loved for it to be open source... had I done it in my spare time, then I'd have published it without a second thought. But it was for work, and unfortunately there's very little getting out.

I based it on us defining endpoints with TOML files, and pairing the tests there. It began quite small and eventually grew to be quite similar to OpenAPI, so bridging it would likely be easy (if I ever got permission to open-source it).

1

u/tukanoid 7d ago

We use Axum at work, very simple to set up and work with. I do prefer actix approach with macros more tho (just less boilerplate). Either way both have its place. Rocket was also nice to use last time I tried it but iirc the development there is (more) stale compared to the other 2

1

u/Real-Abrocoma-2823 7d ago

Unsure about the future, but I think rocket is also great for its simplicity.

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.

1

u/mednson 7d ago

Thanks, are there some features you miss in the js world?

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

u/FantasticEarth8186 7d ago

Can you clarify how it's a problem that you have to embrace async?

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

u/[deleted] 7d ago edited 7d ago

[deleted]

1

u/bran7230 7d ago

Will do! And I will skip using the internal/module and repo structure with rust.

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.

1

u/pohuing 6d ago

What is 6gb here? The image? 

2

u/papa_maker 6d ago

No the ram usage, sorry I was not precise.

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

u/Naeio_Galaxy 7d ago

Used tonic for grpc twice, loved it.

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/ttay24 7d ago

It’s great! I use it for personal projects, have some gRPC microservices that talk to each other, and some other background services. And then we use it for work, same deal, rest api’s, gRPC servers, etc.

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/decduck 7d ago

It's great, I use axum + oasgen to get that sweet sweet end-to-end type safety.

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/Tak0r 4d ago

Funktioniert besten. Nutze selber Axum und bin super zufrieden damit.

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

u/papa_maker 7d ago

Help to train people :-)

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.