Announcing Actix Web v4.0
github.com
github.com
I started learning Rust recently and usually start learning new languages by building different kinds of Hacker News clients with the language. This time I focused on a offline-first desktop HN client, that fetches items periodically and allows the user to browse it in a desktop app built with Tauri.
While developing this, I started writing a API with Actix Web at the same time, so the same service could be used directly in the browser, not just with the desktop app. So I found Actix Web to be the most supported.
However, I jumped into the RC versions (in order to use tokio >v1 which I was already using for other things, and you can't mix versions), while most human-written documentation (website, Stack Overflow, forums and such) were written for the pre-4 version. So I'm glad to see it finally released, and can't wait for all the documentation to/web resources to be properly updated as well so I can learn more about Actix Web.
Great work on creating a nice library folks! :)
Good luck though
Running it over at https://ditzes.com, source code at https://codeberg.org/ditzes/ditzes
Waiting for reaching alpha status before I post as a Show HN, want to have the desktop builds publishable before then at least too.
Actix Web 3.0 - https://news.ycombinator.com/item?id=24514212 - Sept 2020 (108 comments)
ExpressJS vs. Actix-Web: performance and running cost comparison - https://news.ycombinator.com/item?id=22456796 - March 2020 (53 comments)
Actix – Actor Framework for Rust - https://news.ycombinator.com/item?id=22316491 - Feb 2020 (126 comments)
Actix Web – Project Future - https://news.ycombinator.com/item?id=22099335 - Jan 2020 (38 comments)
Rust framework actix and actix-web are dead - https://news.ycombinator.com/item?id=22096616 - Jan 2020 (35 comments)
A Sad Day for Rust - https://news.ycombinator.com/item?id=22075076 - Jan 2020 (991 comments)
Actix project postmortem - https://news.ycombinator.com/item?id=22073908 - Jan 2020 (397 comments)
Actix Web: Optimization Amongst Optimizations - https://news.ycombinator.com/item?id=21962195 - Jan 2020 (14 comments)
Actix-web 1.0 – A small, pragmatic, and fast web framework for Rust - https://news.ycombinator.com/item?id=20104619 - June 2019 (147 comments)
Actix: a small, pragmatic, and fast Rust web framework - https://news.ycombinator.com/item?id=17190705 - May 2018 (123 comments)
Almost every time I've ever tried to silence the type checker (in any other language) it resulted in a bug.
Does it make you slower? Definitely at times, but it's mostly OK, and the code is pretty damn clean. You can check out our repo to see how it looks[1].
Edit: we don't use Actix, we use Axum, but the same holds for Actix too.
What does it even mean? You can't silence a type checker.
[0]: https://www.typescriptlang.org/docs/handbook/type-compatibil...
[1]: https://github.com/integer32llc/rust-playground/pull/777
I still write Python for quick scripts, but if it's gonna be a page or more of logic I give up and write it in Rust. Compile times for quick scripts, in practice, don't really bother me, and cargo is fantastic for "just work please".
The problem is getting to that point.
I only tried Rust once, two years ago. The type system was fighting me all the way: the types different libraries were using were incompatible with each other, there was no obvious way to properly convert between them, finding proper signatures and behaviors was pain as many things were in traits or macros etc.
A lot of this comes down to tooling and ecosystem maturity, so things may have improved.
This aside, you'll still battle with the compiler. As to what you're battling depends on what you're building.
My point was that having the ability to perform "fearless refactoring" to improve architecture and adapt to changing needs of the software needs ruthless type system support to catch the non-obvious areas that you just broke and make sure that API contracts are still correct and to make sure you're not deserializing random stuff into `interface{}` or worse, `Any`, `Value` or `void *`.
Erlang would beg to differ, and it has been continuously running on systems with uptimes longer than rust has existed.
Rust is GREAT for that.
Is not the safety (borrow checker) but the combination of: Bare structs, enums, pattern matching and some traits (like Into) that make a breeze modeling business rules.
The last I investigated, there were many gaps where one had to "roll their own x" - as compared to something like Rails, which comes with a lot of functionality (and has a huge ecosystem of libraries to support it for stuff that's missing).
If you're familiar with Rails as well... can you speak to what I'll be missing when I work with Actix? Some things I know I take for granted are the ActiveRecord ORM, the session framework, the availability of gems to handle various authentication systems, caching, and a ready "out of the box" browser testing framework.
I know I shouldn't expect anything close to what Rails has to offer, and for hobby projects I don't have an issue with that, but I'm curious about just how far things have come.
My response has gotten fairly long, so I think I'm going to turn it into a blog post. Here's a start:
I can't tell you how far you may get with the ORM libraries currently available as I moved to parameterized SQL libraries some time ago. Others seem to get on just fine with diesel, the most popular ORM/query builder. It's very fast, too -- nearly as fast as the plain old paramaterized SQL libraries -- but parameterized SQL libraries are much more popular (at least 3 times more popular) if we were to just look at download stats. You can go a long way with those and roll a custom query builder helper should the need for it arise. There are a few popular async connection pools, deadpool being my favorite.
Actix Web had a fine session management solution, but it has recently gotten a lot of attention lately and a PR awaits for merging with v4 that makes it even better. Actix Web has a strong session management solution, with support for Redis already built.
In terms of authentication, there's a popular jsonwebtoken crate that handles all of the JWT related functionality. There are plenty of strong cryptographic hashing libraries for argon2, bcrypt or whatever you're looking for. There are oauth2 clients. There are hashicorp vault clients. Or, you could roll these clients yourself, if you were so inclined to. There are also systems such as those maintained by the ORY community, written in golang, that have intuitive APIs and can serve auth related purposes. Many options to choose from with regards to authentication and authorization.
There are at least two viable async http clients to choose from. You'll use either extensively.
In terms of caching, there's a pretty good redis client. There isn't a "cache aside" (aka cache-else-db) library in open source, yet. People roll their own and don't seem inclined to share them just yet. :)
Graphql story consists of 2 viable libraries, async_graphql and juniper. Neither is exceptionally better than the other, but async_graphql seems to be leading.
Testing in Rust is pretty good but relative to Python or Ruby it has a lot of room for improvement. I've learned a lot over the years through trial and error and would like to blog about it. The one situation that is difficult to handle in Rust involves end-to-end integration tests involving calls to 3rd party api's. If you wrote your own client, then you can design the client so that you can control URL's, but if you're using open source clients, you may not be able to control those URL settings. This makes it more difficult to route requests to mock servers. Using dependency injection and mock types is what people are doing at the moment to address this issue. There is a nicer alternative, and that involves running a mock server that handles request interception. This is a rather impressive category for open source development and anyone reading this should take a look at what people have done in go, node, etc.
I'm using actix-web for https://fakeyou.com and their websocket support for upcoming features.
It's incredibly productive and resilient. I've built proxies and other stuff with it too, and it performs swimmingly.
I do feel like the docs could be expanded a bit more, I got stuck when trying to write a middleware for example.
Congrats for the release!
I'm not really a web dev, though, so I may be wrong, or missing something.
Now that actix-web 4.0 is out I should be able to finally resolve one of the open issues/PRs, which I was waiting on 4.0 for.
There's no need for a deterministic memory managed language in web applications. GC languages such as Java and C# work just fine there.
C# and Java have vastly more libraries available to them than Rust.
Having sub-optimal behavior is usually a sign of poor design IMHO. But it's difficult for me to pass judgement without seeing the application code. Also, I doubt that Rust would be of any help in this case.
I'm planning for a rather ambitious project, but not sure if I should choose rust (the new shiny thing) or stick to good ol Go (while I do have some issues with it)
Actix is the most mature of the Rust web frameworks. Axum is new but very promising. Rocket is popular but development is stalled at the moment since the main developer has been going through some rough times.
Firecracker, the software AWS Lambda runs on, is written in Rust: https://github.com/firecracker-microvm/firecracker
Mozilla wrote Servo, a browser engine, in Rust. Part of it has been integrated into Firefox a while ago:
> Mozilla incorporated the Servo CSS Style engine in release 57 of its Firefox Quantum browser.
https://research.mozilla.org/servo-engines/
It’ll be used in Android: https://security.googleblog.com/2021/04/rust-in-android-plat...
It’ll probably find it’s way into the Linux kernel: https://news.ycombinator.com/item?id=29485465
Ok one bit of AWS runs on Rust.
C/C++ runs 99% of the the worlds software including OS's/browsers/GUI's/Compilers/Virtual machines/Games/Aircraft/Spacecraft etc etc etc.
"It'll be" same was said of Java
Mozilla wanted to push the boundaries of what's possible with a browser rendering engine and they felt like they couldn't do it safely with the existing languages, so they created their own. Doesn't that, alone, speak volumes for how useful Rust is?
> C/C++ runs 99% of the the worlds software including OS's/browsers/GUI's/Compilers/Virtual machines/Games/Aircraft/Spacecraft etc etc etc.
Now you're being disingenuous. Rust is still so young compared to those languages! Not to mention that the industries best served by Rust move glacially slowly compared to, say, the web. I bet we'll see significantly more adoption of Rust in 10-15 years.
This is from November 2020, I’d expect them to use it even more by now:
> But we also use Rust to deliver services such as Amazon Simple Storage Service (Amazon S3), Amazon Elastic Compute Cloud (Amazon EC2), Amazon CloudFront, Amazon Route 53, and more. Recently we launched Bottlerocket, a Linux-based container operating system written in Rust. Our Amazon EC2 team uses Rust as the language of choice for new AWS Nitro System components, including sensitive applications such as Nitro Enclaves.
https://aws.amazon.com/blogs/opensource/why-aws-loves-rust-a...
That's cool, I guess, but also not particularly interesting.
- I've found it extremely fast to work with and iterate.
- I've been able to meld a lot of complex use cases to it. In-memory caches, worker thread pools, etc.
- It works great with testing, CORS, MySQL, Redis, forms, json, uploads, S3 clients, etc.
- Serde + the expressive type system is incredible (this is more about being able to use Rust, but Actix plays so well with it).
I'm using sqlx for nearly typified SQL checked at compile time. If we get a jOOQ-like DSL, I'll be overjoyed.
also, I'm interested in how you structure your code. is everything a crate? or you work in a giant namespace with different structs (sorry if this doesn't make sense I don't know much rust)
> for request schema, do you know how rust/ actix supports protobuf?
That's a great question! The serde annotations make it look like it should work. If not, there might be a plugin for it. Actix has a rather vibrant ecosystem of utility crates.
I've used Prost for protos once before (it felt like the more mature option), and the build integration was seamless. I was frustrated with how the IDE handled it at the time (Clion+Rust), which is one of the reasons I'm not using protos in Rust today. The IDE couldn't work out the types and everything touching the syntax tree near protos was opaque to the IDE. It was over two years ago the last time I checked the status of protos in Rust, so there's a good chance the situation has improved.
I didn't use Prost with Actix in particular, which is why I can't really provide insight there. It should be quick to set up a test.
I'm using two monorepos: one for frontend (yarn/typescript/react for three websites) and one for backend (all Rust; two servers and seven jobs). If I'd lumped it all together, I would have investigated protos more seriously. I should probably investigate using them again in the near future.
> also, I'm interested in how you structure your code. is everything a crate?
I'm using Rust workspaces to organize the backend monorep. I have about ten binaries, and five library crates that are shared between the various binaries. I also have a few vendored packages that aren't available on crates.io (newrelic-telemetry-sdk, etc.) I was told Bazel does a good job with build caching, so I'll investigate using that soon so I'm not always rebuilding the world.
> or you work in a giant namespace with different structs (sorry if this doesn't make sense I don't know much rust)
With the way modules work, there's next to no need for that in Rust. It's one of the most hygienic import systems I've used.
Overall, I'm extremely happy with the setup and it's been really productive for me.
Is it say possible to run a production quality server that can handle hundreds of thousands of concurrent users on digital ocean lets say?
It's not clear to me as a "buyer" what its selling points are and what makes it uniquely different from other Rust frameworks
It's so situational that you cannot say outright exactly how much something cost in different scenarios. Doing so requires strict metrics about other things at the same time, and could only be done as an analysis of what happened, not what will happen in the future. Subtle bugs and things like just using a different data structure would impact the performance, down to the tiniest detail.
If you're so adamant to see metrics, you could use TechEmpower's framework tests, latest one placing 5th Actix in the "Composite score" (https://www.techempower.com/benchmarks/#section=data-r20&hw=...), as a result of being pretty high up in the specific benchmarks. But even with that information, it doesn't mean it'll be the 5th fastest framework when you use it.
I guess the point is: do you own benchmarks for the specific areas where you need it to be fast, calculate what your costs would be for hosting it, and you'll have your "performance/$".
Absolutely. I used to work as an SRE on Mozilla's WebPush infrastructure. Every running Firefox in the world establishes a connection to it; that means it peaks at tens of millions of concurrent connections every day. We could easily handle hundreds of thousands of connections on a couple CPU cores and gigs of RAM.
Although most connections were usually idle, we also regularly pushed messages to every connected client (e.g. when a collection in our remote settings service was updated).
It's written in Rust using Actix.
The number of open issues isn't a meaningful measure of the maturity or reliability of a project.
Seriously look at modern C++ it is very easy to develop high performance software in a modern language.
I'm a full time c++ developer that does Rust as a hobby, and I'm asking myself if we are talking about the same language. C++ is a clusterfuck of obscure features, 1 million different build systems and hacks upon hacks for even simple things like include guards, forward declaration of classes to not completely kill your build times and _many_ more daily struggles that are simply none existent in Rust.