145 points · by subomi · 3y ago · 118 comments
Happy to answer any questions. Although SQLite is so dead-simple-but-awesome that you probably don't have any. :D
Anyway, hope you enjoy it and learn a thing or two.
Markus
The APIs can even support authentication and authorization with the help of JWT tokens. SQLite may not have row-level security, but even a convention (eg: if a row has user_id column, the JWT must have the same user_id value to get access to a row) would go a long way.
https://github.com/subzerocloud/showcase/tree/main/flyio-sql...
Although I definitely would like to use SQLite just for the cost savings for something. Litefs/litestream looks great.
Without the WAL enabled, I get a around 400req/sec.
edit: clarity
You would have trouble scaling up to fives of authors, though, which would be a deal breaker for any serious production app.
Expensify got 4 million request _per second_ out of a custom SQLite-based setup (on a huge machine, but still): https://blog.expensify.com/2018/01/08/scaling-sqlite-to-4m-q...
I would call those serious production apps.
I don't know how it's done in PHP, I would think it's similar.
Go + Lambda + EFS + SQLite work great for that.
And you have had no issues writing to a single SQLite file over EFS from multiple instances?
Here is a page with quite some queries to render: https://www.chemeo.com/cid/58-801-8/Pentane
I think we’ve collectively forgotten how fast dynamic websites can be on modern hardware!
This concern is a bit overblown, the Cgo boundary is heavier than an ordinary function call but still a zillion times faster than doing disk I/O on the database.
But with sqlite you'd have to perform a hot-upgrade, surely? i.e. shut down the old version and quickly fire up the new version, with a small window of downtime in between.
Note: I see Litestream/LiteFS allows distributed deployment (both in beta).
And yes, LiteFS just selects a new leader and does a rolling deploy (or whatever else you want).
I'm curious what experience you or others have dealing specifically with the write concurrency elements of this setup, should you find it is actually an issue. I've occasionally seen mention of restructuring things to queue writes within the app (e.g. having a single writer goroutine fed with a channel), but I be interested in more details about when folks hit the point of needing to do that, and what they did (and did it help?)
I did some trivial benchmarking around this recently: https://simonwillison.net/2022/Oct/23/datasette-gunicorn/
But yeah most of the time it isn't an issue.
AFAIK, SQLite is fully and completely ACID also in WAL mode.
https://sqlite.org/forum/info/00312b3d02bc0583
Sqlite's internal one has to work this way to support their multi-process guarantees. In comparison, an in-process Go mutex will be readied immediately.
The built-in busy timeout basically takes care of write queueing, so a standard setup like this will take you very, very far.
Any recommendations for a macOS GUI for sqlite that comes close to Sequel Ace? I have tried DB Browser for SQLite, but that feels a bit outdated to be honest.
Concurrent readers is no problem. No concurrent writes right now.
I would only say this is a quick way to run up an application with a cheap VPS for a beginner.
If your app averages 100 req/sec then that’s 8.4M requests per day. That’s more than most applications out there.
Most things will never need to be scaled up
Can you expand on that? I thought it supported multiple readers, but only a single writer. They do all have to be on the same host, though.
Since you mentioned Django - I think there are some complexities where the Python driver can't really do concurrent access if using threads instead of processes, but this is due to Python/GIL limitations, not sqlite limitations.
It's more complicated than "doesn't support multi-core" which you can see in the other replies here: generally unlimited concurrent readers are allowed with single or at least finite writers. Depending on a bunch of settings (e.g. WAL) you might also get concurrent writers, multicore sorting, and some other things that can cross cores too. Those things do have their own tradeoffs.
But my actual claim is that most things don't need to be "scaled" at all. And if you do get there, and again statistically you won't, then you're definitely going to be doing some other rearchitecting anyway and moving sqlite->postgres might as well be part of that.
And IMO, what you lose in the cloud layer you gain by having a deployment really close to your user. Speed of light and all that.
Plus SQLite is super cool and fun! :D
On the opposite I've seen many cases where sqlite3 scales better than postgres, depending on the scale and the application.
If you're doing horizontal scaling, sqlite3 is a very good alternative.
We don’t all operate with unlimited VC money.
Conceptually, RDS is little more than SQLite with a clever networking layer built on top. In context, your application is also just a clever networking layer, so the middleman doesn't necessarily add any value. Of course it depends on exactly what you are trying to do and what tradeoffs you are willing to accept. There is no free lunch.