r/programming • • Sep 10 '24

SQLite is not a toy database

https://antonz.org/sqlite-is-not-a-toy-database/
811 Upvotes

309 comments sorted by

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.

235

u/account22222221 Sep 10 '24

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?

What does it have that other dbs don’t?

253

u/SanityInAnarchy Sep 10 '24

Depends what you're doing.

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.

71

u/yoniyuri Sep 11 '24

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.

→ More replies (1)

28

u/MaleficentFig7578 Sep 11 '24

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.

→ More replies (1)

40

u/gimpwiz Sep 11 '24

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.

→ More replies (3)

26

u/[deleted] Sep 11 '24

backup can be as simple as cp

not if you have separate WAL file. Which you should do.

→ More replies (5)
→ More replies (3)

54

u/nnomae Sep 10 '24

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.

→ More replies (10)

54

u/bastardoperator Sep 10 '24

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.

29

u/account22222221 Sep 10 '24

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

→ More replies (2)

20

u/Mognakor Sep 10 '24

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

  • potentially other scenarios, read https://www.sqlite.org/whentouse.html

→ More replies (3)

40

u/thuiop1 Sep 10 '24

Postgres demands more setup.

37

u/the-berik Sep 10 '24

T.b.h. if you control the server PostGres is also relatively easy to setup.

My go to for development is sqlite but I like postgres in production, also for dashboarding etc.

→ More replies (8)
→ More replies (25)

5

u/lux44 Sep 11 '24 edited Sep 11 '24

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 ;))

4

u/mycall Sep 11 '24

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.

5

u/aust1nz Sep 10 '24

If you think you’ll ever want to scale horizontally, postgres is quite a bit easier to configure for horizontal scaling than sqlite. And since it’s frankly quite simple to set up, it’s enough of a reason to just go with postgres from the start.

→ More replies (3)
→ More replies (9)

31

u/zapporian Sep 10 '24

All macos + ios apps are / were literally built on it. ie. https://en.wikipedia.org/wiki/Core_Data

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.

15

u/bastardoperator Sep 10 '24

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.

https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase

20

u/Wodanaz_Odinn Sep 10 '24

Android still uses SQLite but it's usually behind an abstraction layer like: https://developer.android.com/training/data-storage/room

→ More replies (2)

5

u/ApatheistHeretic Sep 11 '24

I'm not against the idea, how do I use sqlite from multiple applications hosts? NFS/SMB feel like a failure waiting to happen.

11

u/MaleficentFig7578 Sep 11 '24

You don't and you should use a different database when you need that. Do not run sqlite over NFS/SMB.

3

u/iamapizza Sep 11 '24

We can use sqlite for this.

But is it webscale?

Sqlite is pretty performant, has low latency and will do everything you need.

But it's not running in kubernetes.

You don't need kubernetes for your use case.

Kubernetes.

3

u/ZucchiniMore3450 Sep 11 '24

For my personal projects I always start with sqlite and hope it will be enough, and always end up moving to real database.

Sometimes I just need multiple connections, other times it gets slow because of the amount of data, or I miss some functionality like full text search or geospatial ability... there is always something. So I understand them.

2

u/drcforbin Sep 11 '24

Same for me, it's a great place to start. If you don't outgrow it, you saved a bunch of setup, ops time, and trouble. If you do need to graduate to a bigger tool, you haven't wasted any time either; you already have a good data model, you're already SQL, and porting should be straightforward

2

u/BasicDesignAdvice Sep 11 '24

Sounds like you have small clients? How do you find them? I would love to just do smaller scale work for multiple clients instead of what I do now (work for a big media company, luckily I get to do a lot of interesting things).

→ More replies (10)

255

u/Apoema Sep 10 '24 edited Sep 10 '24

I am a data scientist. I use a bunch of datasets that are mostly read only and infrequently used I found that the simplicity and flexibility of sqlite is a lot better for me than using something like postgresql.

181

u/keepthepace Sep 10 '24

I think it was SQLite's author who was saying that there is a misunderstanding about his lib. It is not a competitor to DBs like MySQL or postgres, it is a competitor to open(...) and file IO.

SQLite is not a database, it is a lib to do SQL requests to a local file.

DBs handle concurrency and this is their main feature and their main problem. SQLite does not handle it and does not care. And neither should you if you only have one user at the time.

63

u/anti-state-pro-labor Sep 10 '24

This is a great call-out and fits with how I understand SQLite. It's a wrapper over a file that just so happens to be a SQL interface. Glad to hear it's not far off from the intent of the lib!

38

u/xebecv Sep 10 '24

SQLite allows multiple processes safely write to the database (provided file locking works properly) and it provides atomic transactions using journaling, allowing for process crash resilience, so it's pretty much a database - not just "a lib to do SQL requests to a local file". What it lacks is the ability to be a distributed database. Backups, synchronization and failovers are on you

13

u/Kaelin Sep 10 '24

SQLite does not support parallel writes.

8

u/crozone Sep 11 '24

No, but it locks the database for you so that they're serialised safely.

→ More replies (1)
→ More replies (5)

21

u/tom-dixon Sep 10 '24

DBs handle concurrency and this is their main feature and their main problem. SQLite does not handle it and does not care.

That's false.

https://www.sqlite.org/draft/faq.html#q5

Q: Can multiple applications or multiple instances of the same application access a single database file at the same time?

A: Multiple processes can have the same database open at the same time. Multiple processes can be doing a SELECT at the same time. But only one process can be making changes to the database at any moment in time, however.

SQLite uses reader/writer locks to control access to the database.

...

However, client/server database engines (such as PostgreSQL, MySQL, or Oracle) usually support a higher level of concurrency and allow multiple processes to be writing to the same database at the same time. This is possible in a client/server database because there is always a single well-controlled server process available to coordinate access. If your application has a need for a lot of concurrency, then you should consider using a client/server database. But experience suggests that most applications need much less concurrency than their designers imagine.

They also have WAL-mode, which allows really fast operation when there's many concurrent readers and writers. Orders of magnitude faster than fopen() with manual locking.

https://www.sqlite.org/wal.html

→ More replies (3)

5

u/Apoema Sep 10 '24

I do believe that is the case and for a long time I was naively trying to use postgresql for one of my large datasets, it was a pain to setup and almost every time I was going to use it postgres had updated and nothing was working properly, it was also a pain to backup and restore.

I finally resolved to just use sqlite and break the database up in different files depending on years and that basically solved all my problems.

→ More replies (3)
→ More replies (2)

29

u/TheBananaKart Sep 10 '24

Pretty much my goto unless I know something will have a-lot of concurrent users. Works really well for a sales-estimation app I’ve made for work since I don’t have the bother of dealing with IT just put the file on a shared drive and alls good. Also works great for data logging for industrial applications, used in a few SCADA projects.

6

u/syntaktik Sep 10 '24

How are you handling the concern in the FAQ: https://www.sqlite.org/faq.html on section 5? No concurrency issues at all?

24

u/TheBananaKart Sep 10 '24

Simple we have like 3 engineers, normally only one is estimating at a time 😂 GO and my setup makes it fairly trivial to migrate the DB to something like postgres if it becomes an issue.

→ More replies (10)
→ More replies (1)

29

u/JustFinishedBSG Sep 10 '24

You need to try duckdb

3

u/darkcton Sep 10 '24

We're likely going to try it soon. Is it good?  How easy is it to host?

11

u/FujiKeynote Sep 10 '24

DuckDB is insanely good. To me, they've ticked all the checkboxes for what makes a piece of software great. Self-contained, smart design choices, great language bindings, and zero fluff.

A lot of it feels like magic, and part of that magic is in the fact there's no bloat and no added complexity to the stack. I actually have had legitimate use cases for extremely wide tables (bioinformatics at scale, you have like 60k genes in rows and an arbitrarily large number of datasets and samples in columns) and DuckDB chews through it like a champ.
And no need to think about your indexing strategy! Well, I guess almost no need—it does support explicit indexing—but for the vast majority of cases it "just works."

They also hit 1.0 recently, I can't name a reason not to use it.

13

u/longshot Sep 10 '24

It's the OLAP answer to SQLite

It is awesome

→ More replies (1)
→ More replies (1)

3

u/leros Sep 10 '24

I build small mostly read-only datasets (< 100MB). I'll put them in sqlite and even commit them to git alongside my code.

→ More replies (1)

107

u/EmergencyLaugh5063 Sep 10 '24

I worked at a company that stored hard drive backups in a sqlite database. What originally started as a quick way to get the product to market turned into a 10+ year abusive relationship.

I have a lot of respect for sqlite as a result. It processed enormous amounts of data and we were often limited more by just the speed of our drives than the database technology.

However, before adopting it developers should carefully consider what their long-term plans are. If they predict constant growth and a need to scale their solution then sqlite may not be the best solution and I would recommend just biting the bullet and going with something that has scaling in mind from the start.

For example:

At that company we reached a point where we needed concurrent access because we needed to start separating workloads amongst different processes. So we enabled WAL mode. At the time WAL mode was still kind of new so it's probably a lot better now, but we started to run into pretty big issues with checkpointing not working. This resulted in .wal files growing to sizes far larger than we were comfortable with and then when we finally forced a checkpoint the database would become unusable for long periods of time while it tried to process the large .wal file. WAL mode is simply not a solution to the concurrent access problem, it's more of a workaround and it comes with some additional costs to consider.

3

u/[deleted] Sep 11 '24

Why is it so hard to migrate a database? Isn't it just

go offline
mysqldump ... > db.sql
CREATE DATABASE db
mysql ... db < db.sql
go online

?

89

u/[deleted] Sep 10 '24

Sharded SQLite is very common for systems that require embedded data stores. It’s far from a toy, it was also designed for computerized missiles

54

u/avdgrinten Sep 10 '24

I'm a bit confused by the title. Why would it be a toy?

sqlite is the right solution if you need the processing offered by a database (say, CRUD operations, ACID semantics, queries) but you don't need a remote database because only a single service will ever connect to it anyway.

55

u/kherven Sep 10 '24

Some people who have worked exclusively with the "big" databases are sometimes horrified to see SQLite being used. It hits their ears the same way "We use a text file for our database" might to yours.

Of course that isn't a fair assessment, but I'm assuming that's the kind of person the article's assertion is trying to get through to.

20

u/Cosoman Sep 10 '24

Jokes on you, SqlServer uses 2 files for the database

→ More replies (5)

2

u/freefallfreddy Sep 11 '24

It’s a clickbaity title.

→ More replies (1)

14

u/Weird_Suggestion Sep 11 '24

Here is what SQLite authors have to say about when and when not to use SQLite. https://sqlite.org/whentouse.html

10

u/gnahraf Sep 10 '24

Yes. Also used at scale as units of sharded data both locally (e.g. on Android) and in the cloud (e.g. a db per user to store "user-state" on a game app or platform.) The sharding can be applied in other areas too. E.g. a db per game instance where players take turns to play. The basic requirement for such scaling is that the data flow is organized in such a way that there is at most one writer per db.

2

u/turbothy Sep 10 '24

(e.g. a db per user to store "user-state" on a game app or platform.)

Ooh. Neat idea.

2

u/Fabiolean Sep 11 '24

Web browsers do stuff like this. Use unique SQLite databases for each site you visit to store cookies and user data and more

8

u/FJ_Sanchez Sep 10 '24

It's getting trendy lately with projects like Turso (libsql) and LiteFS. There are also rqlite and Litestream. I recommend reading this https://fly.io/blog/all-in-on-sqlite-litestream/

10

u/hudddb3 Sep 10 '24

rqlite[1] creator here, happy to answer any questions.

[1] https://www.rqlite.io

4

u/FJ_Sanchez Sep 10 '24

You compare it to multiple other projects in the FAQ but not to Turso DB, how are they different? What do you think of libsql?

3

u/myringotomy Sep 10 '24

At that point you are already running a deamon so why not postgres?

14

u/wvenable Sep 10 '24

I don't think of it as a toy but I find the fact that (almost) everything is a string to be somewhat toy-like.

8

u/sidneyc Sep 10 '24

Well that's just not true. SQlite has a bunch of supported types.

https://www.sqlite.org/datatype3.html

11

u/wvenable Sep 10 '24 edited Sep 10 '24

That article describes the issue even better. "Flexible typing" for serious projects is not my jam.

8

u/Mognakor Sep 10 '24

Thankfully it supports strict tables as of November 2021

https://www.sqlite.org/stricttables.html

→ More replies (1)
→ More replies (8)

6

u/Takeoded Sep 11 '24 edited Sep 11 '24

SQLite is a perfect tool for you

$ sqlite3 
SQLite version 3.45.1 2024-01-30 16:01:20
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> CREATE TABLE tbl(str STRING);
sqlite> INSERT INTO tbl VALUES('0123');
sqlite> SELECT * FROM tbl;
123
sqlite> 

My biggest issue with SQLite is that the default affinity type is NUMERIC, it should have been "BLOB".

... used to have 3x of these retarded sqlite behaviors where data would be silently corrupted with no warnings/errors but I can't find my notes :( this is the only one I remember off the top of my head.

Remember one of the SQLite developers saying "we can't fix that now, it would break backwards-compatibility", though. As in, "we can't fix silent data corruption now, it would break apps that rely on silent data corruption."

Edit: found another one!

$ sqlite3 '' "SELECT 'foo' || x'00' || 'bar'" | wc -c
4
(it should have been 7)
sqlite3 '' "SELECT '123'" | wc -c 
4
(it should have been 3)
$ sqlite3 '' "SELECT x'00'||'123'" | wc -c 
1
(it should have been 4)

silent data corruption righ there. Data integrity is not important for SQLite 😔

5

u/Bognar Sep 11 '24

Thanks for this, it was my experience as well. Everyone goes on about performance and reliability, but I find it hard to care when there are basic problems with correctness.

I've used SQLite with wrapper libraries that try to account for these quirks and make it invisible to your chosen language, but I still worry about edge case correctness problems leaking through the abstraction.

28

u/garfield1138 Sep 10 '24 edited Sep 10 '24

We have all been there. "It's just a small project and SQLite will suffice" and 3 days later we're migrating to MariaDB/PostgreSQL.

58

u/vanKlompf Sep 10 '24

We have also been in „make it future proof, use enterprise Postgres”. And project is dead after 3 days

9

u/tothatl Sep 10 '24

Whenever feature creep starts going towards sharing the sqlite database state, the migration should be planned.

If it's not, get away from that rat hole.

3

u/bwainfweeze Sep 11 '24

So here's the trick that most of us miss out on.

Expensive changes that have to be made to retain your existing revenue stream tank your company, and generally negatively affect morale of the people who pay attention.

Expensive changes that have to be made to attract or retain new revenue are costs of doing business. There's new money to pay for the new work. I was about to say, "this is fine" but even I don't entirely believe that. This can be fine. Some people call these, "good problems to have".

"Oh no! We have so many customers we need to upgrade our database so we can keep raking in cash hand over fist! Anyway..."

4

u/OffbeatDrizzle Sep 10 '24

No no.. it's not a toy

1

u/shaze Sep 10 '24

We went to RocksDB :(

8

u/tothatl Sep 10 '24

It's also pretty darn fast.

You can feed it tables of millions of rows and do queries that would bring a lesser professional DB to its knees.

1

u/donatj Sep 11 '24

a lesser professional DB

I guess name the "lesser db". FoxPro or Bento? Sure.

Every time I've migrated from sqlite to mysql or mssql it's been for performance and the gains have been decent , even with the database running on the same machine

-1

u/garyk1968 Sep 10 '24

Not really. I worked in the city for 7 years in finance, we were building reg reporting repositories using mssql. Typical throughout was 10-15 million records per day…that need to be stored for 7 years. Not hating on SQLite as it’s awesome but mssql/oracle/postgresql would easily handle this volume.

13

u/bwainfweeze Sep 10 '24

I worked in the city for 7 years in finance

You are not the target audience for this thread. There's a giant space between 'not a toy' and 'golden hammer'.

→ More replies (4)

2

u/LIGHTNINGBOLT23 Sep 11 '24

One of the biggest issues I have with SQLite is that it doesn't support compressed rows/columns by default (not the same as entirely compressing and decompressing the whole database file). There's only a few half-baked extensions to do this, and then there's ZIPVFS which is offered by the SQLite developers, but you have to pay $4000 for it.

→ More replies (2)

2

u/Carighan Sep 11 '24

SQLite is not a toy database

That's just what a toy database would say! 😑

Jokes aside, I feel people aren't all that often even in this situation. I can count on one hand the times I had to introduce a new database without the decision having already been made by some circumstance or another.

2

u/lurebat Sep 11 '24

Duckdb anyone? It's pretty cool, versatile and supports better syntax.

5

u/scottix Sep 10 '24

I don't think anyone considers it a toy. It depends on the use case and how you plan to use it.

1

u/Ok-Bit8726 Sep 11 '24

It’s also the most widely deployed database in the world

3

u/[deleted] Sep 11 '24

I think the name is the problem. To me, “lite” makes me think “less than” or “not as good”, which I guess I’ve seen in other products that have been marketed as “lite”.

4

u/MaleficentFig7578 Sep 11 '24

But it is lite. It's very simple, a drop-in library, no complex administration, and with fewer features.

2

u/PabloZissou Sep 10 '24 edited Sep 10 '24

"This is a myth. In the write-ahead log mode (available since long ago), there can be as many concurrent readers as you want. There can be only one concurrent writer, but often one is enough."

That might be the case for some types of applications and very specific ones but that sounds like strong biased information, from that point on how can I know if the rest of the claims are accurate?

SQLite has its uses but it is not useful for everything.

1

u/Curious-Dragonfly810 Sep 11 '24

We use it for rocket science 🚀

1

u/Drakonluke Sep 11 '24

I manage a postgresql database with about a dozen tables and a few hundred records. At this point using postgres seems excessive to me and this post was very convincing. It's important data, but it will never reach millions of rows (it's an IT Hardware, Network and consumables management app for my work). How can I convert the database to sqlite?

1

u/bulletrhli Sep 11 '24

In our case we are adding roughly 3 to 5 million rows a year right now, with the possibility of increasing. We thankfully don't have a lot of traffic but the data is really important to retain long term for analysis. We just use mariadb, mostly due to familiarity. Not quite sure what the best case for us is. We maintain two databases with a total of maybe 10 tables but they are just densely packed. We will never have to change the amount of columns, and we have a decent index setup for our queries but by no means perfect.

1

u/nesh34 Sep 11 '24

So I'm a bit out of the game with respect to starting new professional projects, as I've been in big tech for 6 years.

Please correct me on the following understanding:

  • If you want an online transactional database that you may want to scale in future, use PostGres.

  • If you want an offline database (that for example lives on the client device), use SQLLite.

1

u/ElMachoGrande Sep 11 '24

Yep. Sometimes, small and simple is what is needed.

The same goes for Access. I've used Access a lot for single user desktop application with small (say, a few GB) databases, and for "database on file server" applications with few (2-3) users. I only use the database, I build front end in other tools.

I think the problem is that people tend to think in human scales. "My customer database is huge, it has thousands of customers!", when not even millions would count as anything but a small database.

Being able to install a program without having to add a database service, just a database file and some DLLs is a great thing in many cases.

1

u/ProjectInfinity Sep 11 '24

It's a decent database but I really dislike writing applications using it. It's just harder than it should be to avoid concurrency locking issues.

1

u/HoratioWobble Sep 11 '24

I use it for isolation applications and mobile apps quite often. Never had any issues. Never understood the hate for it to be honest.

If you have local, relational data, why wouldn't you?

1

u/audentis Sep 11 '24

I find it funny to say: "When you are [Role], [Technology] is perfect for you". Where's the use case in this consideration?

SQLite is great and I love it, but literally the first statement in the article is something I deeply disagree with.

1

u/Voidrith Sep 11 '24

I have a service that reads in a lot of metrics / telemetry data from a lot of different customers and needs to keep them isolated from eachother due to the wild differences in structure. Every customers dataset is a series of sqlite files, while all the administrative/orchestration is in a single big postgres db

sqlite is great for what i need it for. Its not perfect for everything.

1

u/st4rdr0id Sep 11 '24

100% of the interviewers for backend positions I've encountered don't acknowledge this. Having worked mostly in mobile development, I've worked with ORMs and SQL a lot, and that experience apparently doesn't count as real experience.

1

u/hughk Sep 11 '24

If you use the Adobe product Lightroom for photographic image management and processing uses SQLite. You can even do your own queries in it. The problem is that it isn't designed for multiuser.

1

u/The-Dark-Legion Sep 11 '24

You lost me on "Native JSON". If you store JSON documents in a relational database, you did something wrong along the way.

Normal forms, people. If your data doesn't conform to a schema, you chose the wrong technology!

1

u/anacrolix Sep 11 '24

False. There's a schema in there you just haven't found it yet

1

u/The-Dark-Legion Sep 11 '24

I agree. Not always, but 99,9% of the time it is true.

1

u/anacrolix Sep 11 '24

I built this on SQLite, give it a spin (C, Go and Rust bindings provided): https://github.com/anacrolix/possum

1

u/TCB13sQuotes Sep 11 '24

I just want Wordpress to officially support SQLite out of the box. Will work fine for 70% of the WP websites out there.

1

u/crusoe Sep 11 '24

For embedded tough to beat,

But SQLITE is pretty loosey-goosey when it comes to enforcing data types.

Oh, they finally added datatype enforcement in 2021. Cool

1

u/00nu Sep 12 '24

SQLite for simplicity, speed and maintenance.PG when tcp connections are needed (instead of api calls?!)

1

u/AbbreviationsFlat976 Jul 31 '26

Everyone talks about SQLite as the "little guy" of the bunch—and in a way, it is. But people also mistakenly assume that companies with fewer than 50 employees don't exist; there are companies whose databases barely reach 100 MB. There are scenarios where the requirements are simple: a local database for fewer than 10 users that works without an internet connection.

1

u/wjrasmussen Sep 10 '24

Look at that, SQLite is all grown up and out on the town.

Now go get your shinebox.

1

u/usrlibshare Sep 11 '24

Never was.

1

u/New_Computer3619 Sep 11 '24

Look left and right around you. If you see an electronic device like your phone, your security camera or even your car, it’s more likely than not that this device use SQLite.

0

u/Aedan91 Sep 10 '24

As is the case with 90% opinionated posts in this community, the answer is "it depends". It's certainly a toy for some use cases, it's more than enough for others.

→ More replies (1)

-110

u/OffbeatDrizzle Sep 10 '24 edited Sep 10 '24

SQLite is a perfect fit for small websites and applications

So it's a toy...

There is a popular opinion among developers that SQLite is not suitable for the web, because it doesn't support concurrent access. This is a myth. In the write-ahead log mode (available since long ago), there can be as many concurrent readers as you want. There can be only one concurrent writer

So it's a toy...

edit: lots of toy fanboys here

8

u/StellarNavigator Sep 10 '24

I guess you've never heard of the legend Pieter Levels! His tech stack is sqlite, javascript, jquery and makes a few millions a year.

-7

u/OffbeatDrizzle Sep 10 '24

What does that have to do with anything? I never said you can't make money with it

17

u/bloodhound83 Sep 10 '24

What do you mean when you call it a toy?

→ More replies (4)

31

u/Mognakor Sep 10 '24

This may come as a shock to you but there are applications besides web applications.

→ More replies (1)

47

u/pojska Sep 10 '24

Some jobs are big, some jobs are small. A good craftsman uses the right tool for the job.

-50

u/OffbeatDrizzle Sep 10 '24

Some hammers are toys, some can down brick walls. How does that contradict anything I said?

37

u/[deleted] Sep 10 '24

/u/OffbeatDrizzle uses sledgehammers to push in nails

17

u/pojska Sep 10 '24

It's hard to say where exactly your thought process is going wrong, because you've only said "so it's a toy," which is entirely wrong.

It seems like you're implying that any tool that is not useful for huge websites
software is not a tool, but rather, a toy. This is obviously incorrect. Toy databases exist, just like toy hammers. The key feature of a toy is that it is designed for play, not work. A large inflatable hammer is big, but a toy. A jeweler's hammer is small, but not a toy.

SQLite is not a toy database. It is used by professionals to get real work done. In a wide domain, it is the best tool for the job. Perhaps it is not suited for the narrow domain of software you have expertise in.

→ More replies (5)

7

u/SnooPaintings8639 Sep 10 '24

I have an app that has extremely static data, i.e. only the admin updates this when the customer needs some new items.

This RO reality, makes my app very easily and cheapliy scalable. Each of my nodes simply loads the db file from the shared resource on boot, and then it just works, very fast, very simple, and SQL compatible. I reload the db by either restart or execution of a dedicated entry point. Add as many nodes as needed.

This is as "toy", as any other "do one thing and do it well" tool.

3

u/davvblack Sep 10 '24 edited Sep 10 '24

idk it seems fine if the next closest solution is "committing json to your repo" for which there are certainly cases for, on the web. Git is a "database" in some sense, and "webscale" in some sense. There are certainly use cases where you may commit some data into a git repo to be used by a highly scalable application.

Those same usecases would compare favorably to times when sqlite might be the correct tool for the job, for example when the changes are slighlty-more-frequent than sldc, but still 'rare'.

I would be hard-pressed to think of a problem where the solution is "maybe postgres, maybe sqlite" but that's not necessarily it's next-most-similar solution.

"Maybe config files, maybe sqlite" is much closer.

1

u/MaleficentFig7578 Sep 11 '24

I would be hard-pressed to think of a problem where the solution is "maybe postgres, maybe sqlite" but that's not necessarily it's next-most-similar solution.

Any web app that only needs a single server, such as a personal blog.

3

u/ub3rh4x0rz Sep 10 '24

Having only one concurrent writer solidifies that it is not the right choice for web. I try to tell juniors who try to XY problem into getting it to work in a web context to just use postgres, and they're like "well that's just too complicated". No, too complicated is trying to manage locking of a pool of size 1 without severely throttling traffic yourself, especially as an inexperienced dev lol.

I do love sqlite for offline analytics of relatively small datasets, where concurrent writing isn't needed

9

u/QueasyEntrance6269 Sep 10 '24

It really depends, most applications are read-intensive. Use the tool that works for you, but especially with WAL mode (where you can read even during a write), one VPS is enough for most applications.

1

u/MaleficentFig7578 Sep 11 '24

sqlite handles locking for you. Remember to set busy_timeout and retry the whole transacion if you get SQLITE_BUSY - it can be because of deadlock prevention which ignores busy_timeout and fails immediately.

-2

u/OffbeatDrizzle Sep 10 '24

Are you agreeing with me? Nobody else does :(

19

u/bawng Sep 10 '24

You might be right that it's the wrong tool for the web but that doesn't make it a toy. Unless everything that isn't web is toys.

→ More replies (1)

-23

u/kobumaister Sep 10 '24

Sad to see people so emotional about technology, SQLlite is what it is, and has its (small and specific) use cases. I dont understand why people is downvoting you... Does the toy concept seem too offensive FOR A DATABASE THAT IS NOT INTENDED FOR PRODUCTION?

Get my upvotes.

13

u/Mognakor Sep 10 '24

Where the fuck are you getting that SQLite is not intended for production?

0

u/kobumaister Sep 10 '24

Experience. But let me be more specific: It's not intended for production of any serious project.

Why do you take it so personal? it's just a database.engine for smalls projects.

4

u/Mognakor Sep 10 '24

Experience

So personal opinion.

But let me be more specific: It's not intended for production of any serious project.

Considering the wide spread successful usage of SQLite in serious production systems (likely even the browser you or i use to argue), i think your experience is lacking.

Either you think the companies financing the living for 4 or so developers pay for support of their toy projects or they are stupid for using it in serious software for which it is not intended according to you.

3

u/OffbeatDrizzle Sep 10 '24

Don't tell them about mongodb

5

u/kronik85 Sep 10 '24

lol, what does production mean to you?

It's used everywhere. Mother. Fucking. Everywhere.

-2

u/kobumaister Sep 10 '24

Production means: resilient, stable, predictable and ideally scalable.

if you've seen SQLlite in production, I'm sorry but you are not working with serious products.

5

u/sociobiology Sep 11 '24

Firefox isn't a serious product?

3

u/MaleficentFig7578 Sep 11 '24

iPhones aren't a serious product?

1

u/kronik85 Sep 13 '24

it's "small and specific" use cases are 10,000x more numerous than every mega social-media company in the world. production != big. small != toy. you've got a massively warped perspective of what it means to be production ready.

0

u/[deleted] Sep 10 '24

[deleted]

2

u/bwainfweeze Sep 10 '24

How far are you away from worrying about it running out of head room? Have you made design changes to keep it from reaching that point?

0

u/[deleted] Sep 11 '24

[deleted]

2

u/MaleficentFig7578 Sep 11 '24

Concurrency is a big weakness, so is data typing.

1

u/LesterKurtz Sep 11 '24

I think it has a theoretical storage limit of 4TB. Maybe more since I heard that a few years back.

2

u/MaleficentFig7578 Sep 11 '24

They say 256TiB

1

u/LesterKurtz Sep 11 '24

That's pretty cool tbh.

0

u/[deleted] Sep 10 '24

[deleted]

3

u/MaleficentFig7578 Sep 11 '24

use sqlite and create table data (id varchar primary key, json varchar not null);

but once you have SQL you may wish for more schema than that, and you can do it.

1

u/anacrolix Sep 11 '24

You can use JSON extension in sqlite.

56

u/[deleted] Sep 10 '24

[removed] — view removed comment

8

u/SnooPaintings8639 Sep 10 '24

Yes it is. And it definitely needs (and deserves) more love in the space.

0

u/[deleted] Sep 11 '24

[deleted]

7

u/MaleficentFig7578 Sep 11 '24

What do NoSQL databases bring that SQL don't? you can always have a table with two columns: ID and JSON

0

u/[deleted] Sep 11 '24

[deleted]

2

u/CherryLongjump1989 Sep 11 '24 edited Sep 11 '24

There’s a reason why Google went from BigTable to BigQuery. You don’t hear about BigTable anymore now that you can access it via SQL. Even the platforms you mentioned such as Clickhouse offer a SQL API, as do many that you didn’t mention like Elasticsearch or Singlestore. SQL is not the problem, you’re confusing the query language with an RDBMS. These days if you don’t support SQL then that’s a liability that makes your database less likely to be adopted.

As far as embedded databases such as SQLite or DuckDB, the whole advantage is that you have SQL and ACID properties for every situation that calls for local storage or low-latency in-memory access, where none of your NOSQL solutions would be appropriate. It vastly expands the number of use cases for which a database is appropriate. It’s used for everything from config files to text messaging clients. There’s a reason why SQLite is actually the most prevalent database in existence. You don’t need a team of on-call engineers to administrate and handle server outages for the SQLite database in your iPhone app. SQLite also has the distinction where it’s actually part of standardized file formats, such as for geospatial data used by everyone from consumer to military use cases. People even build offline apps with eventual consistency by using an embedded database that eventually syncs with some server-side data store.

0

u/[deleted] Sep 11 '24

[deleted]

2

u/CherryLongjump1989 Sep 12 '24 edited Sep 12 '24

I’m not aware of people choosing BigTable outside of legacy reasons. There are countless more modern alternatives. Internally at Google, where I worked, we used higher level APIs built on top of BigTable, or have been swapped out for better more modern things than BigTable. BigQuery itself is built on top of these intermediary APIs. I’m not sure why someone would choose to use BigTable directly for a brand new project. Maybe they are misinformed?

Moreover, the vast majority of BigQuery users - as well as most other “big data” large distributed database systems - don’t have anywhere close to the amount of dara that justifies their use and complexity. Or if they do have a lot of data, most of it is useless junk and they’re paying tons of money for the privilege of having poor data hygiene.

Neo4J is a great example of a database that is poorly adopted. For as old as it is, countless SQL databases have come after and ran circles around it. There are far more people doing graph queries in databases that support SQL. Neo4J is particularly infamous for having a convoluted API. Plus, graph databases themselves are notoriously difficult to design because different graph problems call for entirely different database designs. Neo4J is the type of system that you end up migrating away from.

I don’t understand a lot of your strawman and goalpost shifting arguments. No one ever said NOSQL can’t be ACID or that in-memory data can’t be organized without an embedded SQL database. I don’t know where you came up with those weird tangents.

I’m glad you’re familiar with MBTiles and such. Look up what the military is doing with it. Your next generation stealth fighter jet isn’t going to be querying an S3 bucket while it’s flying over Iran. You have a bias towards online client-server systems, clearly.

You mock SQLite in message clients but I put up all the messages on every iPhone on the planet against whatever data you can shake a stick at in some “big data” client-server database. And it is faster and lower latency than your best “BigTable” solution. That’s one huge multi-tenant distributed database that you would be killing yourself to try to shove into a client-server solution. That’s what you’re not seeing. You have a bias toward shoving as much data as you can into a single centralized store whether or not it makes any sense to do so. You’re telling me that an embedded SQL database can’t solve a problem of your own creation, and I’m flabbergasted. The embedded database eliminates the problem. That’s why SQLite exists.

19

u/[deleted] Sep 10 '24

[removed] — view removed comment

4

u/Habba Sep 11 '24

Yeah this has been my experience too. Having been writing some web services in Rust (because I like the language and these are for fun) I've even found that I don't need multiple workers since the service can easily handle tens of thousands RPS.

If I ever needed to scale this up my plan would actually be just having additional SQLite files/worker pairs, since for my use case that's easy to do.

1

u/[deleted] Sep 11 '24

[removed] — view removed comment

5

u/Habba Sep 11 '24

I have been using Axum and been happy with it! It's for building APIs, so only backend, for frontend I have been using it with htmx because it's easy to get interactivity and I don't need to learn JS for it.

If you would want to do full stack in Rust, I have some experience with Leptos and that has been really nice.

As for Rust, it is a very cool language IMO. It will feel really annoying at first coming from Python (it did for me) because it just does not let you do things that are not a problem in Python. For me it clicked when I realized that it was just forcing me to fix bugs while I wrote them instead of having to hunt them down when the program is already running.

1

u/gmes78 Sep 11 '24 edited Sep 11 '24

Axum.

Though, keep in mind that doing web (and async stuff in general) may be a bit awkward as a first Rust project. Axum does some fancy stuff in its API that seems like magic if you're not comfortable with Rust.

1

u/[deleted] Sep 11 '24

[removed] — view removed comment

1

u/MaleficentFig7578 Sep 11 '24

Most apps don't have this and don't corrupt databases.

2

u/TCB13sQuotes Sep 11 '24

Yeah, there must be something wrong with that app's implementation.

1

u/[deleted] Sep 11 '24

[removed] — view removed comment

2

u/MaleficentFig7578 Sep 11 '24

Literally most apps.