Is Rust web yet?
arewewebyet.org
arewewebyet.org
> Can I replace my Rails/Django/Flask already? Yup!
While I agree that you can try to replace Flask with Rust web frameworks, you can't do it for Rails or Django. Rust web frameworks do not let you easily test your application's database access layer nor provide advanced authorization, and lack other features that become necessary when your application becomes bigger.
If you don't need the performance that Rust provides, you should still go for Django or Rails. Otherwise you will end up reinventing them.
Sadly, I have reached a stage at which there are very few languages I trust anymore to actually not explode in unpredictable manners when push comes to shove. Rust is one of them.
Well, that's totally fine. To each his own. I push Ruby production code for 8 years now and I trust it.
I fully realize that some people love these languages. I've written pretty sophisticated applications in these languages myself (including video games), and they're definitely great for exploring ideas. But at this stage of my career, for applications that matter to me, I value the time spent maintaining code more than the time spent writing it, and I find that the balance that works best for me is to use a strongly, statically-typed language such as Rust.
YMMV
https://devblogs.microsoft.com/dotnet/embracing-nullable-ref...
Now, Haskell or (modern) Java or C# are good languages, too, and they're by far not the only ones.
If you wish examples of the kind of features I need:
1. I pretty systematically need to juggle with many threads; 2. I very often need to juggle with many processes, with non-trivial interactions (i.e. actual protocols); 3. I very often need to access the OS; 4. I pretty systematically need to juggle with sophisticated data structures and algorithms (think graph matching algorithms, or dynamic trees of dependencies between ongoing tasks); 5. I regularly need to handle distributed applications in which pieces interact through non-trivial protocols; 6. I pretty systematically need to ensure that the event loop remains responsive. 7. Whenever I interact with the rest of the world (either the OS or as a web client or server), I want to be sure of which piece of data is sanitized and which isn't.
Of course, every single of these task can be achieved in any language. It just happens so that:
1. Rust has the best support for threads that I know in an industrial language. 2. and 5. Rust's type system is the best I know to express protocols among industrial languages. I hear that Ada's type system is just as good, but I don't know Ada, so I cannot compare. I hear that Haskell's type system is currently being extended with linear types, so I'll need to test-drive that, too. 3. While there are other languages that are at similar level as Rust for such things, I don't know anyone that is strictly better. 4. and 7. Any language with a strong, static type system is good here, including Rust and all your examples. 6. Great support for coroutines is really useful. Many languages have it these days, including Rust.
Once again, to clarify, I'm not trying to convince everyone to switch to Rust. I'm just answering the assertion that the only reason to use Rust is performance. That's certainly not the case for me.
It's much more a safety that you do not crash, due to input, side effects, parallelism (locking) errors, mapping wrong types, derefercencing null in some edge case by accident, ...
Rust gives you a lot of guarantees here, that it is extremely fast is just the cherry on top.
Any GC language (Java e.g.) will give you that if you don't use C extensions.
And if you do use them Rust wont fair any better (or if you use libraries that use unsafe).
Although I should make a point that those kind of remarks don't come from the core team.
Yes, but that's the main allure of Rust. As for the rest (e.g. resource releasing, avoiding concurency issues, avoding not-exhastive mathces, injection, etc.), other languages have their own ways as well, including Java.
If those are your main concerns (and not also top-speed) I don't think Rust is worth the extra cost (learning slope, slow compilation times, single implementation, fewer libs and developer tools, etc).
Not really. That's often touted as the banner feature, but it's the expressive type system that really makes Rust a better candidate than, for instance, Java.
My main point in this particular discussion is that Rust has way fewer gotchas than most other languages used in the industry, including Python and JavaScript. Whether these gotchas are problems for your use cases, only you know. I know that such sleepless nights tracking such gotchas have killed my will to write and maintain large codebases in Python or JavaScript (or C++), at least for a few years.
Meanwhile, safety in a web application is domain-specific, and there isn't much a language can do to protect you. There aren't really Rust features that directly prevent SSRF attacks, or HTTP desync. In fact, my experience assessing Rust (and Go) web applications is that they intend to reincarnate web vulnerabilities that went mostly extinct in Django applications years ago; for instance, I'm virtually never going to find SQLI in a Django application, but Rust web applications are somewhat likely to build their own SQL queries. This will shock and upset some Rust developers to hear (all the popular Rust SQL interfaces force parameterized queries! they're thinking), but it's true.
I like Rust, and write more Rust than any other language lately. I'd say the same thing about practically any modern language compared to boring old Django, which is the Volvo of web frameworks.
I have nothing much to say about reliability and do recognize that writing in Python or Ruby means that you're also writing ridiculous batteries of unit tests to verify basic things like whether your setters and getters work properly, because the language essentially makes you check your own typos. I'm only talking about security.
Note that I'm not claiming that Rust is the solution to every problem under the sun. It just happens to be pretty much the sweet spot for problems I need to solve, which typically involve concurrency and/or distribution and/or new protocols and/or sophisticated graph algorithms and/or actual OS access.
> Meanwhile, safety in a web application is domain-specific, and there isn't much a language can do to protect you.
There absolutely is. Rust's expressive type system is a more important feature than the memory-safety guarantees for general purpose programming. This has significant impact on the ability to express security constructs directly in the code. Witness, for instance, the widespread use of typing to distinguish unvalidated and validated user inputs, such as Rocket's RawStr type [0].
Applying that technique can mitigate SSRF attacks without even knowing the details. You can worry all you like about SQLI in Rust, but in the code I've seen it's no more a concern than any web app, and likewise it can be enforced in the type system in a way that sure seems superior to "hope the dev only writes boring Python".
I'd agree with the general premise that, all things being equal, the security of something that looks exactly like everything else is higher than some novel construct. But I strongly disagree that there's nothing a language can do to help developers write secure applications, and I'd suggest it starts with an expressive type system.
[0]: https://api.rocket.rs/v0.4/rocket/http/struct.RawStr.html
Similarly: it's not at all my claim that Rust is somehow more susceptible as a language to SQLI attacks! The opposite thing is true: Rust, as a language, is far better situated to deal with them, because of expressive typing. But that's what could be, not what is. In practice, ironic or not, if you implement the same CRUD application in circa-2020 Rust and in Django, the Rust application is more likely to have SQLI.
The point is that unlike kernel code or browser components, where memory safety is most of the ballgame and Rust is a real game-changer, web application security is domain-specific. The language and its runtime are much less important to web security than what gets built on top of the language. And right now, even though Python is an objectively inferior language, more of the domain of web security is built more carefully on Django than what's available on Rust.
As to your points about what patterns are more likely in actual practice, I can't speak to that; I've only seen a handful of Rust web apps. But the ones I've seen absolutely do use type-foo to keep things straight.
> The language and its runtime are much less important to web security than what gets built on top of the language.
That's a great point. I would highlight, though, that what gets built (and how likely it is to have bugs, which is also pertinent!) is directly impacted by the language and runtime, so the two questions can't be neatly separated.
In the long run, will most users be writing the guts of, say, a session manager to support their CRUD app? No, of course not, they'll just reach for some shared resource. Is it easier to be confident that the Rust implementation of that library has a lower incidence of bugs? Today, no, because for the Django version you can rely on the major real-world use as evidence of reliability, but in the long run, almost certainly. Is it easier to be confident that the usage of the Rust version of the library is correct? Absolutely, since the invariants can be enforced by the compiler.
I think we're mostly on the same page here.
So if you actually care about these things, rust might be really poor, because you are spending time fighting the borrow checker instead of thinking about the security surface area of your system, and the language is optimizing for speed in a domain where the bottleneck is usually the network.
Whoever pays the electricity bill?
As far as I can tell, Rocket is still on 0.4.5.
Rocket's current released version is 0.4.5, and that version builds with a stable Rust toolchain.
error: failed to run custom build command for `rocket_codegen v0.4.5`
Caused by:
process didn't exit successfully: `/home/vlad/code/test-rocket/target/debug/build/rocket_codegen-f5b5d853ac3ddd89/build-script-build` (exit code: 101)
--- stderr
Error: Rocket (codegen) requires a 'dev' or 'nightly' version of rustc.
Installed version: 1.47.0 (2020-10-07)
Minimum required: 1.33.0-nightly (2019-01-13)
Edit: formattingThat said, with Cargo using the unreleased version is as simple as changing `rocket = "0.4.5"` to `rocket = { git = "https://github.com/SergioBenitez/Rocket" }` so it's not like you even have to clone it manually. You can even specify branches if you urgently need a PR and patch entire workspaces with forked versions and so on.
I haven't noticed that C# is faster than Go, or that it's as fast as Rust/C++. Except in selected micro-benchmarks, of course.
C# is at best in the same bracket as Go: https://www.techempower.com/benchmarks/#section=data-r19&hw=...
Compared to the golang version using fasthttp, which is non-standard and makes compromises to achieve speed, and I'd avoid it for production.
Can you expand on this comment a bit? I find testing in Rust to be fantastic. Rocket makes for calling test functions simply via standard rust in tests, though you’ll need to build some test harness boot strap for your DB, but you generally end up doing that in any language for functional/end-to-end tests.
You kinda answered your own question here. Rails and Django have built in support for end-to-end and functional tests, including database access in the same way as the normal app, all autogenerated. That is just table stakes for web frameworks these days.
From what I've seen, it's totally possible to use Rust for web development. However, there are tons of web frameworks in various languages that provide way more out of the box than you can find in Rust. These frameworks have had tons of time to mature - Ruby on Rails is 16 years old, Django is 15 years old, Laravel is 9 years old, and so on.
I think (and hope) Rust will get there eventually, but I think it'll take some time. There's a lot of hype, but speaking as a web developer who's interested in Rust I think there will need to be a lot more tooling and a lot of educational content before it gains any significant market share. I got my start with C/C++ before I ever touched web stuff, but I never got too far into advanced language features. That combined with not having written a serious C program in years makes Rust something I'd really have to commit to learning, so even though I'd love to have a faster better-typed alternative to PHP I won't be writing any actual webapps in Rust in the near term.
Basically, I think most of the people writing webapps in Rust will be Rust people interested in the web rather than web people interested in Rust for a while. There are of course organizations that do more complex stuff on the web and will jump on this sooner, especially places that use microservices and don't have to move their whole platform over, but many people building simpler sites with smaller teams will wait until there's a substantially larger ecosystem.
A big app takes years of work, and along the way you be building utility functions to easily stand up test data. It’s not that hard and you don’t need it all at once.
No one is saying that Rust dev will be as smooth as Django. In fact, there is another paragraph right below:
> While development might not be as smooth as something like Rails or Django, the Rust web development ecosystem and community is engaged and very helpful. A lot of work has been put into the web in the past few years, and we're getting there!
You can replace a Django app with Rust. While you might have to put in extra work to:
> test your application's database access layer
> provide advanced authorization
The main point that the author wanted to make is that Rust is suitable for scale web development. It might not be perfect, but we are getting there, and the ecosystem and community is very large, engaged, and helpful.
Care to share why? It provides a lot of useful information and curated packages for common categories. It is actually widely used as a reference for package selection. Just because you disagree does not make it "awful"
> If you can't get the nuances why Rails/Django/Many other frameworks are a better solution for writing a web server than I dunno what to tell you.
I'm enthusiastic about learning Rust myself, but it's not even remotely a replacement for Rails. Rails is, IMO, bar-none the fastest prototyping / solo dev tool for building CRUD apps that there has ever been. It made it possible to build a blog in under fifteen minutes in 2005. In 2020, it's even more productive and for an even wider variety of applications.
What Rust framework is even remotely similar?
But the development is experience and ecosystem is nowhere near (again, only speaking for rocket and I know a lot of work is being done to improve things) what you are used to from Django. For example, rocket's configuration system is quite limited (currently being reworked), poor cors support, limited test support, etc..
Again, not saying you can't do it, but it's not the same.
That's a strong statement. Anyone care to back it up? I've never used Rails/Django.
testing is well integrated, db access can be done through django's amazing ORM or, via raw sql.
you can get a fully functional REST API, with documentation, authentication, authorization, testing within a day's work (thanks django rest framework!).
also, there's so many django specific libraries out there, that if you need something (like, stripe support), you can just "pip install" it.
But the real benefit for me is reliability. With rust web apps, I feel a lot more confident that runtime errors have been properly handled. And of course you save some productivity because the type system means you don’t need to smother your code in unit tests like one normally does when they want to demonstrate their python or ruby code works.
To be fair, as a web developer by day, I still haven’t gotten around to trying to write any Rust in my free time. I am curious though. But after browsing the docs of actix-web and rocket, it seems a bit of a reach to say you could use these solutions in place of monolithic frameworks Django or Rails.
Maybe if they had said they could take the place of an Express/ Slim / Flask app I wouldn’t have rolled my eyes as hard. Wouldn’t these battle tested ‘micro’ frameworks be a better comparison?
Anyway, since I really know next to nothing about Rust, what would be the benefits for me to pick say, Actix-web over Slim to start a new project?
I get the feeling the best reason would be I’m already an experienced Rust developer and want to leverage that domain knowledge. Or maybe a team that already writes a lot of Rust wants to keep consistency over their repos.
This might sound like it could get cumbersome fast, but it's actually really simple in practice, due to clever uses of traits. UnverifiedInvoiceId implements rocket::FromParam, so I can deserialize it from a URL parameter. InvoiceId is only created in the serde::Deserialize implementation of an invoice-returning API response.
So a (significantly simplified) endpoint in the app might look like:
#[get("/invoices/<unverified_invoice_id>")]
pub fn get_invoice_by_id(
unverified_invoice_id: UnverifiedInvoiceId,
api_conn: ApiConnection,
) -> HtmlResponse {
// API "search" methods take unverified user input as parameters
let invoice = api_conn.fetch_invoice_by_id(unverified_invoice_id);
// API "lookup" methods take verified ids
let line_items = api_conn.fetch_invoice_line_items(invoice.id);
render_invoice(invoice, line_items);
}
I can't accidentally switch up things that don't belong together, even though under the hood they're all just unsigned ints.It is possible to do something like this in nearly any language with a type system.
Serde -> Zod (https://github.com/vriad/zod)
Diesel -> Prisma
Yet you expose yourself to concepts that are unique to Rust that do not enhance the developer experience (such as lifetimes). I don't need to worry about lifetimes in typescript and can just focus on shipping code.
Lifetimes is just one example, but there are others that create more friction than they provide benefit IMO.
But, to answer your core question, there are a few different reasons:
* Performance. The simple, straightforward Rust code will often be much faster than the usual suspects here. Sometimes, I/O is your bottleneck, but sometimes it's not. Maybe you only move some backend services over. npm is an example of a company that did this; some high performance services were implemented in Rust because Node was struggling.
* Consistency. Resource usage tends to be very flat. This helps with things like capacity planning, but also reliability (which is a later bullet point).
* Cost. This is directly related to performance, but also on a different axis: memory usage. We've seen people switch code to Rust, and while the performance doesn't change things for end users, the extra overhead means smaller servers, or less servers, which translates directly into $$$. There are some big, not super public success stories here I wish I could tell you about, but a public example is Rubygems. They had a lambda doing some log processing, and the performance benefit of Rust made things fast enough to move it onto lambda's free tier. Infinity savings! (Though of course it was actually from $12,000/year -> $0)
* Reliability. Back to the npm use-case, they had a lot of ops issues with Node. The Rust code ran for something like a year, year and a half, before ever having a single production issue. Static typing helps here, less variable resource usage helps here.
* Static types. Some people have come to prefer developing in a language with static types. Rust doesn't have a monopoly here, but it is among very few languages that have many of its features, and many of them don't check those previous boxes.
Of course, things aren't a panacea either. The ecosystem isn't as mature, even if this web page says it is. Async is great, but not perfect. Some people really do not like static types. Etc.
Thanks for the detailed response, I have an eyebrow raised :)
The memory usage part is where Rust is clearly at a stark advantage in that comparison.
I'm a generalist who wants to use great tools for my work. I've built a variety of systems, not just web applications, with Rust. The more I use the language, the more I learn and develop greater capabilities to do more unfamiliar work. I am on the fence right now about diving into video streaming/processing but already have a foundational knowledge that will lend useful to a Rust-based solution. Embedded product development, too. And mobile. Rust is being used everywhere, now, with success.
So, while you may get away with using slim for your web app, using Rust instead is a way of acquiring the skillset that is applicable across all software development. One may do web dev today, but security engineering tomorrow. Whatever the domain, Rust expertise carries over. Using Rust for web development is how you invest in a software engineering future. As a manager, one may argue that this is up to the programmer to do so in their own time, and not company time. Well, in response to that I recommend reading Steve's comment as to why you can't afford not to use Rust going forward. :)
The strict typing in graphql has made dataloaders orders of magnitude faster. The same code that makes our business logic clear makes it easy to figure out if graphql needs to resolve all those nodes with individual sql queries, one against the parent node, build some `IN (?,?,?,?)` prepared statement, or resolve from cache. String manipulation is definitely a bit harder, but otherwise the experience as a web app developer has been amazing.
An extremely cool new one is serde_pickle support (python's favourite binary serialization), which we're using to load tiny word-vectorization dictionaries in WASM. This lets lawyers collaborate concurrently on the same contract, and farms out the laptops/phones they're working on's GPU cycles to auto-draft the contract (e.g. type 8 words, and can see "85% chance this a non-disparagement clause -- here's some example language you can use. Here's some case law saying when it's enforceable and when it's not").
This is essentially the reverse of "with Electron you can now create native applications entirely in Javascript". Yes it works, but only with a lot of overhead that wouldn't exist by doing it the "straightforward" way.
A much smarter approach is to create hybrid JS/WASM applications, manage the UI in Javascript, move isolated standalone features (cross-platform code or performance-sensitive code) into WASM modules, and call into those WASM modules from JS.
For native applications, maybe a better idea is to drive the UI with native code, and use WASM to run "untrusted" external code (for instance extensions/plugins), because a WASM runtime is a lot smaller than a complete browser engine like Electron.
If you write Rust for WASM you could just use a native UI framework and target that instead!
I suppose they consider working with other languages, ecosystems and communities a smarter approach. Perhaps they have good reasons.
It's hard to get the binary size of WASM modules down to the size of minified Javascript, especially for code that calls into the browser anyway (e.g. for manipulating the DOM). Depending on what the code does it's not impossible, and sometimes WASM even comes out smaller, but this takes a lot of optimization and tweaking, and often developers are blind to this sort of problem (it mostly affects the users after all).
One cannot simply hand-wave those points away just because Javascript sucks (even ignoring the fact that JS hate is often completely irrational, I don't like the language either, but sheesh, C++ or Rust are not that much better).
Plus there's some other downsides such as likelihood that you might have to mix small amounts of Javascript as a second language into a WASM heavy solution based on another language.
However those are tradeoffs, and depending on the situation those tradeoffs can be very acceptable. A lot of enterprise software for instance isn't particularly concerned with those issues, and benefits strongly from the other very very significant benefits that can come from the other side of the tradeoff of avoiding the javascript ecosystem (not just language, but culture, tooling, churn and etc). Those benefits can include a range of things but I will just point out one theme which is increased stability and maintainability .. expressed in thing like type safety and refactoring tools, longer release cycles, less reliance on packages in favour of batteries included comprehensive language libraries, less pain with package upgrades, less pain with the canoninical way to use your framework de jour changing each year, less pain with prior art patterns being (gradually) rediscovered (and renamed) , and generally a culture that prioritises reliability and maintainability over the new hotness (or hotmess, depending on perspective!).
There's other situations, such as building the absolute fastest load time for a customer page, that tradeoff might not be appropriate. However to be fair there are other techniques for managing that, such as server side rendering and client hydrating of SPAs. Or gasp server rendered sites hehe with just a sprinkling of client interactivity if needed.
(Actually I think SPAs are usually not great at fast time to responsiveness, but that's really another discussion and lets not get sidetracked. The main point is the drawbacks are tradeoffs, and for many systems they are appropriate tradeoffs.)
Not sure I personally feel comfortable building my own authentication modules. The rocket example was similar to one I did in flask but with flask I didn’t feel like I was creating my own auth. Rocket guards and JWT left me feeling like it was much easier to make a huge mistake.
People think speed is the only advantage, reducing runtime debugging and providing a more secure, more correct front end, free null pointer issues and free of memory leaks and runtime type errors - rust just has the added bonus of being fast.
You're right some of the tools aren't quite there and if you move a rails-y app over to rust, you have a job ahead of you to assemble some libraries, but it is doable - the point is that you can put rust in production at web scale now.
Rails doesn't even have it's own authentication built in?
Seems laravel, might be closer to django, and with jetstream - it has an admin area baked in, which others don't.
Laravel is also just as, if not more performant (if you mix in swoole).
Authentication/Authorization - for me, this means something like Rails Devise, which gets you a full set of routes, controllers, and views for user management, including correct session management, account creation, password reset, all using best-practices for handling passwords, session tokens, and reset workflows. Instead, we get a few cookie and JWT widgets. Nowhere near ready.
CMS - they list 3 static site generators. A static site generator is all well and good, but it's nowhere near being a CMS. They not only don't have a CMS, but don't even seem to know what a CMS is or that they need one and that a static site generator is not a substitute.
Database - it at least does have some okay ORMs. But do any web frameworks integrate with them to the extent that you can set up test databases and run test suites with them automatically? Do any of them support validations? Last I checked, Diesel's support for associations is pretty bare-bones.
I've tried out Rocket. It's all right for making relatively basic API apps. And it still doesn't build on Stable yet, though that's hopefully coming soon. I like Rust for a lot of things, but it has a long way to go before it can compete with full-fledged web frameworks.
One thing I hate about rails is devise.
laravel new app --jetstream
gets me an app with admin area, profile page, teams, my choice of livewire (like phoenix liveview), or vue + inertiajs (spa w/out vue-router i.e. using laravel's native router), I also get 2 factor built into the auth layer.
Might be 8 hours of work just to get rails to have all that laravel brings from the scaffold command for a new project.
After spending too much time chasing down dynamic-typing related bugs in both of those frameworks, I find myself missing a lot of their feature set when I look at other frameworks. However, I'm tired of doing "defensive programming" in Python to essentially statically assert argument types and unit test things that a statically-typed language would disallow by construction.
This stuff in Rust, Go, and even Nim [0] look interesting, but the consensus seems to be the value proposition of Rails or Django is still hard to beat unfortunately.
I agree with other commenters on this thread that in general such benchmarks may not mean a lot when compute is so cheap and the autoscaling infrastructure is awesome, but I often work on embedded platforms or other resource constrained devices where adding the JVM is a nonstarter (not that Django or Rails is an option either in those cases).
Secondly, something seems off if a php framework is getting top place, unless it's doing some AOT compilation.
Security is probably the next biggest one. Vulnerabilities in the JVM are a problem but you'll have that in most software (given maybe only Flash beats the JVM in the history of boths existence) but the defaults for running a lot of things like groovy aren't secure (there is a debug port you can directly manipulate the memory of the running process without authentication). Commonly people use these debug ports in production, not just leave the defaults but actively choose to let them run. This is a very common pattern in Java based services usually caused by my first point. I am not aware of any other language or framework that offers remote memory access as a feature.
Then there are the dependencies and package ecosystem. I believe the "built on the JVM" languages like Kotlin have gotten a lot better at this, but as soon as you start tapping into the pure Java "enterprise grade" libraries you're most likely bringing in way more than you bargained for both in terms of complexity, maintainability, and security. A lot of those libraries are simply poorly built.
The JVM gives you practically every knob you need to achieve maximal performance for your workload. I don't know of any other environment that does that. Secondly, with new GCs like ZGC and Shenandoah, the number of knobs to tune (at least with respect to the GC) has decreased dramatically to only a couple.
> Security is probably the next biggest one. Vulnerabilities in the JVM are a problem but you'll have that in most software
This is a non-issue for backend systems. Barely anyone uses Java for browser-side rendering anymore.
While this is true, finding folks that deeply understand how those knobs work, (and what the potential pitfalls are of twisting each knob might be) is not as easy as finding a Java/Kotlin/Scala/Clojure/JRuby developer. The out-of-the-box JVM experience can take one quite a long way. It's that last mile to real performance that can be the nightmare.
That's because no other environment needs to. No other environment eager loads a quarter gig of ram to say hello world. The fact that you need to know at least 16 flags for the JVM with obscure syntaxes to get a basically stable Tomcat server (not Tomcat flags, those are another nightmare) is precisely the problem with Java.
> This is a non-issue for backend systems. Barely anyone uses Java for browser-side rendering anymore
You've got to be trolling on this one. I'm definitely not talking about browser-side rendering. Weak backend systems are exactly how Fortune 500 systems get breached over and over and over. This was exactly the cause of the Equifax breach and so many others. You should never think that is ok.
This is just hyperbole and you know it. The JVM with the turn of a few knobs is able to accommodate high throughput batch workloads, as well as lower latency workloads, especially with the advent of ZGC and Shenandoah, all while supporting multi-TB heap sizes.
Look at what hacks the Discord and Twitch teams had to endure to get around golang's workload specific GC for example, and it will show why the JVM is written the way it is.
> Weak backend systems are exactly how Fortune 500 systems get breached over and over and over. This was exactly the cause of the Equifax breach and so many others. You should never think that is ok.
Those were not JVM-specific issues, and would have happened regardless in any hosting environment or even compiler if we're talking about running single binaries. You need a good upgrade path process laid out.
https://stackoverflow.com/questions/37738106/net-core-vs-mon...
I must admit that I've been tinkering with this debugger for about 11 years. (Used to be MonoDevelop, then Xamarain Studio.) It used to be very unstable. Now it's usable.
YMMV
For runtime-checking based on PEP484 type hints, one can complement this with a library like Pydantic/Enforce.py/typeguard/typesentry. Enforcement of the types is typically opt-in per function call, often by adding a decorator.
In the Java world people just use jdbc and wrap it with a threadpool and expose it as "async", but in rust it is truly async down to the system call.
Go, Python, C# have native implementations as well, e.g. the de facto standard Postgres driver for Go (which is by the way super fast), https://github.com/JackC/pgx
But why should one choose Rust when there're plenty of alternatives with much larger and much more stable ecosystems. And those alternatives offer much higher productivity and a much larger talent pool.
Rust is not even the fastest web framework (https://www.techempower.com/benchmarks/) . And the benefit over Java, C# or Go is really negligible. Who needs more than 300000 req/s and can't afford servers to scale?
So, another nice try from the Rust evangelists, but no thanks.
What I think differentiates this from normal outreach and education that every project needs to do to build a community is the sense of entitlement and the declaration that they're outright hostile and argumentative and then expect to be engaged.
I think a problem exists when that something new is being pushed and hyped in order to create a self-fulfilling prophecy where everybody starts jumping on the bandwagon and an ecosystem is built.
From a management positions this is probably the most important question you can ask. Your most expensive resource is your programmers, and a few talented operations guys, and you need a good reason to expend those resources.
We work rather closely with other municipalities, and one in particular is very adoptive of new things. One of the things they adopted was kubernetes. But the thing is, we’re not Netflix, and kubernetes isn’t easy, and the result was they spend two years worth of man hours on something that didn’t make them anymore competitive than us because the advantages never really comes into play in our small enterprise organisations.
We spent those two years worth of manhours improving our Azure strategy, getting our operations guys up to speed on powershell and our developers on python, and actually moved our organisation forward in a manner that was useful.
Maybe Rust is useful, maybe it’s going to have a brighter web-future than .Net Core, but if you can’t show me how that is, or why I should adopt it, then it’s a really big risk that I’m happy to let other people take. We can always adopt it later.
Of course you probably meant to ask the question in a different light, and I think that point is very valid. I just can’t stress enough, how little something being all the hype actually means. What if Rust turns out to be another Ruby on Rails or “Node.JS for everything” craze? Then I won’t lose any sleep over never having thouched it, and if you look at our local job market, then there hasn’t been a single Rust focused job in my entire country for two years now. Not even as a “nice if also you know” listing. That doesn’t exactly install me with confidence that Rust is ever going to be important.
In my experience, and this is just a data point: because it is much simpler to write correct Rust code and to refactor large Rust code bases correctly than doing the same for Javascript, Ruby, Python, C++, C, Java, etc.
That Rust has great perf and uses little resources is just a bonus, but not something that most apps will care much about.
The downsides you mention about the ecosystem, libraries, frameworks, are real.
I disagree with your claim that there is no "talent pool" for Rust. The "talent pool" for javascript or C++ is _only_ "all javascript experts" or "all C++ experts" because if you are not very good at Javascript or C++, you can't really be trusted. A Javascript programmer can start being productive in Rust without issues quickly, but the same wouldn't be true if they had to program in C++ instead.
The "talent pool" for Rust is "all programmers with domain knowledge". If they are not experts in Rust, that doesn't matter. Smart people you want to hire all pick up Rust very quickly, and the amount of dangerous mistakes anyone can make by not being a Rust expert is very small.
Offer/demand wise, the demand for Rust jobs is much higher than the Rust jobs that are currently available. If you post a Rust job on reddit you'll get 100 CVs in a day...
---
IMO, your main point still holds: right now Rust web frameworks are not as feature full as Django, Rails, etc. and if Rust frameworks are missing features you need, picking it up for a professional project probably doesn't make sense. Unless... you are willing to implement those features yourself...
C++ is not a good fit for network accessible services. It is too easy (even with Modern C++) to cause memory based security problems (and I say this as someone who writes protocol stacks in C and C++ for a living).
Rust's security story is much better out of the box.
Occurrences of unsafe in: Actix-web: 39 A few dependencies Regex: 136 Bytes: 118 Tinyvec: 8
That’s far from exhaustive. So I wouldn’t consider this implicitly safer than any particular C++ library that has been through some basic static analysis. If anything, there probably have been way more eyes on STL. I would be even less confident in this case since the author of Actix who probably actually knew what he was doing was harassed out of his own project by the friendly community.
I get the safety for performance trade off, but Rust evangelists pretend this trade off never happens, and it’s very pervasive in important libraries.
I don't have personal knowledge of the use of unsafe in Actix-web, but yes I agree that it's not ideal and I would prefer to use an alternative. On the other hand, it is a library used by a number of projects and so security problems are more likely to be surfaced (and I get fixes for them for very little effort).
I'm more concerned with how easy it is to create security holes in your application (when built in a way encouraged by the framework), and it is definitely easier in C++ than Rust.
Exactly companies who can afford to scale. If you could switch from Python to Rust and reduce your server costs by 10x, why wouldn't you?
I'm quite impressed by Microsoft's Blazor and .NET Core teams working on improving Blazor's performance and decreasing the system bundle's download size. Blazor's performance in upcoming .NET 5 is reported to be already 2-3x better than in .NET 3. I expect that ongoing work on ahead-of-time (AOT) compilation to WebAssembly, including an ability to freely mix AOT- and JIT-compiled code (expected to be shipped as part of .NET 6) will further improve Blazor's competitive position vs. Rust's WebAssembly from the performance perspective.
Blazor has two separate modes, 'Server Side' and 'Web Assembly'.
What you're describing is the server side mode.
The second mode, called Web Assembly, compiles your code to WASM that is executed in the browser.
https://docs.microsoft.com/en-us/aspnet/core/blazor/hosting-...
Also, "The .NET 5.0 core framework libraries have been annotated to indicate what works in the WebAssembly runtime, so developers now get a warning in the code editor when attempting to call an unsupported method." from https://www.theregister.com/2020/10/15/microsoft_emits_net_5...
Rust - 15/2462
C - 71/2462
Go - 105/2462
Kotlin - 109/2462
Typescript - 147/2462
C++ - 193/2462
C# - 221/2462
Java - 544/2462the failure of rust was it tried to start from scratch where better solution would be to seamlessly integrate into c,
maybe if gcc has support for compiling rust the future switchover on embedded would be easier
The ecosystem needs to settle and stabilize a bit more before it reaches deep adoption in the industry as a whole. If you're a lean "disruptive" start up then you probably don't mind using more experimental technologies but big, established companies like to have a more long term vision. You don't want to have to rewrite half of your software 5 years from now because nobody uses FancyLang anymore.
So what's the point? Python was created in 1991, in 2000 was more popular than Rust is today. Rust was created in 2010, so it is older and in a world where it has to compete with more languages. Reality is different of what you wish to be true.
laravel new myapp --jetstream
And have SaaS style teams, admin area, authentication, 2-factor, tailwind layouts, and vue+inertia all configured for me, so I literally just need to build the unique feature parts and not worry about auth/sessions/etc?
Forgive my ignorance (I haven't done front end web dev in almost a decade), but what is the use case for WebAssembly? What does it enable websites to do that (1) needs to be done within browsers and (2) can't be done with JS?
Also, are there any prominent websites that use WebAssembly? It's shipped with all browsers, but what percentage of users ever make use of it?
[1] https://www.figma.com/blog/webassembly-cut-figmas-load-time-...
What they did was cutting it to 30% or by 70%.
newLoadTime = oldLoadTime - (70% of oldLoadTime)
newLoadTime = oldLoadTime / 3
Personally I find the additive expression unintuitive and find the multiplicative expression easier to reason about. "cut by" does generally indicate an additive expression. It should really have been phrased as something like "reduced by a factor of 3"
Factor, noun "a number or quantity that when multiplied with another produces a given number or expression."
It's not an exact integer factor, but I think the concept of factor is more general than that.
That would imply the phrase has to be "reduced by a factor of 1/3", which leads to the wrong impression. The better technically correct phrase would be "reduced by a divisor of 3"
TL;DR: - "almost fast as native code for web browsers” - in case you wanna do some expensive computing without a server - "Compiling Existing Applications for the Browser" - port existing code into the browser (eg cpp apps)
e.g you can develop parser in console application and then ship it to the browser and use it there to parse e.g code without changing a single line of code or having to do some bullshit or traspiling it to js.
Once it matures it will allow you to get rid of writing javascript and use java, c#, rust, c++ and many other to write frontend.
More seriously, one of the main draws is being able to us the same language on both the front and back end, which might be beneficial to reduce the need to duplicate model or just to be able to develop on the front end in ones preferred language.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
JS doesn't have integers; all numbers are represented as doubles. One of the reasons having actual integers is important is performance, as integer operations are often faster than floating point operations. BigInt doesn't help with that.
I have a web app where every time there is an error on the client side it sends it back to the server. On normal JS it locks up the browser for 10+ seconds. In WASM it's instant.
Never found another use except for this.
Weird, I think I do the same thing (global exception catcher) and it works fine
I think the core use case is "Being something that's not Javascript".
The desktop programming world gets benefit from having multiple languages that suit different use-cases, so why would the web not?
Personally, it allows me to write tools that can run either on the command line or in the browser. Only the user-interface need be rewritten - internally both versions can share a lot of code.
WebAssembly makes it possible to do this using a language other than JavaScript. However, the languages I can use are still limited - AFAIK WebAssembly is currently only well-supported by C, C++ and Rust.
There is no access to the DOM and the POSIX-like WASI interface is limited so the main use case is reusing code with manual memory management (C, Rust, etc).
WebAssembly also targets server-side JavaScript runtimes like Node, Deno, and Cloudflare Workers.
I would recommend Rust over Typescript, if you are going to spend time on types, use Rust it's more worth it.
I tought about using Rust instead of JavaScript for frontend for some time.
On the one hand, Rust is a step back, because there is quite some things you have to do more than with JavaScript.
On the other hand, Rust has an interesting type system that could save you in the long run and things like pattern-matching and expressions everywhere is even a direct usability improvement over JavaScript.
So it's not, Rust is more low-level than JavaScript, that's why it's bad for frontend, but more, Rust is different from JavaScript some parts are harder, some are easier.
I would recommend to use the best tool for your problem. If you want to display a button and manage click events, don't use Rust it's not worth it.
So the vast ecosystem and ready functionality offered by typescript or other high level languages is worth less than what exactly?
The main advantage for me is the monad. Sure you could use monads in typescript or even vanilla javascript but in Rust, everything uses monads.
The vast javascript ecosystem is available to rust in the browser too. Server side it's not as big and I agree javascript has a point there. But now, if you look at the ecosystem of libraries with proper and up-to-date typescript definitions, well it's not that great.
---
Things I like:
- Modern type system. Sum types, Option type etc
- Strict compiler. If it compiles, it works.
- Great error messages.
- Mature package tooling. Cargo is at least as good as npm.
- Mature GraphQL packages.
- Decent cloud support. Github actions, Container guides.
---
I've been running it in production for a while, usually as a remote schema for Hasura: https://github.com/ronanyeah/rust-hasura
Deploy pipeline:
- Push to github
- Github action builds binary
- Github action pushes binary to AWS ECS in a container
- This triggers a rebuild of the AWS Fargate service which restarts with new Rust code
Web is high level scripting, and lower level languages can be used by those high level languages to provide the required speed. The performance of those languages do increase over time with new hardware and discoveries. You can hardly do better than the concise syntax of php or python, depending on your preferences, in terms of performance vs code length.
To me programming has always been about obeying the KISS principle. Does using rust for the web corresponds to that principle? I'm unconvinced. Compare rust code to php code. php might be slower to process big operations, but big operations shouldn't be left to php anyway. php is a high level scripting language. Contribute to php and writing an extension would be a better way to go in my opinion. This or another scripting language.
The best language to use is the one you know how to use best. If you know all languages equally well that you're free to choose the ideal language for every project, then sure, that's the way to go.
But you are right, reality often goes differently than what's thought to be ideal, which is why "perfect" solutions sometimes doesn't gets adopted in favor of a less perfect solution, which leaves the old "perfect" solution forgotten by history.
The performance aspect (aside from WebAssembly, where it has few contenders) is something that can be partially matched by other technologies.
By comparsion, developing for the web in Crystal is quite enjoyable. The language has great ergonomics (I'd say even better than Ruby). The web ecosystem might not be mature but it's blooming and it has you covered in the main areas. Most importantly, if you're missing something, it's very easy to build it yourself. The standard library contains a lot of web goodies, including a very decent HTTP client, a server, easy to use and fast JSON and XML parsers, an OAuth2 client (yes!). The language feels like it was built for the web, which I can't say about Rust.
In the end, what matters is your use case and the trade-offs you are willing to make (development speed vs. performance vs. safety guarantees). If I would have to build a load balancer, I might consider Rust. For a normal web app, I'd personally go with something like Crystal, Ruby, Python, Node.
I've never used FastAPI, but https://www.techempower.com/benchmarks/#section=data-r19 (which is the first thing TechEmpower shows me) says that for this specific test (and maybe others are different, you should look into it!), FastAPI does 52,080 RPS, and actix-core does 651,144.
https://dev.to/krowemoh/a-web-app-in-rust-17-conclusion-1njd
For the most part you could replace most things with rust but you'll be rolling your own solutions for things that other frameworks already supply. Actix was great to use and has enough middleware that I feel comfortable using it.
I don't see any reason outside of desire though to use rust and actix, python and flask are basically the same thing but easier to write. Luckily I like the language and it is fun so for now I'll continue using it.
It could be rust will be better once you have business logic where the borrow checker could really shine, just making a simple crud is too much glue work such that any programming language would work.
Only if you REALLY need it, like if you're embedding a web server into an existing Rust service. Otherwise, it's going to be very time consuming to do things that are straightforward in other languages.
(TLDR: A Rust++, or "Objective Rust" that simplifies some memory issues could make Rust web ready.)
For the past few months, my occasional hobby has been trying to learn Rust. BUT, I've also spent a considerable amount of time getting up to speed in NodeJS.
Regarding running Rust in the browser with WebAssembly: I've spent DAYS trying to figure out how to hook callbacks into the DOM cleanly. I basically went through the "Game of Life" walkthough, (https://rustwasm.github.io/docs/book/), and then ported all of the JavaScript sides into Rust. Trying to make registering a callback from the DOM as clean as implementing a button click handler in C# is just a nightmare.
The problem is that Rust just isn't good for complicated object graphs. This is where almost any language that's garbage collected, or uses some form of automatic reference counting, shines. And, if you're building a "normal" web application, Rust isn't going to have tangible performance advantage over Java / C# / NodeJS / Python. (Meaning, if you aren't running at Google Scale, there's no tangible performance advantage for Rust.)
Part of what happens in Rust is that it's very hard for a struct to reference itself so it can register event callbacks. You're forced to either make all users of the struct use reference counting, or you have to encapsulate a reference counted type used with callbacks. In a garbage collected language, this kind of hurdle isn't needed. In reference counted languages, registering event handlers just requires a weak reference to yourself to avoid cyclic loops. This is because GC / ARC languages assume the same memory model for all objects; which isn't the case in Rust.
Anyway, to make Rust easier to work with, it needs a way to trade some of the raw, "0-cost-abstraction" advantages for the advantages that come with GC / ARC languages. Need raw performance? Use pure Rust. Just need to get it done? Use a higher-level syntax.