What software stack would you have chosen for Lemmy?
Lemmy is an open-source, federated link aggregator and discussion platform similar to Reddit, Lobste.rs, or Hacker News. The software stack used in Lemmy includes Rust with Actix and Diesel for the backend, and TypeScript with Inferno for the frontend.
The developers chose Rust for its performance, safety, and concurrency features, which help in building a reliable and efficient backend. Actix is a popular Rust web framework that provides a lightweight and fast foundation for the server-side application. Diesel is a Rust ORM (Object-Relational Mapping) and query builder that simplifies database interactions. On the frontend, TypeScript offers better type safety and tooling compared to plain JavaScript, while Inferno is a fast and lightweight React-like library for building user interfaces. These technologies were chosen to create a performant, reliable, and easily deployable platform.
I read someone saying that the lack of contributors was due to the software stack being unconventional and takes people a while to get used to it. So I was curious to know what other people would have used.
Rails. Of course, I'm biased because it's what I know the best, but also because Mastodon is written with Rails so in terms of getting more contributors from a similar project I think Rails would have been a good choice.
I also looked into helping with Lemmy development, but ran into the same problem you've described: I don't know anything about any parts of the stack. I run my own instance so I can run and debug it well enough, but actively working on new features/bug fixes would require more time to get up to speed than I can put in currently.
Edit: I'm not one to complain about imaginary internet downvotes, but can we be better than reddit please? Downvote is not a disagree button. The question was what would I have chosen, not what the most popular web framework is this year. It's cool if you would have chosen something else. This whole thread has become "what framework does everyone like the most currently?"
and at some point in the future, the possibility of upgrading from Ruby to Crystal …
Rails is terrible. For something like Lemmy I'm confident it would just fall over (or require a much higher hosting burden). There's way too much data to render and retrieve in a system like Lemmy, the caching systems for JSON shuck (hello jbuilder caching objects instead of json), Ruby performance is awful, there's no mitigating factor to allow efficient blocking on IO bound requests (like coroutines or fibers), Ruby used a non-compacting garbage collector so it's subject to heap fragmentation and wasting memory, there's no static typing (or even type hinting), the Ruby ecosystem is built on Rails alone at this point (few if any libraries to make use of), the principle of "developer happiness" results in the need for tools like Rubocop to "resolve" invented problems WRT "how do you style X in a particular context" (among other things), and to top it off the framework makes doing the wrong thing easy and the right thing harder (Rails apps are so prone to N + 1 database queries).
It's also a ridiculously hard thing to hire for because basically nobody teaches Ruby or Rails. There's a very limited pool of Rails experts.
If some of that has changed I'd love to know, but after working in rails for ~3 years... I have no love for it. The only thing I'd ever use rails for is a small scale project, like a small business website/webstore. IMO, it's not suitable for websites that need to serve large volumes of data that doesn't cache well at the page level.
Well, it seems to work well enough for Mastodon. I'd also point out that there are websites far larger than Lemmy using Rails at scale (Shopify and GitHub being the primary examples). It scales quite well.
Without benchmarks, this is a subjective statement. Ruby 3 is quite speedy now, at least I find it to be. Performance is even better with YJIT enabled in Ruby 3.2. I think this "Ruby is slow!" stereotype is left over from before Ruby 1.9 when YARV was introduced. Is it as fast as a native language? No and it never will be, nor will any other interpreted language. But this idea that Ruby is somehow the slowest possible interpreted language has not been true for a very long time now.
I'm not entirely sure what you mean by this, but Ruby introduced fibers a while ago.
Not true anymore. Ruby has had a compacting GC for a while now. This was a difficult problem to solve because of Ruby's support for native extensions. Otherwise it would have been done much sooner.
You can use RBS (built into Ruby) or Sorbet (third-party Shopify project) for this if you want. Or don't, I personally prefer Ruby's duck typing. I don't think a language using someone's preferred type system makes it "terrible" just because it's not what someone likes. Other people are perfectly happy with it.
Ruby being a one-stop-shop for Rails has been a criticism of it for years. I'm not sure how that's a knock against Rails or Ruby though. I personally write all sorts of non-Rails things with Ruby as I love the syntax and greatly enjoy writing Ruby code over that of, say, Python. To each their own though. There's Sinatra, Jekyll, Fluentd, Chef, etc. all written in Ruby.
I personally love the configurability that Rubocop provides. Some people like the "one true way" of formatting for languages like Go (which also for some reason thinks single letter variable names everywhere is a great idea), but other linters like Eslint for JavaScript have the same level of configurability as Rubocop. Alternatively, just don't use them. Rubocop is not something you need to use to use Rails.
Drop in gem that will automatically solve 99% of N+1 issues: https://github.com/clio/jit_preloader
Again, subjective statement here. My company has no problem hiring Rails devs. Granted, we operate on the idea that any good engineer can get up to speed with a framework in a reasonable amount of time. I don't believe in the "you are only worth the frameworks that you know" idea. Give me three months and I'm confident I could be proficient & competent with any web framework. Not a true expert per se, but knowledgeable enough to get stuff done, which at the end of the day is what you need to do. Those are the people I want to hire. Not the person that's going to be afraid to jump into something new because they've never worked with it before.
Am I saying that Ruby/Rails is perfect and there's no problems? Of course not. There's no such thing as a perfect language or framework. But I also think that Ruby is unfairly demonized because of lack of familiarity and it being less used than JS and Python frameworks. And oh boy do I have complaints about JS frameworks. But I wouldn't go so far as to call any of them "terrible." Maybe it's not my/your cup of tea and that's okay.
I could be mistaken, but I believe these sites are normally "using rails" (as in they shell out to other languages, Go has become common, for performance critical end points or portions of those end points that need to work a bit harder). I also suspect they've got some pretty heavy modifications.
I haven't worked with Ruby since... 2.5(?). That's very fair about the JIT improvements.
The Ruby language itself has fibers, but last I knew Rails was not making use of fibers for ActiveRecord. The problem is effectively you're in an interpreted language (bad enough) without real parallelism (worse). So, when any IO occurs one of your non-parallel threads is blocked. Ruby jumps around to process the different threads, but this creates a context switching problem and you lose a lot of performance to the preemptive multitasking's context switches (and resources are hard locked up by the IO).
With a coroutines or fibers based approach (cooperative multitasking) you don't need multiple threads, the "callbacks" just fire into the appropriate place when IO is fulfilled (what NodeJS is famous for). You can get way better throughput and it becomes trivial to execute queries that aren't co-dependent in parallel (so your page that depends on 10 different queries gets resolved much faster, and your app can work on other pages while that data is being resolved in the background).
It's not a silver bullet, you can run into issues if you have CPU bound tasks on the event loop thread (and thus create latency issues as things just aren't getting finished). However, in a well designed web app that shouldn't happen anyways (this stuff should be in background job queues, or at the very least running in separate threads -- in Ruby that likely means processes unless the threading has significantly improved).
That's good to hear.
RBS is definitely newer (I stopped working with Ruby around 2018). Looks like Sobet was just getting started. Also good to hear.
I've changed my stance over the years from "it's a matter of preference" to "it's objectively bad." The lack of any type structure leads to a significantly larger requirement in unit testing. Unit testing can be good, don't get me wrong, but in our org it had gotten to the point we were writing unit tests that effectively tested "did the code change" ... and I don't think that's a good workflow. You're lacking a compiler to do type checks for you (when you refactor something) so you have to write all the code to catch things the type system would've taken care of for you.
Put another way, I don't consider a unit test for a function as trivial as:
To be superior to the type system telling me
y
no longer exists. However, ify
no longer exist, I still want to know before a customer bumps into the inevitable crash.The problem you run into here is a lack of mature libraries to leverage if you want to do anything non-trivial. e.g., our application needed to read from spreadsheets. The Ruby libraries either A) didn't have support for common formats like
xls
or B) would load the entire spread sheet into memory represented as Ruby objects (you can predict how well that performed :) ).Without potentially breaking a NDA, that made the effort to get efficient spread sheet processing much more challenging than it would've been if we'd picked a language with more reach; this is just the main example I think of, there were others.
I think we eventually started using something akin to that. However, I'm a big advocate for making the wrong thing look wrong/complicated, and Rails very often makes the wrong thing look simple. Note that gems like this don't really solve the problem they just inform you when you've made the mistake, or alternatively forcing your app into hammering your database even in situations when it doesn't need to (which can drive you back to my earlier points about the lack of cooperative mulitasking to deal with the IO bottlenecks).
I agree, but there is something to be said for hiring people that are extremely knowledgeable in the framework to help highlight solutions (like those you've mentioned here) vs "you're a great C++ dev, now go do Ruby!" It's not a deal breaker, but when you hire folks like that the time to get them up to speed is going to be far higher, and they're going to make mistakes that in a sense "aren't at their experience level" (particularly with the former point about making the wrong thing look wrong considered).
I'll concede my initial reply/stance was a bit bold, and you've definitely highlighted serious improvements in the ecosystem I've either overlooked or forgotten about... Perhaps I should've said was terrible; I'm not rooting for Ruby to fail, but I did have a bad experience.
I can't speak to what they're doing internally, but I would agree this is a safe assumption. I think the point though is that Rails, with some help of external services depending on use case, can certainly be scaled out to a level that is far above the average web service making it more than capable of handling 95% of use cases you could throw at it. In the case of Shopify, they've traditionally been great about contributing optimizations back to Rails so their performance optimizations are shared with the larger ecosystem (and has the benefit of keeping them closer to upstream).
To your point, Ruby recently introduced Ractors which are true parallelism. They're new enough that their use isn't widespread yet, but I've played around with them and it's definitely neat to have real parallelism in Ruby now. And for web services, this would depend too on the web server. For example, using Puma or Unicorn will have multiple worker processes so there is some parallelism between requests regardless.
Yeah, I get that. For what it's worth, I really can't think of a situation where there hasn't been some library written in Ruby for something that I needed shy of extremely esoteric stuff that I likely would have needed to write myself if working in another language anyway. But that's going to be highly dependent on a case-by-case basis. For what it's worth, I make it a point to use as few third-party libraries as I can unless they're highly popular. It's a problem in all languages that random person's pet project library, while highly useful, becomes abandonware far too often.
You might be referring to the Bullet gem which is just a notification that there's an N+1 and where to find it so it may be fixed. However, the JIT Preloader gem actually does automatically solve the problem of N+1s in nearly all cases (see the README for details if you're curious). It's the closest to a silver bullet solution for the N+1 problem as I've seen and I now give almost zero thought to N+1s anymore. I know the devs were wanting to get it merged into Rails to solve this problem for everyone, but I don't know what happened to that effort.
Right, I wouldn't portend that anyone can make an easy switch from, say, embedded systems to web development in a few weeks or even a few months. I meant more like if you're competent web developer the core concepts of building web backends/frontends don't vary all that much between frameworks. At the end of the day, the underlying concepts deal with HTTP and HTML/JS/CSS so if you have a solid understanding of the base concepts and system design for the backend it shouldn't be much trouble to switch the framework sitting on top of those, especially if you have a team around you that is effective at code reviews, answering questions, and generally investing in new employees. Like you said, switching from something totally unrelated is a different situation though.
Thanks for a thoughtful reply, by the way. :) I really shy away from getting into pointless internet fanboy debates over which tool/language/framework is "best" but always enjoy when there's thought out reasoning behind points.