Is it time for building Rails apps with SQLite?

Have the stars aligned to use SQLite in production? SQLite was always the quick development companion for all new Rails applications, but it looks more and more appealing to use it for everything.

Is it time for building Rails apps with SQLite?

Why SQLite?

First, why do we might want to run SQLite instead of MySQL and PostreSQL?

It's lightweight

SQLite is a self-contained database engine that requires minimal setup and administration. It is lightweight, making it easy to embed within applications without the need for a separate server process. This let's you just run rails server in development without running any additional process as well as saving you the same process in production.

It's fast

Now this advantage might be harder to get since SQLite is always used for smaller projects and lacks the same concurrent features like its big cousins. But SQLite file usually lives close to the application and therefore accessing the database is super fast. In fact, it's also fast locally:

It's just a file

The fact that we don't need an extra process makes server deployment easier. If I am deploying with Kamal I save at least one accessory (a database container). Backups can also be easier depending on the strategy we use. It's easy to reason about.

New possibilities

SQLite enables some new possibilites that are hard to do with traditional databases. 37signals is looking into running a single database per tenant with activerecord-tenanted and then also running the database from a location close to the tenant with possible new features coming to Kamal.

Concerns

There are certain configuration you need to run when using SQLite to make it a truly viable choice for production. Think immediate transactions, fair retry interval, WAL journal mode, and more. Luckily for us, this was already baked into Rails 8 release and the numbers you can be doing look pretty convincing:

If you use Rails 8, SQLite is a possibility. This still doesn't solve the concurrency limitation of SQLite, but it enables lots of applications to go very far. And when going for single tenant (like with ONCE products) or using activerecord-tenanted, we might actually be able to use SQLite for everything.

If you aren't convinced yet, have a look at sqlite.directory, a directory of SQLite-powered applications or watch this interview with DHH:

Future

I feel like the main building blocks for the next generation of Rails applications on SQLite are out there and it's time to add this support to Business Class. Perhaps not initially with full database-per-tenant approach, but as a convenient option with Litestream backups.