Lurker News
I periodically hear about projects that use/have used sqlite as their sole datastore. The theory seems to be is that you can test out an idea with fewer dependencies (and cost) and that it scales surprisingly far.

There are even distributed versions being built for reliability in the cloud: dqlite by canonical (of Ubuntu fame) and rqlite
Given the complexity it seems like there are use cases or needs here that I'm not seeing and I'd be very interested to know more from those who've tried.
Have you tried this? Did it go well? Or blow up? Were there big surprises along the way?
- https://sqlite.org - https://dqlite.io - https://github.com/rqlite/rqlite

Comments (325) 124 threads

Earlier comments
simonw#
I'm running a bunch of different read-only sites and APIs on top of SQLite using Cloud Run and Vercel - abusing the fact that if the database is read-only you can package up a binary DB file as part of a Docker container or application bundle and run it on serverless hosting.

This means it won't cost any money if it's not receiving any traffic, and it can scale easily by launching additional instances.
I wrote about my patter for doing this, which I call Baked Data, here: https://simonwillison.net/2021/Jul/28/baked-data/
A few examples are listed here: https://datasette.io/examples

pieterhg4 replies#
Yes for all my sites: Nomad List, Remote OK, Hoodmaps, Rebase etc. No real issues at all.
el_dev_hell1 reply#
Awesome to hear!

How do you handle this? Do you store the SQLite file somewhere like s3 or just in memory?
How does this work for such high traffic sites?

pieterhg#
No in the filesystem on a VPS. All my sites just run on a VPS. Nothing fancy!
levelSEOfan#
glad to see pieter here, I am keeping an eye on rebase ;)
WA2 replies#
I read in one of your Tweets that you use one database file per (unrelated) table to avoid corruption. Why did you move to this model? Are multiple tables per file really more easy to corrupt?
barryhennessy#
I'd be interested to know what kind of corruption you were facing.
pieterhg#
Yes! It kinda happened because I had no idea how SQLite worked so I thought this was normal.

Then I thought this is great and makes it easier to move the db file if it just has 1 table. So I can download it easily for local dev for ex.
And yes in case there's corruption which never rly happens, only one file thus table would be affected.
PS: one thing that really helped reduce issues was setting PRAGMA MODE to WAL

matthewaveryusa3 replies#
I’ve worked on several projects with sqlite, both read and write heavy, all with high concurrency, with databases in the few hundred MB with 400k server clients, and 100 bare-metal servers running at capacity. The sqlite part of our system is never the problem. In our case sqlite has been an alternative to custom files on disk or replacing a spaghetti of hashmaps in memory. we also replaced a single postgresql instance with all customers into many sqlites per customer. Performance and reliability is why I always reach for it first. At this point I’m a zealot and would argue your first ‘data structure’ of choice should be an sqlite database :)
Mertax1 reply#
What pain points have you experienced with "many sqlites per customer". I'm considering transitioning to something similar but would love to know what pitfalls I might not be considering.
matthewaveryusa#
None really, but we have a fairly simple design where all the shared databases we attach are read-only (think big static lookup tables that a separate process takes care of updating.) I would probably avoid having databases attach contextually -- seems complicated and error-prone.
giantrobot#
I'm also in the SQLite is a data structure camp. You get fast access and persistence for free. You can also fix a lot of issues just exploring the database offline.
ricg#
Did you ever run into the problem of the system running out of file descriptors? If each client gets its own database file, each connection will require a file descriptor.

For example, Linux limits the number of file descriptors to 1024 per process to each process can open up to 1024 files at any point in time.
I ran into this problem in the past in another project (the system ran out of file descriptors for another reason).

barrkel1 reply#
Don't be afraid of a database process. They are not scary, and are certainly less scary to scale up than whatever you might need to do with SQLite. There's more help available and better tooling.

SQLite may shine in edge cases where you know you can outperform a regular database server and you know why, and you could build everything either way. SQLite could be a way to e.g. decentralize state, using local instances to do local storage and compute before shipping off or coordinating elsewhere.
Otherwise, SQLite can simply be a recipe for lots of lock errors on concurrent operations. I've also never been very impressed with its performance as a general purpose replacement for postgres or MySQL.

jjoonathan1 reply#
> tooling

Yes, I learned this the hard way. I understood that simplicity meant limitations, but I did not understand that simplicity meant danger until SQLite burned me.
If your perf tanks, you don't want to have to spend days putting timers all around someone else's codebase. Caveat: SQLite may be better these days -- my incident happened in 2013 -- but I spent more time tracking that one SQLite issue than I have spent spinning up postgres instances since then.

srcreigh#
do you have any details about the situation you were facing?

Load more comments