What if Rails was Built on Rust?

Posted November 24, 2023 by Team Loco

What if Rails was built on Rust and not Ruby?

Then it would look like this:

async fn current(
    auth: middleware::auth::Auth,
    State(ctx): State<AppContext>,
) -> Result<Response> {
    let user = users::Model::find_by_pid(&ctx.db, &auth.claims.pid).await?;

pub fn routes() -> Routes {
    Routes::new().prefix("user").add("/current", get(current))

Introducing: Loco

Loco is a Rails inspired web framework for Rust. It inlcudes almost every Rails feature with best-effort Rust ergonomics:

  • Controllers and routing via axum
  • Models, migration, and ActiveRecord via SeaORM
  • Views via serde
  • Seamless, Background jobs via sidekiq-rs, multi modal: in process, out of process, async via Tokio
  • Mailers
  • Tasks
  • Seeding
  • Environment-aware configuration
  • Tracing, logging, seamlessly integrated via tracing
  • Generators via rrgen
  • Batteries-included authentication (like Rails' devise)
  • Testing kit, with automatic truncation, fixture seeding, auto migration, snapshotting and redaction

It's full stack for real.

Why not Rails?

If you're happy with Ruby, use Rails. Don't spend time looking elsewhere because of performance -- Rails and Ruby are good enough.

But if you love Rust, you can now build companies like Rubyists have been building for ages -- use Loco.

  • You'll get Rust's safety, strong typing, fantastic concurrency models, and super super stable libraries and ecosystem. Build once, then forget about it.
  • Deployment is copying a single binary over to a server.
  • You'll be getting an order of 100,000 requests/sec without any effort. And 50k requests/sec with database calls. You will never need more than a couple servers. Heck, you can deploy on a Rasberry Pi and be happy..

The One Person Framework

Inspired by DHH's approach, Loco's guiding principle is above all:

The one person framework

From this single guiding principles comes everything else.

For example, one person team, or one person company:

  • Has no time to debate libraries, tooling, linting rules: strong opinions are welcome. Tell me how I should work.
  • Needs a driving tool in addition to their brainpower -- that's the Loco CLI. Generate code, operate your project.
  • Needs stability, anything that breaks is a waste of time, any surprise is a waste of time
  • Needs simplicity -- don't surprise me
  • Needs a single operability story. Deploys should be simple. No Kubernetes, no IAC, no preconditions.
  • Needs control. Send emails and author the emails locally, not on some remote service
  • Needs locality. Everything that happens in production should first happen in development and locally
  • Needs ad-hocness. No holy grail ceremonies. Build tasks to run birthday emails to your users, rather than go on a crusade for an "Admin" project.

Loco is the one person framework for indy hackers, hobbyists, and startups.

With around 20mb of a deploy binary, and 50k requests/sec - all you need is a single small/medium server, Postgres or Sqlite and an internet connection. Startups should be cheap!

Get started with Loco today!