Stephen Margheim
fractaledmind.github.io · Personal blog · on HN since 2023
Stephen Margheim writes about running SQLite in production with Rails, including performance tuning, concurrency, backups and Litestream.
What HN saysHN commenters recommend his SQLite on Rails series as where they learned most of what they know, though one finds it works around SQLite's write limits.
16HN people shared it
9linked it in comments
13stories submitted
477story points
2 years agolast shared
2023people per year2026
Most-shared posts
- 1SQLite on Rails: The how and why of optimal performance6 people · 279 points · first shared 2024 · 96 comments on HN
- 2Supercharge the One Person Framework with SQLite4 people · 30 points · first shared 2024 · 10 comments on HN
- 3Setting Up Litestream on Debian Linux with DigitalOcean Spaces2 people · 1 points · first shared 2023 · discussion on HN
- 4Sqlite on rails improving concurrency2 people · first shared 2024
- 5How (and why) to run SQLite in production1 people · 155 points · first shared 2024 · 80 comments on HN
- 6Fine-tune your SQLite database for production web app usage1 people · 3 points · first shared 2023 · discussion on HN
- 7PlanetScale-style database branching for Rails and SQLite with 2-lines of code1 people · 2 points · first shared 2023 · 1 comments on HN
- 8Select Dropdown for Polymorphic Associations1 people · 2 points · first shared 2024 · discussion on HN
- 9Solid Errors1 people · 2 points · first shared 2024 · discussion on HN
- 10SQLite Myths: Linear writes don't scale1 people · 1 points · first shared 2023 · discussion on HN
- 11Enhancing your Rails app with SQLite: Installing extensions1 people · 1 points · first shared 2023 · discussion on HN
- 12Loading SQLite Extensions in Rails1 people · 1 points · first shared 2023 · discussion on HN
- 13111.png1 people · first shared 2025
- 14Sqlite in ruby backoff busy handler problems1 people · first shared 2024
What HN people wrote when they linked it
adenta · 2025-02-17
Do you really need concurrency? My understanding is read are like… picoseconds, because everything happens in memory. You don’t have a separate server to call.
This guy is great: https://fractaledmind.github.io/2024/04/15/sqlite-on-rails-the-how-and…
anze3db · 2024-06-15
Stephen has a whole series of blog posts on SQLite (in Rails) that I highly recommend. I've learned most of what I know about SQLite from him!
https://fractaledmind.github.io/2024/04/15/sqlite-on-rails-the-how-and…
Also, hello Lee! I miss being in a Slack with you!
abbbi · 2024-03-27
another article praising sqlite in production and working around a known sqlite limitation: concurrent writes. As they link in the article:
> But, my favorite feature of the gem is its improved concurrency support.
> [..] https://fractaledmind.github.io/2023/12/11/sqlite-on-rails-improving-c…
Really. At the point you are experiencing database locked in your productive app that uses sqlite as backend, i would strongly suggest to use another database backend that was designed with concurrent writes in mind.
Nothing against sqlite in production, its nice, as long as your workload meets its feature set.
skybrian · 2024-03-27
I went through this presentation looking for "how do you do backups" and it glosses over it. But the author blogged about that separately [1].
It seems he uses Litestream with DigitalOcean Spaces for this. Looks like they start at $5 per month for 250 GB [2]. Would that be the best way for a hobbyist to get started?
[1] https://fractaledmind.github.io/2023/09/09/enhancing-rails-sqlite-sett… [2] https://www.digitalocean.com/pricing/spaces-object-storage
simonw · 2024-11-09
Missing from this, but very important: you can connect to the same SQLite database file multiple times inside the same process (e.g. in different threads) but you can also connect to the same SQLite database file from multiple different processes on the same machine (with the same filesystem - NFS will lead to all kinds of nasty problems).
Easy way to prove this to yourself: run two different terminals, run "sqlite3 data.db" in each one, run create table / insert / update queries in one and watch the results become visible to selects in the other.
Changes only become visible to other connections after they have been committed.
In default mode any writes will hold an exclusive lock and will cause any reads to be blocked waiting for that lock. In WAL mode reads can continue even while writes are taking place.
Writes can only run one at a time, but can queue waiting for each other to finish - and since most writes take microseconds to run this is very rarely a problem.
The most complicated thing to understand is the need to use BEGIN IMMEDIATE TRANSACTION in concurrent environments to avoid the occasional SQLITE_BUSY exception. The best explanation I've seen of this is here: https://fractaledmind.github.io/2024/04/15/sqlite-on-rails-the-how-and… - search for SQLITE_BUSY.
ncruces · 2024-11-09
There are benefits to having a single writer connection (and multiple readers).
One is that you can get fairer and more efficient locking. The (interruptible) file lock APIs that SQLite uses lead to a lot of sleeping and retrying that wastes time, and is not very fair.
https://fractaledmind.github.io/2024/07/19/sqlite-in-ruby-backoff-busy…
Another some APIs, like the backup API, work better if they can track writes, and (e.g.) backing up from the single writer connection helps there.
ozim · 2024-10-26
I don't know about 1TB data but I think it was used in some missile system so I would say yes for mission critical data, not sure if we think about mission critical in the same terms.
Edit: by pure chance I hit that just a moment ago: https://fractaledmind.github.io/2024/10/16/sqlite-supercharges-rails/
metabeard · 2024-10-18
S3 is acting as a backup, not a data store. The SQLite file is local to the app. This recent post discusses the tradeoffs in more detail and includes metrics. https://fractaledmind.github.io/2024/10/16/sqlite-supercharges-rails/