I keep trying to push SQLite on my customers and they just don't understand, they think they always need something gigantic and networked. Even when I show them the performance, zero latency, and how everything is structured in the same way, they demand complexity. Keeps me employed, but god damn these people and their lack of understanding. The worst part is these are 2 and 3 table databases with the likelihood of it growing to maybe 100K records over the course of 5-10 years.
Can you convince me that I should choose Sqllite over Postgres, who performs great at small scale, but will also very painless scale to a cluster of if I need it to?
SQLite's main benefit is simplicity, and its main target isn't replacing Postgres, it's replacing fopen. So it's basically zero overhead, zero work to setup and maintain, backup can be as simple as cp...
I don't know if I agree with the OP that it's a good choice for small websites, but if you're building anything that ships to a user's device, then you should be asking: Should your app work offline? (Is there any reason it shouldn't, for that matter?) If so, probably better to use a library to manage a single file, rather than asking your users to set up some docker nonsense.
Just so people are aware, you CAN NOT just cp a sqlite database while it is open. There are ways to do it, and I would suggest looking it up before doing it.
You shouldn't backup sqlite with cp while the application is running because you can get a torn backup that is corrupted. You can do it while you are holding a database lock (BEGIN IMMEDIATE), or you can stop the application or you can use the sqlite backup API. This advice applies for non-WAL databases and I can't tell you how WAL changes it.
Of course it is safe to take a backup while the application is only reading from the database.
Yep, it seems to me that if I'm going to have a webserver, I may as well also have a postgres/mysql server, slap em together and do whatever I want, it's gonna work great and be free and be easy to configure and keep going. But if I want to ship something that needs to have a database locally, sqlite is a great option if the data isn't enormous and not super complex. Which 99.8% isn't.
The best explanation I have seen is that SQLite doesn't replace a database, it replaces file access. So it's amazing when you want to store some structured data without the hassle of setting up a database, i.e. in those situations where the alternative would be to come up with your own file format. If your workload is a more standard single central repository problem then you'll almost always be better off going with one of the other databases.
So smallish amounts of client side structured data storage it's the king. Server side data storage, go with a normal database.
SQLite is great for scenarios that have one of those characteristics
clientside data
portable files, e.g. read-only data exports, like an advanced form of json, you may want the ability to do joins or fast access for entries within a dataset that can scale up to gigabytes
scenarios where updates are not time critical, you can guarantee a single writer, e.g. through a scheduler
I look at from this perspective, I'm happy to bill my customers more, if complexity makes them feel better, and makes me more money, I'm not going to beat a dead horse. Most of my stuff uses an ORM so switching out the DB and doing a migration is something that can be done fairly easily too. I look at SQLite as the most deployed database in the world and something that everyone uses even if they don't realize it.
Most of my stuff uses an ORM so switching out the DB and doing a migration is something that can be done fairly easily too.
This does not jive with my personal experiences. Both times I worked on a project migrating databases it was hell. Both times the database was a few TBs so it hade more to do with the practical considerations of moving that much data in a time frame that didn’t cause outages. Which is why, IMO, selecting an option that will scale from the start, if there is any chance of scale, is a good choice
SQLite is not for concurrent users, the whole database is locked on write. There's 'WAL-mode' to overcome that somewhat, but at that point you really should use more capable database instead.
If you think about clusters, SQLite is not on the table (heh ;))
SQLite is great for embedding inside mobile apps so you can keep the 1:1 (client/server) tables CRUD DTOs intact while having all the sophisticated SQL queries inside the mobile app. This can greatly simplify things, especially when internet connections are sporadic.
It's obviously a pretty good / great solution for native frontend applications, when wrapped with an ORM, formal versioned schema and fully automated migrations.
And obviously on backends that don't need crazy scaling or whatever.
Not sure how many folks use it on the android platform, but it's there too. I heard the contacts app used it, but not sure if that's true anymore, if so that's practically every phone.
607
u/bastardoperator Sep 10 '24
I keep trying to push SQLite on my customers and they just don't understand, they think they always need something gigantic and networked. Even when I show them the performance, zero latency, and how everything is structured in the same way, they demand complexity. Keeps me employed, but god damn these people and their lack of understanding. The worst part is these are 2 and 3 table databases with the likelihood of it growing to maybe 100K records over the course of 5-10 years.