r/ruby • • 9d ago

Snails is a Rails-like framework for API-only Ruby apps.

https://snails-rb.org/

Snails builds on Matz's Spinel to compile apps into a single native binary, minus Active Record, server-rendered views and gems. It keeps the Rails conventions and builds the framework in plain Ruby. One process, multi-threaded, across all cores: no worker processes, no GVL. On the benchmark, Snails serves about 3× the requests per second of Rails in cluster mode, with more than 10× lower peak memory under load.

Site: https://snails-rb.org/
Repository: https://github.com/snails-rb/snails

24 Upvotes

13 comments sorted by

5

u/KevinSaison 8d ago

Really curious to see where this goes. Do you eventually see Snails growing into a more complete Rails alternative?

2

u/kslrinn 7d ago

Thanks. I'm building a bigger demo app on Snails right now: a trace explorer (ingest spans, search traces, find the slow span). If the conventions hold beyond the telemetry service, that's my answer for API apps: Rails conventions, without the Rails stack. I'll post it when it's up.

2

u/The-WinterStorm 7d ago

I think the idea is neat, but I am unsure why I would want this. I just started getting back into Rails and I have yet to find any reason at this time to do it. I think if Rails could lighten the bloat... I'm sure it'd be better.

2

u/kslrinn 6d ago

Honestly, if Rails fits what you're building, you don't need this. I'd stay.

The part I'd push back on is "lighten the bloat." I ported one of my Rails workers to Rust and the same job went from 360 MB to 2 MB. That's not bloat you tune away, it's the stack. Rails can get lighter, but I don't think it closes that gap.

I didn't want to leave Ruby, so I created Snails instead.

1

u/atomic_transaction 6d ago

How does this compare to Grape?

1

u/kslrinn 5d ago

The runtime is the big difference. Grape runs on CRuby, so you keep gems, Rack middleware, and AR or Sequel. Snails compiles to a native binary with Spinel: no CRuby, no gems, no runtime metaprogramming, and a plain SQL model layer. If you want the gem ecosystem, Grape is the safer bet.

1

u/mxsifr 5d ago

Heya Claude, how are you today?

2

u/kslrinn 5d ago

Open weights, if anything ;)

0

u/[deleted] 8d ago

[deleted] — view deleted comment

2

u/kslrinn 8d ago

Fair point. roundhouse has more targets than the Spinel one I tried. That target runs the Rails runtime, so AR and the gems come with it; the other targets drop Rails at runtime, but the source stays Rails and the output is generated code in another language. If I wanted Go or Rust, I'd port directly, as I did for one worker. My constraint was the stack, not the target language, so I create a framework rather than a transpiler.

longer version here: https://snails-rb.org/blog/a-native-rails-like-ruby-app-using-20-mb-of-memory/#roundhouse-kept-the-rails-stack

4

u/KontoOficjalneMR 8d ago edited 8d ago

I gave up after two paragraphs of meaningless AI slop in README.

Shame because sounds interesting.

Edit: Holy shit, it's basically a framework for AI bots to clone Rails project into another framework while verifying that it kinda produces same output (kinda because there's no formal proof, just AI coded test framework that checks in under test conditions same endpoint produces same output).

0

u/[deleted] 6d ago

[removed] — view removed comment

1

u/kslrinn 5d ago

Not as a gem. Snails runs compiled by Spinel, not on CRuby, so Sequel can't be loaded as-is. The DSL itself could be ported to Spinel and used as app code. Sqlx is built in because I prefer a thin SQL layer, not because a DSL is impossible.