9 ms·
Rust for web development: 2 years later
- nafizh 6y ago"Rust is a real pleasure to use for web development, and I thoroughly recommend it. It is so versatile that, without a doubt, it’s the last programming language I learned. Ever." This doesn't inspire much confidence in the evaluation of the writer.
- nesarkvechnep 6y agoSounds pretty immature.
- sylvain_kerkour 6y agoI sincerely believe that Rust is here to stay!
- loloquwowndueo 6y agoJava is a horrid language and it’s here to stay. I don’t understand your point.
- zepto 6y agoAlso, when Java first came out, people loved it because it was way more productive than C or C++ for a lot of things because of the presence of garbage collection, and the simple type system. It really didn’t seem horrible back then.
- sylvain_kerkour 6y agoHey author here, I Would love to know why :)
- __s 6y agohttps://en.wikipedia.org/wiki/No_Silver_Bullet https://en.wikipedia.org/wiki/No_Silver_Bullet Praises are generally dismissed when they seem to contradict this principle
- sylvain_kerkour 6y agoNever heard about that before but I will dig the matter for sure. That being said I'm sure that rustaceans disagree about the "No Silver Bullet" part (when you can compile to WebAssembly, write HTTP / TCP servers, embedded development and much more).
- Jare 6y agoI love Rust, but I'm pretty sure it is not the best language for exploratory programming or quick prototyping.
- lostcolony 6y agoEven excluding network and org effects - For distributed problems I'd prefer something like Elixir. This may even be true for web dev (I admit I haven't explored it as much in Rust; just, a lot of what I've had in web services is IO bound, with strong process isolation expectations, and that's perfect for Elixir) For heavy math, Julia or maybe Python + libs. To build a DSL, a Lisp. For something largely integrative of other libraries, whatever language those libraries are built in. For certain types of problem solving and optimization problems, a logic language like Prolog. Etc.
- waiseristy 6y agoNo no no... You're just not using enough Rc<RefCell<>>'s /s
- nicoburns 6y ago> I'm sure that rustaceans disagree about the "No Silver Bullet" Rustaceans tend to be a pretty practical bunch, so I'd imagine most of them do agree with it. It was also the one part of your post I didn't agree with (if taken literally)
- Kinrany 6y agoI found myself agreeing with both of you at the same time. I'm very interested in programming languages and expect new and better ones to be discovered in the future. At the same time yesterday I noticed that I'm not as hungry for new languages as I were before: Rust is good enough that I can live with it being the last language in existence.
- chewbacha 6y agoI simply read it as hyperbole and facetious. It made me chuckle.
- ampdepolymerase 6y agoRust is usable for web development if you consider vanilla Python Flask without extensions to be the pinnacle of all web frameworks. The abstraction level in non-nightly Rust frameworks is shockingly bad. Standard features like diffing and generating migrations that are found in mature ecosystems like Django/Laravel/ASP.NET/Prisma are non-existent in Diesel. There is no maintained, out-of-the-box authentication solution. The only framework that try to tackle some of these problems is Rocket and it has been perpetually in nightly despite stable Rust compatibility having been achieved last year. (Companies using Rust need to donate and sponsor more)
- sylvain_kerkour 6y agoHey, I updated to specify that I'm specifically talking about JSON APIs.
- ampdepolymerase 6y agoI agree,Rust development for microservices and JSON APIs is quite doable. Your new book looks quite exciting. Is there a preview somewhere?
- sylvain_kerkour 6y agoThank you! No preview is available today (I don't have enough bandwidth available) but it's on my todo list. Please feel free to subscribe to the newsletter where I will announce when it's available :) https://kerkour.com/subscribe https://kerkour.com/subscribe
- ampdepolymerase 6y agoSubscribed! Bloom is really cool, what's the current status on it?
- z0mbie42 6y agoThanks again! I'm working on it 2 days a week beside writing the book. The next major milestone is receiving emails in the inbox, but I think it will take 2-4 months to have it working.
- the-smug-one 6y agoRust's IDE situation is just not good enough yet. rust-analyzer + emacs incurs constant high CPU usage for me.
- pixel_fcker 6y agoI get the same with emacs (gccemacs nativecomp) but it works just fine in vim and vscode.
- afavour 6y agorust-analyzer with VSCode works fantastically well for me.
- endisneigh 6y agoWhat's the advantage of using Rust for web development vs. JavaScript (for example) and using Rust for specific tasks as necessary? The Node/Rust interop is decent enough.
- loloquwowndueo 6y agoOnly a troglodyte would use JavaScript for server-side programming. And you can’t use rust for front end work. So you’re kind of asking for what the advantage is of an apple over a backhoe - the comparison makes little sense.
- frenchy 6y ago> Only a troglodyte would use JavaScript for server-side programming. As a troglodyte myself, I don't disagree with you, but you're being unnecessarily demeaning. > And you can’t use rust for front end work. You certainly can (for example https://yew.rs/ https://yew.rs/), but as usual there are certain caveats and limitations.
- nicoburns 6y agoIt's much simpler to use one language rather than two. And Rust code isn't much harder to write than JavaScript (especially if you're using TypeScript). Rust also gets you: 1. Better performance 2. More importantly: much better safety guarantees. Rust web services tend to be set it and forget it. They don't break. they don't crash. They only rarely have bugs.
- afavour 6y ago> Rust code isn't much harder to write than JavaScript As someone that's coded in both... eeeehhhhhhh Memory management in Rust can be a real bear. Just, for example, creating a closure that references a variable outside of its scope is not simple. You can make your life a lot easier by wrapping everything you reuse in Rc<> to make it reference counted, but then you're eating into the performance gains that are the initial selling point, and after a certain point you're just manually implementing the things that JavaScript does for you. Don't get me wrong, I love Rust. But I wouldn't want to use it everywhere I use JS/TS today.
- raverbashing 6y agoI'm really not sure. I like Rust but I think it's too "low level" for web development. Ok, it's a better C++ but I wouldn't use it for web development neither. (And yes I agree with the points raised) For a specific component of a web service where performance is very important absolutely. For a direct connection from a customer or an app, only in very specific cases.
- paulgb 6y agoThe thing with Rust is that it has a lot of low level features, but you can actually get a lot done without using them. I have found that most data pipelines can be implemented without ever explicitly having to specify borrow lifetimes, for example. To the extent that it is more difficult to implement things in Rust than (say) Python, I’ve found it’s usually because of lack of libraries (although this is much less often the case these days) than the language itself getting in the way.
- tapirl 6y ago> When in Node.JS or Go a medium-sized service’s Docker image takes 5 to 10 mins to build and deploy, I guess you build Go binary in building the docker image. You should build Go binary then build the docker image instead (5 seconds duration). One the other hand, even if you build Go binary in building the docker image, 5 to 10 mins duration is still not a typical build duration for most medium-sized Go projects. One minute is enough.
- steveklabnik 6y agoWe are using Rust for backend development at Oxide; two of my co-workers (who are the ones doing the work) laid out why they chose to do so: https://www.youtube.com/watch?v=EmSjZbSzA3A https://www.youtube.com/watch?v=EmSjZbSzA3A If you asked me five years ago, I would have said "never." I was just asked this ten minutes ago, and my feelings are now "depending on your constraints, it can make a lot of sense, but I don't think it's going to be something for everyone."
- k__ 6y agoI was thinking about how difficult it would be to use Rust on FaaS for a web service. Could be a good fit, since most of the web related stuff would be handled by an API gateway.
- steveklabnik 6y agoYou can write at least AWS Lambdas and Cloudflare Workers in Rust, supported by upstream. Maybe other platforms too.
- ducktective 6y agoI didn't understand Oxide's goal. You want to build a "computer" specifically designed for server and cloud. But isn't that actually CPU and general hardware design (like ASIC/FPGA/etc)? What does Rust have to do with that? Are you trying to implement Rust's high-level programming language concepts in silicon so the generated assembly would run faster compared to amd64 or M1 or whatever-used-in-servers?
- steveklabnik 6y agoWe are (well, will be) selling physical servers, yes. It involves a lot of that sort of work (hardware design). But we are also writing a lot of software, from the firmware up. And it’s all in Rust. My job responsibilities are firmware/os dev stuff, these folks are working on the higher level stuff. I believe they went over the context in their talk, but haven’t watched it since they gave it, so maybe I’m misremembering.
- rajin444 6y ago> Once it compiles, it works (usually). How does Rust help prevent logic bugs? I thought tests helped prevent logic bugs. Or does the author mean "works" in that it runs where an interpreted language would not (i.e, syntax error)?
- pitaj 6y agoThe type system is very powerful. Enums help prevent a lot of logic errors.
- chewbacha 6y agoWhen I repeat this I’m generally talking about type-tests versus logic-tests. In dynamic languages, you only know if it’s fails at runtime so being statically typed eliminates a category of specs. Rust excels here, in my mind, because of its expressive type system which can allow you to encode logical building-blocks as types and hoist the logic into the type system, eliminating even more specs in favor of compiler errors. Ultimately, with a sprinkling of logic tests, you can feel confident that compilation means success.
- Dowwie 6y agoRust compiler isn't going to tell you that your mortgage amortization logic is incorrect. You're still going to need to write tests to validate that the business logic is correct. However, the way that the calculations are implemented can be done in a way with Rust that offers higher levels of confidence about how systems will behave in production.
- andoriyu 6y agoWell, Rust (or any language) won't prevent business logic bugs. > Or does the author mean "works" in that it runs where an interpreted language would not (i.e, syntax error)? More than that, but close. i.e. you won't get NPE from java. Syntax error or type mismatch from interpreted language. In addition, NewType pattern will stop you from passing seconds into a function that takes ms and vice versa. You won't get data races. You also won't get an `undefined is not an object`. Long story short, due to language verbosity it's hard to make logical mistakes.
- atarian 6y ago30 minutes to build Rust in a container? Why does it take so long?
- fafk 6y agoHe's probably using Docker with Mac/Win, which runs a linux VM. The rust compiler doesn't like being run in a VM like this. It's fast on Linux where containers are native.
- stusmall 6y agoThe last place I worked at had pretty similar build times for one rust service. Right before I left we ended up finding some low hanging fruit to trim that down to 15-20, but that's still pretty gnarly. Build times can pile up pretty quickly as systems grow over time. I have to say with that code base the big sin was some extreme macro misuse. It's still possible to see times like that without heavy macro usage though. That was a native linux build on a fairly modern i7 laptop.
- amelius 6y agoWeb development without garbage collector sounds like a bad idea. Rust wasn't designed for this.
- tom_mellior 6y agoThe author does seem to use Rc and Arc references, which collect garbage using reference counting.
- kitkat_new 6y agocould you provide any reasoning for that, please?
- onei 6y agoThis is an argument I've never come across before and I'm curious - why does web development require the use of garbage collection? Recent blogs I've seen suggest that at very large scale, garbage collection in languages like Go have severe side-effects, although obviously there's very few of us running at that scale.
- sudeepj 6y ago> Web development without garbage collector sounds like a bad idea. Before rust, all the mainstream non-gc'ed languages (i.e C/C++) were not recommended mainly due to potential security issues. The only options left were gc'ed languages (e.g Python, Java, Go). Now Rust enters which addresses a lot C/C++ issues but the ergonomics, lack of tooling & learning curve is too much for lot of basic web services. For large scale web services, investing in Rust makes sense to make it more performant & resource efficient, especially a lot of $$ is riding on it.
- sweeneyrod 6y agoThe question shouldn't be "why does web development require the use of garbage collection" but "why would you not use a language with a GC when you have the opportunity". Before Rust (and after the 90s or whenever hardware became sufficiently cheap) it would've been very odd to consider a non-GCed language for something like webdev. Even for things like high-frequency trading where reliable low latency is very important, some companies think using GCed languages like Java and inventing hacks to avoid GC pauses when necessary is a worthwhile tradeoff because of the productivity gain from having a GC. Certainly Rust has done lots of cool stuff to make living without a GC easier. And maybe it has sufficient compensating advantages to make it worth using for things like webdev (although I wish more of its proponents would try different statically typed functional languages that share some of those advantages but don't make you manage memory manually). But lacking a GC is still pretty clearly a disadvantage outside of a few areas (namely, those where people often use C++).
- brundolf 6y agoWas hoping this would go into more detail; about 50% of it was just repeating well-known points about the language itself. In particular there was no discussion of auth, which you need even if you're just doing JSON APIs. I've fiddled around with Rust web proof-of-concepts and I tend to agree that the language is somewhat-but-not-completely suited to it, and that the ecosystem is coming-along-but-not-quite-there-yet. But I have a small sample set for those impressions; I was looking forward to reading a more in-depth anecdote about the ups and downs and how to overcome different limitations, as well as a some informed speculation about the future.
- maxpert 6y ago`Rust is a real pleasure to use for web development, and I thoroughly recommend it. It is so versatile that, without a doubt, it’s the last programming language I learned. Ever.` This rings a Node.js fandom bell in my head; I'll be very careful taking authors opinion seriously. Edit: I've myself been working on writing a websocket pubsub server in Rust and I can tell you the ecosystem is not as developed as projected by author.
- baby 6y agoI use rocket and it still feels beta, has issues to integrate with other libraries like tokio and mongodb because of the quick changes of versions that are incompatible, and in general lacks a lot of essential features. At the same time it’s light and easy to use, like flask
- incadenza 6y agoThis is somewhat tangential, but I'm feeling a bit ambivalent about all of the popular options for building RESTFul APIs lately. With every new entry in the ecosystem, the same libraries (authentication, migrations, logging, authorization) have to be re-implemented. In spite of all of this new stuff (Go, Node, and now Rust) I look around and don't really see how we've done any better than Rails in the past decade or so. Performance needs aside, I feel like we're just going around in circles since Rails.
- iamwil 6y agoPerformance is a real need. Iterating and maintenance is also a good thing. A 2x refinement may be a difference in degree, but a 10x refinement will be a difference in kind that will enable other kinds of innovation.
- blacktriangle 6y agoPretty much the same reason Wordpress marches on. The advantages of a "better" language are just not worth rebuilding the entire ecosystem around WP or Rails, both of which have massive leads and neither of which are standing still. RESTful APIs are pretty much a solved problem, the next language isn't going to get big by being a better Rails, it's going to get big by doing something new.
- Thaxll 6y ago"I have to understand the differences between a Box, an Rc and an Arc" That's actually a problem I would say, most web dev use Java/C#/Go/Ruby/Python/Node/PHP etc... which all have a GC, so it's a big shift for 99% of people. It completely change the way that you design your app.
- ampdepolymerase 6y agoJust wrap everything in an ARC and you will have a GC :)
- Scarbutt 6y agoAnd now you have a slower Java.
- burnthrow 6y ago> Memory management is a distraction: Actually, no. I don’t use that many lexical lifetimes and use instead smart pointers. So yes, I have to understand the differences between a Box, an Rc and an Arc, but my productivity is not impacted compared to Node.JS or Go. By throwing everything on the heap, I doubt you see much improvement performance-wise over Node or Go. You probably even come out behind idiomatic Go which makes good use of the stack. What's the point?
- Klonoar 6y agoEeeh, I run a few web services on a Rust stack and follow a similar pattern. Performance still tops a comparable Node/Python setup; I unfortunately am not a Go user beyond dabbling so can't comment there, but I suppose I'm just weighing in to say "I've not hit issues with this". Often times, I Box something and tag it with a "review this" for later. If it somehow becomes a bottleneck, well, it's relatively simple to solve in most web-framework use-cases. Haven't really needed Rc, only needed Arc for shared data structures (rare).
- wtetzner 6y agoIt may also come down to what else the web service needs to do. If you're just doing a CRUD app, you're probably right. But if you're wrapping some complex logic that itself makes sense to writ in Rust, then I can see why you might want to write the web interface to it in Rust as well.
- deleted 6y ago[deleted]
- stunt 6y agoFor "frontend" web applications, you need so much abstraction that for me it's always about choosing between frameworks rather than languages. (Spring, Laravel, or Rails?) Unless what you want to build is tiny and simple and you don't need a lot of features, or it's so massive that you can invest on building everything that you need.
- alexfromapex 6y agoI agree and the security guarantee makes the other trade offs worth it