News for hackers. Stuff that matters.
Re:Hctree is an experimental high-concurrency database back ... by simonw on Wednesday January 18, 2023 @05:47PM (#34434222)
Concurrent writes and replication!

See also this thread on the SQLite forum: https://sqlite.org/forum/forumpost/d9b3605d7ff40cf4

Re:Hctree is an experimental high-concurrency database back ... by metadat on Wednesday January 18, 2023 @05:50PM (#34434242)
The linked performance graphs look remarkably promising, indicating hctree with 25% smaller pages scales to 1 million transactions per second:

https://sqlite.org/hctree/doc/hctree/doc/hctree/threadtest.w...

Re:Hctree is an experimental high-concurrency database back ... by freeqaz on Wednesday January 18, 2023 @08:33PM (#34435634)
Nit: 1kb pages vs 4kb pages, so 75% smaller (25% of the size).
Re:Hctree is an experimental high-concurrency database back ... by metadat on Wednesday January 18, 2023 @08:46PM (#34435728)
Oops, yes thank you for the correction!
Re:Hctree is an experimental high-concurrency database back ... by michaelcampbell on Friday January 20, 2023 @08:43AM (#34452999)
Thank you. One of my (granted, OCD driven) peeves is the recent ubiquity of framing that sort of comparison as "3 times smaller!". Ohmygod, no.
Re:Hctree is an experimental high-concurrency database back ... by jimnotgym on Wednesday January 18, 2023 @06:26PM (#34434625)
It makes me wonder why I would use anything else?
Re:Hctree is an experimental high-concurrency database back ... by Aperocky on Wednesday January 18, 2023 @06:42PM (#34434761)
even when this is not the case, sqlite works well enough to replace maybe 80% of heavier database setup out there.

Scaling and ability to scale is very valuable, but I would guess massive premature scaling is much more common than scaling cliffs - especially as they don't get reported or have nearly as much visibility.

Re:Hctree is an experimental high-concurrency database back ... by fierro on Wednesday January 18, 2023 @06:56PM (#34434871)
the fact that SQLite is a library (embedded DB) means only one node can access the DB at a time. This would not be appropriate for many apps that require HA.
Re:Hctree is an experimental high-concurrency database back ... by Aperocky on Wednesday January 18, 2023 @07:38PM (#34435233)
Indeed, SQLite should not be used anywhere that scaling or concurrency is a concern, or in general any external customer facing features.

In a similar vein, an internal subsystem can probably do away with a dedicated database server.

Latter is likely more common.

Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @07:48PM (#34435305)
That's silly. SQLite works fine for all sorts of customer features, and, deployed carefully, is fine with concurrency (writes are serialized, per database, but SQLite makes it easy to use multiple databases). SQLite has this weird reputation, I think, because frameworks like Rails used it as their "test" database, and the industry has broadly slept on how capable SQLite is in serverside applications.
Re:Hctree is an experimental high-concurrency database back ... by AlphaSite on Wednesday January 18, 2023 @08:00PM (#34435403)
I think if you use a lot of database features, sqlite isn’t really powerful enough for a lot of use cases IMO. Or atleast that’s the impression I have.
Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @08:02PM (#34435419)
Which features would those be?
Re:Hctree is an experimental high-concurrency database back ... by luckylion on Wednesday January 18, 2023 @08:26PM (#34435589)
Concurrent inserts. There are applications where you don't care about that, but that excludes a lot of web-apps, or things running with multiple processes.

If that changes, I'd agree with your point, but currently that's a big constraint.

Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @08:29PM (#34435607)
How exactly does that exclude a lot of web apps? Most web apps are very read heavy. And SQLite serializes writes to individual databases, not across all of them. It's trivial in SQLite to query across multiple databases.

Further, some form of write serialization is common to most database clusters: the most common cluster architecture is single write leader, multiple write replicas, which have the effect of serializing writes as well. Those clusters are all also taking advantage of the read-heaviness of applications.

Re:Hctree is an experimental high-concurrency database back ... by luckylion on Wednesday January 18, 2023 @08:41PM (#34435696)
Many web apps also write a lot. Are you suggesting to have individual databases per process and then read from all of them and aggregate the data you want in memory? That would sound too much like I'm building a database, which I don't want to do.

I'm not talking about clusters and replication, just a single database on a single server, like Wordpress for example. It can handle large amounts of concurrent users if you're using InnoDB (which has been the default since how long?) and nobody will even notice that there's anyone else because it's not locking the table (or the whole database) to write, and you don't have to wait or deal with frequent busy timeouts.

Re:Hctree is an experimental high-concurrency database back ... by simonw on Wednesday January 18, 2023 @08:50PM (#34435761)
Most SQLite writes can be measured in microseconds. If your app is doing less than 1,000 writes a second you probably won't even notice that SQLite is serializing your writes rather than applying them concurrently.
Re:Hctree is an experimental high-concurrency database back ... by luckylion on Wednesday January 18, 2023 @09:41PM (#34436115)
I must've been doing something wrong then, I've regularly hit longer locks as soon as the DB grew, to the point that it was not usable for me with multiple processes writing in the same DB because it was constantly locked by one.

Having one writer and multiple readers was fine, but even having a dozen writers who update something a few times per second quickly led to the DB becoming the bottleneck. I tried different modes, but saw no difference so I just gave up on using it concurrently.

Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @09:43PM (#34436120)
I spent a bunch of time wrestling with this last year (and into this one), and the general solution I settled on was to serialize writes through a single writer; multiple reader threads and multiple writer threads (or processes) is not a fun configuration to put SQLite in.

There were 500MB-40G databases, probably ~1.5 updates per second at peak load?

Re:Hctree is an experimental high-concurrency database back ... by sqlcommando on Thursday January 19, 2023 @12:19AM (#34436977)
I think "web app" is too broad a category to have this kind of discussion over.. for a lot of web apps 1.5 updates per second could be considered a reasonable limit. Many people work on web apps that do 100x that and don't consider themselves to be working at any particular level of scale. 1.5K updates/sec is not uncommon either, in different settings -- high-traffic internal web apps can hit that in a single company, and the people working in those contexts don't consider that too special either, not to mention public facing websites like GH where many people start their careers without having seen anything different.
Re:Hctree is an experimental high-concurrency database back ... by tptacek on Thursday January 19, 2023 @12:44AM (#34437113)
I'm not benchmarking SQLite, I'm relating the environment in which I was tuning SQLite concurrency, because I feel like it doesn't mean much to say "here's what worked for me" without at least some basic facts about what I was working on. SQLite itself can do tens of thousands of writes per second on commodity hardware without breaking a sweat.
Re:Hctree is an experimental high-concurrency database back ... by ec109685 on Thursday January 19, 2023 @03:14AM (#34437919)
There's more to most applications than interactions with the database. Once your web app exceeds the capacity of a single machine, is SQLite a good choice for state?
Re:Hctree is an experimental high-concurrency database back ... by russell_h on Wednesday January 18, 2023 @08:54PM (#34435796)
I think he’s saying to shard writes by tenant, or something else that makes sense for your app - so you can route reads to an individual shard. Same as you’d do to shard any other database, if a little more DIY.

Speaking of Wordpress though, that’s a pretty great example of a web app that typically handles almost exclusively reads. I’ll bet almost any Wordpress instance would work great on SQLite.

Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @09:34PM (#34436066)
WordPress is the archetypical application that SQLite would kill for, but for historical reasons, WordPress has always wanted MySQL. It's funny, because there's a whole movement towards static sites that is, in part, a reaction to how bad the n-tier architecture behind WordPress is!
Re:Hctree is an experimental high-concurrency database back ... by luckylion on Wednesday January 18, 2023 @10:15PM (#34436297)
They're working on supporting SQLite as a backend: https://make.wordpress.org/core/2022/12/20/help-us-test-the-...
Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @10:24PM (#34436352)
It's crazy that this is only happening as of 2022, right? They could have kept a whole generation of web sites on WordPress by eliminating the MySQL dependency, and gained a performance and deployability advantage in the process. Even multitenant WordPress would have come out great with SQLite. I'm waiting for someone closer to WordPress to tell me how wrong I am about this, because I have to be missing something.
Re:Hctree is an experimental high-concurrency database back ... by luckylion on Thursday January 19, 2023 @09:35AM (#34440679)
I'm not sure that it'll bring a lot of sites back to or keep them on WP, but it'll be great for testing. Much of it is always integration testing with WP because of how filters and actions work your code is rarely ever isolated, SQLite will make that much easier and faster.

It's also really not a big switch for the most part. I'm not aware of that many MySQL-specific things happening in WP. Things like fulltext indexes aren't in core, so it's really just using a different driver to get the basics working. I'm sure it would break a lot of plugins, but that's fine, they have platform requirements anyhow, adding "does work with sqlite" isn't a huge step and can likely be automated to a high degree (if the plugin never uses wpdb->query, ->get_results etc, it's compatible).

Re:Hctree is an experimental high-concurrency database back ... by ec109685 on Thursday January 19, 2023 @03:19AM (#34437947)
And to be clear, this would be a single instance of the WordPress php application that all traffic would route to, and it would access the SQLite database on that node?

If that node failed, then the php application and database would be restored to a new machine and traffic would resume?

Re:Hctree is an experimental high-concurrency database back ... by syastrov on Thursday January 19, 2023 @04:01AM (#34438196)
I did an experiment of switching an app which uses Postgres to use SQLite. I ran into issues where I had a long running transaction in one process doing writes and another process doing reads and writes. As soon as the second process tried to do any writes, I would often get the queries running into locks and aborting. Otherwise, it worked great for reads and sped up the app a lot as there were lots of N+1 queries issues.

This is also after playing with settings about WAL mode.

It would not be a viable solution to split these tables into separate databases to avoid the concurrency issue. Also, most of the issues involve writes to the same tables.

Is there honestly any way to get that working well with current SQLite or do we need to wait for hctree or begin concurrent to mature?

I would be concerned that to get this working in its current state would require a large refactoring of the app which would require a lot of effort and would introduce limitations that make coding more difficult.

Re:Hctree is an experimental high-concurrency database back ... by cldellow on Wednesday January 18, 2023 @08:51PM (#34435772)
Maybe I'm using SQLite wrong, but I have a website scraper. It's written in python and so uses processes for concurrency to avoid GIL issues.

On my laptop, 16 processes accessing the same SQLite db file can do something like 5,000 write transactions/second. That seems like plenty for many purposes?

A caveat: it's in WAL mode, with synchronous mode set to NORMAL. This means that it's not fsyncing the WAL on each individual transaction commit. Instead, they get synced in batches roughly every 200ms. If you pull the power plug on the server, it may lose some amount of writes that happened in that time. Terminating the process is fine.

Yeah, yeah, we're giving up some amount of durability. In practice, not very much (200ms of transactions) and only very rarely (when the server dies). That seems like a fine trade-off for many backend processes and many web apps. You could tune this, as well: for the transactions that you _really_ want durability on, run a checkpoint before rendering your response to the user.

Re:Hctree is an experimental high-concurrency database back ... by fierro on Thursday January 19, 2023 @01:48PM (#34443953)
won't long running write transactions block eachother? Not all apps can avoid the need for these kinds of transactions.
Re:Hctree is an experimental high-concurrency database back ... by MobiusHorizons on Thursday January 19, 2023 @12:10PM (#34442747)
Care to justify that? The evidence seems to be against you for most read heavy workloads, especially if latency is any concern.
Re:Hctree is an experimental high-concurrency database back ... by zie on Wednesday January 18, 2023 @07:02PM (#34434920)
May I introduce you to https://litestream.io
Re:Hctree is an experimental high-concurrency database back ... by bsaul on Wednesday January 18, 2023 @07:14PM (#34435028)
I don’t see how sqlite replicated to other servers can be faster than any other relational dbs replicated on those same servers, at least without taking more chances to loose data. The limit is most likely network latency anyway, isn’t it ?
Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @07:49PM (#34435315)
Other relational databases require network roundtrips to fetch information from the database once it's replicated. SQLite doesn't. It's a huge performance difference, to the point where it changes how you access your database; for instance, there's not much point in hunting down N+1 query patterns anymore.
Re:Hctree is an experimental high-concurrency database back ... by bsaul on Thursday January 19, 2023 @03:17AM (#34437933)
hm i see.

so the cost is in the initial setup of the client instance, which needs to download the whole database to its local sqlite ?

Re:Hctree is an experimental high-concurrency database back ... by luckylion on Wednesday January 18, 2023 @07:15PM (#34435030)
From what I understand, that streams the file to a separate location, but it doesn't change the file-locking, does it?
Re:Hctree is an experimental high-concurrency database back ... by zie on Thursday January 19, 2023 @10:31AM (#34441345)
Right, for a SQLite based app, you are mostly limited to 1 instance running at any given time(there are multi-node stuff shoved behind SQLite done by 3rd parties, but that's a whole diff. can of worms).

The point being, you run 1 instance and you have litestream replicate to your backup node for HA purposes.

Now you are going to think, what about scaling?!!? How many apps actually need to scale beyond 1 node? Very few. If you run into scaling problems, that is when you deal with solving your scaling problem. Because scaling is unique to each application. But before you remotely think about scaling past one node, you just build the node bigger. Nodes can get pretty massive these days.

Re:Hctree is an experimental high-concurrency database back ... by hamandcheese on Wednesday January 18, 2023 @08:47PM (#34435742)
Litestream didn’t exist until late 2020, meanwhile postgres has existed for decades.

Moreover, SQLite requires the place you run your application to have durable storage, which is a huge departure from the status quo.

It’s definitely neat, but the stack as a whole doesn’t strike me as mature enough to replace Postgres just yet.

Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @09:38PM (#34436102)
You're writing this as if LiteFS and Postgres were basically the same thing, and the selection criteria just boils down to the Postgres pedigree and maybe all the Postgres-specific SQL features. But that's not the case at all. The difference between replicated SQLite and Postgres is that SQLite is in-core: it doesn't have to round-trip on the network to fetch data; it can burn through a large set of N+1 queries faster than Postgres can handle a single select. The difference is that SQLite is much faster.

You sacrifice things to get that speed (Postgres features, set-and-forget write concurrency). Nobody is saying there's no reason to use Postgres, or maybe even that Postgres is the right call most of the time. But the idea that SQLite is rarely appropriate for concurrent serverside applications? It's received wisdom and it's wrong.

Somebody across the thread actually suggested that WordPress was an example of the kind of application that SQLite wouldn't work for, that needed an n-tier database. (Leave aside the fact that WordPress doesn't support SQLite, has instead a longstanding MySQL dependency). WordPress! WordPress is a perfect example of a concurrent serverside application that probably should almost exclusively use SQLite. As I said in a different comment: the whole movement towards static site generators is, in large part, a reaction to how bad n-tier databases are for a very large, popular class of concurrent serverside applications.

Re:Hctree is an experimental high-concurrency database back ... by hamandcheese on Wednesday January 18, 2023 @10:12PM (#34436278)
My second paragraph was specifically talking about the gigantic difference between operating a stateful application vs. a more typical stateless app + stateful DB. Most people aren’t deploying to Fly.io (yet!), so making Litestream work sounds pretty high risk to me :) combined with the lack of pedigree I led with, I just don’t see litestream as a good answer to “I need a HA database solution” for most people.
Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @10:19PM (#34436318)
Litestream isn't a Fly.io feature.
Re:Hctree is an experimental high-concurrency database back ... by hamandcheese on Wednesday January 18, 2023 @10:43PM (#34436460)
No, but the ability to deploy it on stateful containers is.
Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @10:46PM (#34436475)
I'm sorry, I don't understand any word of that sentence (for instance: we don't run containers?). We sponsor Litestream and LiteFS (in the sense that we pay Ben to work on it full time), but no part of Litestream is baked into or in any way coupled with our platform. If you can run Litestream on Fly.io, you can run it anywhere else.
Re:Hctree is an experimental high-concurrency database back ... by hamandcheese on Wednesday January 18, 2023 @11:05PM (#34436582)
> for instance: we don't run containers?

You "transmogrify container images into Firecracker micro-VMs" - surely you knew what I meant?

And there is no denying that fly.io is a _particularly_ well suited platform to run stateful SQLite apps (with or without Litestream), since fly makes running stateful applications easy. I think thats awesome.

I'm really confused why you seem to be trying to distance yourself from that, and why you are latching on so hard to my passing mention of fly. I wasn't making a dig, just pointing out that most people are stuck with (arguably worse) platforms that don't lend themself to stateful, "in-core" databases.

Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @11:45PM (#34436789)
My confusion is that there's nothing container-y about Litestream. It works anywhere SQLite does. I like our platform a lot, but I mean, Litestream works just as well on AWS.

I'm just confused, is all. :)

Re:Hctree is an experimental high-concurrency database back ... by chillfox on Thursday January 19, 2023 @12:25AM (#34437002)
For most of the world (outside silicon valley) stateless is not the typical. The typical is stateful app + stateful DB run on stateful VMs.

For most enterprises, running a stateful app with SQLite is not only possible, it's easier than running stateless apps as their entire IT infrastructure is setup to support stateful apps and it's what their sysadmins know how to do.

I have tried to deploy stateless docker container apps into a typical enterprise network and it's a nightmare. The people done understand it, are not interested in understanding it, none of the infrastructure supports it and if you want to setup something like Kubernetes then you end up in configuration hell as none of the easy to deploy standard setups actually work out of the box in an enterprise network, everything ends up needing highly customized configuration to work.

Re:Hctree is an experimental high-concurrency database back ... by ec109685 on Thursday January 19, 2023 @03:12AM (#34437906)
If your application exceeds the capacity of a single server (e.g. a Java Web Service that is backed by a database), do you see SQLite as a useful solution for that case?

That seems like when you'd need a standalone database, no?

Re:Hctree is an experimental high-concurrency database back ... by vidarh on Thursday January 19, 2023 @06:40AM (#34439258)
If you think the capacity will never exceed that one standalone database. If not, you'll need to plan for sharding anyway, in which case sqlite can work just fine.
Re:Hctree is an experimental high-concurrency database back ... by ngrilly on Thursday January 19, 2023 @05:18AM (#34438709)
> SQLite requires the place you run your application to have durable storage, which is a huge departure from the status quo.

Having durable storage used to be the status quo for decades. It changed only recently with cloud providers (or their customers) pushing for stateless workloads because they are much easier to manage in a distributed system than stateful workloads.

Re:Hctree is an experimental high-concurrency database back ... by zie on Thursday January 19, 2023 @10:38AM (#34441441)
SQLite has been around for a very long time, it is easily the worlds most deployed SQL database. Litestream is just a way to do live sync/replication to make HA easier.

There are certainly use cases where SQLite is not a good fit. There are likewise use-cases where PostgreSQL is not a good fit either.

One is not better than the other, it just depends on your particular needs for that particular project.

My point is, SQLite is a totally sane and reasonable storage/DB solution for many server side applications as well.

Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @07:50PM (#34435317)
Only one node can write to a given SQLite database at a time. SQLite handles concurrent readers swimmingly.

The fact that SQLite is a library has not that much to do with its concurrency model?

Re:Hctree is an experimental high-concurrency database back ... by beoberha on Wednesday January 18, 2023 @08:02PM (#34435416)
What do you do if the node running the SQLite instance goes down?
Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @08:03PM (#34435423)
The same thing you do in a multi-reader, single-writer MySQL cluster, except with SQLite there's one less thing to go down, because the database is embedded in your process.
Re:Hctree is an experimental high-concurrency database back ... by beoberha on Wednesday January 18, 2023 @08:09PM (#34435453)
I’m not familiar with MySQL specifically, but people worried about HA have standby replicas. Enterprise DBs make this almost trivial to do and it’s very possible with PG extensions. I’m sure someone has built a system like that with SQLite, but it’s much less ideal than other database systems.
Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @08:20PM (#34435539)
Exactly what is "less ideal" about it? SQLite has distinct advantages over n-tier databases: it's embedded, so you're not round-tripping to the network for fetches, which makes simple query patterns that are untenable for things like Postgres reasonable for SQLite. It's also, of course, faster (about as fast as you can possibly get) for some access patterns.
Re:Hctree is an experimental high-concurrency database back ... by beoberha on Wednesday January 18, 2023 @08:29PM (#34435611)
We’re not talking about latency though. The argument is around the HA story. Totally agree that if your app and DB are on the same machine and if HA isn’t a hard requirement, SQLite is probably what you should go to before PG.

However, if you can’t have any downtime, you’d have to build some bespoke solution to make sure you have standby replicas ready to go if there’s an issue on the primary instance. For a lot of enterprises, that’s a total nonstarter.

Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @08:31PM (#34435622)
We're going around in circles. You can replicate SQLite. What makes replicated SQLite "less ideal" than n-tier databases?
Re:Hctree is an experimental high-concurrency database back ... by kthejoker2 on Wednesday January 18, 2023 @10:07PM (#34436253)
Just playing devil's advocate (I don't have much of a dog in the fight):

* SQLite's replication isn't built in, you have to use another library (LiteStream, LiteFS, etc) to achieve it. That in itself is an indication it's not inherently designed for such, and at a minimum will require a lot more testing to ensure your HA/DR failover scenarios work like you're envisioning. Perception matters.

* Litestream, LiteFS today are in "beta mode", fairly DIY, mostly CLI and YAML configs, making it comparatively complex and error-prone to configure vs. most n-tier databases which offer OOTB replication via GUI, and it's usually just a checkbox with cloud PaaS databases.

* "No one ever got fired for choosing IBM" there are tons of blogs and walkthroughs of setting up HA/DR for all the major RDBMSes, it's a safe choice if you run into any issues, whereas you might find yourself deep in an obscure dev forum debugging Docker dependencies or networking protocols. It's a risk.

* Needless to say, commercial support also matters.

* On LiteStream's own tips page ( https://litestream.io/tips/ ) there's a subheader called "Data Loss Window", if I were competing in any way with this solution, I think I'd bring that up pretty early.

Broadly, I think it'd be fine for a lightly written, mostly read OLTP system that's relatively stable. Anything else and I might get itchy about relying on just the WAL for replication.

SQLite fills a great ethos of "no muss, no fuss" but replication a lot times is 100% fuss.

Re:Hctree is an experimental high-concurrency database back ... by mbreese on Wednesday January 18, 2023 @10:34PM (#34436406)
It seems like you keep missing the SQLite caveat — it’s the same process as your application. HA doesn’t make sense here in the context of SQLite by itself.

Here’s how I think about it, but I don’t do replicates with SQLite often, so I might be wrong.

You really can’t compare SQLite to a Postgres or MySQL or Oracle server. With a database server you worry about replication/HA etc for the server. If the server is up, it can be queried, independent of the application.

With SQLite, you worry about replicating the data. If your application is running, it can access the data. You just need to make sure the data is consistent between nodes (if you use multiple nodes).

The data can be replicated, but if your SQLite node goes down, there’s no need to worry about the application because that means the application is also down. Similarly, if the application is up, your database is also up!

Re:Hctree is an experimental high-concurrency database back ... by beoberha on Wednesday January 18, 2023 @11:49PM (#34436809)
I mean this is our entire point. SQLite isn’t built for HA. You’re stuck replicating it yourself or using non-enterprise-ready solutions. It’s not SQLite’s fault, it’s just not the tool for the job if you need HA.
Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @11:52PM (#34436818)
SQLite is one of the most reliable codebases in the industry. You're ignoring what the comment says. In an n-tier architecture, both your app server and your database server needs to be HA, because they're servers. With SQLite, the app server is the database server. It's still HA, there's simply one fewer thing to HA-ify.

I don't know what "non-enterprise-ready" means, but it sounds like a selling point to me. The XML can come later.

Re:Hctree is an experimental high-concurrency database back ... by vidarh on Thursday January 19, 2023 @06:13AM (#34439078)
When the app server is stateless, HA for the app server is usually a near trivially easy problem to solve though, and a whole lot of web devs are used to treating the database as a black box that they'll treat as always up so I get the fear and uncertainty of suddenly having the HA setup interfere with "their" domain.

Coming at it from a devops angle, I'm used to being the one to have to deal with the database HA myself, and then having one tier less becomes a lot more appealing, and not really more scary than ensuring any other database setup is resilient.

Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @10:22PM (#34436337)
The comment I replied to upthread was also talking about n-tier replication features that weren't built in.

LiteFS isn't the only way to replicate a SQLite database.

Do you want Oracle servers? Because "Nobody got fired for choosing IBM" is how you get Oracle servers.

If you read just one additional sentence in to the Litestream "Data Loss Window" section, you'll find: "This is how many replication tools work including PostgreSQL’s log-shipping replication".

I don't know what you mean by "relying on just the WAL". The WAL is the database. What else would you replicate? How are you contrasting this against Postgres replication?

Re:Hctree is an experimental high-concurrency database back ... by chillfox on Thursday January 19, 2023 @12:43AM (#34437109)
Sometimes I honestly think that the problem is that the SQLite ecosystem makes it easy to understand how things work, so people get scared. Whereas other things comes off as magic and magic is comforting, you don't need to know how it works, you can just trust it.
Re:Hctree is an experimental high-concurrency database back ... by layla5alive on Thursday January 19, 2023 @02:30AM (#34437669)
100%

On so many topics, this is the answer. People want a pleasant fiction of clean abstracted magic.

Re:Hctree is an experimental high-concurrency database back ... by MobiusHorizons on Thursday January 19, 2023 @12:08PM (#34442713)
It is so hard for me to imagine ever trusting magic, but I think you are very right that people seem to prefer it. I think this discrepancy explains so much of the conflict I get into in my career.
Re:Hctree is an experimental high-concurrency database back ... by ngrilly on Thursday January 19, 2023 @05:06AM (#34438605)
> LiteFS isn't the only way to replicate a SQLite database.

What are other ways to replicate that you're aware of?

Another approach I like is to use a replicated block storage like GCP Regional Persistent Disks. This is making failover trivial. But then I'm not sure the replica can be used as a read-only copy.

Re:Hctree is an experimental high-concurrency database back ... by vidarh on Thursday January 19, 2023 @06:31AM (#34439199)
> What are other ways to replicate that you're aware of?

Litestream (wal -> object storage), Rqlite (wrap in http layer + raft + streaming changes between nodes; rqlite kinda defeats much of the purpose for me), Dqlite (in-process server-thread + raft + streaming changes; dqlite obscures that there are server threads plus network communication involved, but it's there), LiteReplica (VFS extension streaming to a replica), Verneull (VFS extension -> object storage), Sqlite Ceph VFS (VFS extension storing to RADOS)

Very different sets of tradeoffs. E.g. several of these requires you to run a separate tool to do the replication. Several depends on object storage either for the primary storage (the Ceph extension) or as the replication target / to restore from, which may be fine if you already have a compatible object store. Some can use e.g. Consul to control which server is the writer.

> Another approach I like is to use a replicated block storage like GCP Regional Persistent Disks. This is making failover trivial. But then I'm not sure the replica can be used as a read-only copy.

Block storage that can guarantee in-order read/writes is fine. Network filesystems that can guarantee in-order writes and support proper locking can also allow writes (with the usual caveats) from multiple nodes. The problem here is that you really must be sure, and often - e.g. for NFS - it can appear to work just fine but be just broken enough you'll run into it at just the wrong moment.

Re:Hctree is an experimental high-concurrency database back ... by beoberha on Wednesday January 18, 2023 @11:40PM (#34436758)
I will throw my weight behind this reply as what I would have written if I had the time and energy :)
Re:Hctree is an experimental high-concurrency database back ... by throwaway892238 on Wednesday January 18, 2023 @11:51PM (#34436813)
Abstractions. Sometimes you need them. Different operating systems, CPU architectures, applications, clients, libraries, versions, hell different companies running proprietary apps, licensing, regulations... A database with a dumb network socket on a random host is fairly well abstracted.

As far as HA goes, that abstraction can then go toward allowing your apps and DB to be built for different reliability/durability/etc requirements, potentially saving money, gaining better performance or reliability, meeting weird compliance requirements, contractual requirements, vendor or software limitations, etc.

It's also easier to troubleshoot and maintain the database separate from the application in some circumstances. If SQLite is bundled with your application, it might be harder to deal with a problem affecting one or the other. In traditional organizations, you can hire people to manage databases and people to manage applications, rather than one person who has to deal with both, or even weirder, two people that would be working on one db-in-your-app.

Re:Hctree is an experimental high-concurrency database back ... by tptacek on Wednesday January 18, 2023 @11:58PM (#34436859)
Sometimes this is true, and sometimes it's what CORBA advocates say you to get you to adopt object brokers. Sometimes your app benefits from an explicit networked database tier, and sometimes it doesn't. I'm fine if you think most of the time it does. I'm not fine if you think it rarely does: that's not true. There are big advantages to not having a separate database tier, and the industry is sleeping on them.

(To be clear: the company I work for sells a Postgres service, and we benefit from n-tier databases! I have strong opinions here because I think this is an interesting controversy.)

Re:Hctree is an experimental high-concurrency database back ... by chillfox on Thursday January 19, 2023 @12:34AM (#34437055)
"you’d have to build some bespoke solution"

Or you could use one of the many off the shelf solutions that has sprung up over the last few years.

Re:Hctree is an experimental high-concurrency database back ... by snovv_crash on Thursday January 19, 2023 @04:53AM (#34438505)
What is the point of having a HA database if your frontend app isn't running to be able to query it?

SQLite gives the guarantee that if your frontend app is running, then the DB is available as well. Try doing that with a non-embedded DB.

Re:Hctree is an experimental high-concurrency database back ... by anonymousDan on Thursday January 19, 2023 @07:40AM (#34439680)
The point of disaggregating your replicated database is you can scale your app and db tiers independently. Typically you only want to have a handful of database replicas (e.g. to failover after your primary fails), especially if you want strongly consistent replication. But your stateless app tier may require many more servers.
Re:Hctree is an experimental high-concurrency database back ... by fierro on Thursday January 19, 2023 @01:28PM (#34443694)
yes this is true, I was imprecise
Re:Hctree is an experimental high-concurrency database back ... by randomdata on Wednesday January 18, 2023 @07:58PM (#34435376)
The only real difference between SQLite and something like Postgres or MySQL is that Postgres and MySQL bundle a networking layer on top of their embedded DB engines.

If you are worried about high availability, chances are you too are building a networking layer on top of a database, so what do you need two networking layers for?

Re:Hctree is an experimental high-concurrency database back ... by Aperocky on Wednesday January 18, 2023 @08:25PM (#34435577)
I broadly agree, however running a cache/networking layer is difficult, and is handled well by other open sourced implementations.

If someone already wrote that networking layer, why would I want to do it again? And run into all of the bugs that they already discovered and solved?

Re:Hctree is an experimental high-concurrency database back ... by randomdata on Wednesday January 18, 2023 @08:31PM (#34435629)
Agreed, although we are having this discussion now exactly because those same problems are starting to get solved for SQLite in an open and polished way, so it is no longer a case of needing that second networking layer to integrate with such solutions.
Re:Hctree is an experimental high-concurrency database back ... by beoberha on Wednesday January 18, 2023 @08:05PM (#34435430)
Do people build their own networking layers above SQLite (besides for fun)? If you’re doing that, then you need to build some kind of replication story. At that point it makes sense to just use PG or MySQL
Re:Hctree is an experimental high-concurrency database back ... by randomdata on Wednesday January 18, 2023 @08:10PM (#34435463)
Unquestionably. Web apps and the like which are little more than networking frontends to a database are probably the most common type of software written these days.
Re:Hctree is an experimental high-concurrency database back ... by beoberha on Wednesday January 18, 2023 @08:25PM (#34435581)
Ah, we’re talking about different things. I took “network layer” to mean something like the ability to connect directly to the database over the network, not through some shim application.
Re:Hctree is an experimental high-concurrency database back ... by randomdata on Wednesday January 18, 2023 @11:24PM (#34436680)
Meaning something like rqlite[1]? The age of fat desktop clients all connecting back to the central SQL server is long behind us, so yeah there is probably little reason beyond fun for something like that these days, but where there is fun!

[1] https://github.com/rqlite/rqlite

Re:Hctree is an experimental high-concurrency database back ... by password4321 on Wednesday January 18, 2023 @10:23PM (#34436343)
Ha! PostgreSQL still needs some kind of replication story! ;)

(PS. Mostly just pointing out that replication is still a bit awkward.)

Re:Hctree is an experimental high-concurrency database back ... by ngrilly on Thursday January 19, 2023 @04:07AM (#34438234)
Most apps nowadays are HTTP APIs on top of a database, which means we have one networking layer – the HTTP API – on top of another networking layer – the database protocol. The idea behind using SQLite is to just skip the latter, which is simplifying the stack significantly and reducing the database latency, which is making things like 1+n not a problem anymore.

With a tool like LiteFS, it is now possible to get replication done by a sidecar process: https://fly.io/docs/litefs/

Re:Hctree is an experimental high-concurrency database back ... by snovv_crash on Thursday January 19, 2023 @04:46AM (#34438467)
It's because people are using super slow languages which incur lots of overhead in running the queries and formatting the results into human readable form. As such they need many more machines to run these webapp machines than they do to run the database itself.
Re:Hctree is an experimental high-concurrency database back ... by pjmlp on Thursday January 19, 2023 @07:52AM (#34439756)
And stored procedured, debugging, JIT compilation, extension in multiple languages, ....
Re:Hctree is an experimental high-concurrency database back ... by hamandcheese on Wednesday January 18, 2023 @08:40PM (#34435692)
Not only that, but typical devs write slow application code, which needs to be distributed horizontally across many workers.
Re:Hctree is an experimental high-concurrency database back ... by Cthulhu_ on Thursday January 19, 2023 @03:28AM (#34438002)
There's rqlite (https://github.com/rqlite/rqlite), which looks cool on the surface but... it's a layer on top of sqlite, at which point you should probably think long and hard whether it's still the right tool or you should switch to e.g. postgres.
Re:Hctree is an experimental high-concurrency database back ... by ngrilly on Thursday January 19, 2023 @04:02AM (#34438200)
To get HA, it is now possible to replicate the SQLite database using LiteFS, which is similar to how you would get HA with MySQL or PostgreSQL: https://fly.io/docs/litefs/
Re:Hctree is an experimental high-concurrency database back ... by metadat on Wednesday January 18, 2023 @06:30PM (#34434665)
Perhaps because as of today:

> The prototype is still missing features and contains many bugs. But it works well enough to test.

Re:Hctree is an experimental high-concurrency database back ... by stefanos82 on Wednesday January 18, 2023 @06:27PM (#34434639)
Exactly what I was thinking!
Re:Hctree is an experimental high-concurrency database back ... by rcarmo on Wednesday January 18, 2023 @06:47PM (#34434802)
Lack of JSON CONTAINS would be a good reason.
Re:Hctree is an experimental high-concurrency database back ... by TkTech on Wednesday January 18, 2023 @06:55PM (#34434860)
Heh, this is the reason Takahe is currently broken on SQLite. Hashtags currently need a JSON contains.
Re:Hctree is an experimental high-concurrency database back ... by simonw on Wednesday January 18, 2023 @09:05PM (#34435874)
It's possible to simulate JSON contains in SQLite using a devious subselect.

Here's an example:

https://datasette.io/content/plugin_repos?_facet_array=tags&...

That page shows every row where the tags column (a SQLite JSON list of strings) contains the string "Data Import"

Here's the underlying SQL:

https://datasette.io/content?sql=select%0D%0A++rowid%2C%0D%0...

    select
      rowid,
      repo,
      tags
    from
      plugin_repos
    where
      :tag in (
        select
          value
        from
          json_each(plugin_repos.tags)
      )
    order by
      rowid
    limit
      101
I haven't tried it yet, but I have a strong hunch that this could be dramatically accelerated using a join against a FTS table on that "tags" column in order to first filter the rows down to a likely subset.
Re:Hctree is an experimental high-concurrency database back ... by rcarmo on Thursday January 19, 2023 @02:08AM (#34437535)
Django would need to be patched to do that, since the default SQLite provider would make it hard to do that cleanly.

Here’s the relevant Takahe issue: https://github.com/jointakahe/takahe/issues/325

Re:Hctree is an experimental high-concurrency database back ... by rcarmo on Thursday January 19, 2023 @02:06AM (#34437519)
Yep. That’s exactly what I stumbled upon myself.
Re:Hctree is an experimental high-concurrency database back ... by blacklion on Thursday January 19, 2023 @05:21AM (#34438727)
Do these developers, who require JSON CONTAINS, know about basic normal forms and RDBMS in general?!

I understand, that sometimes for performance it is needed to de-normalize huge datalakes, but typical website controlled by CMS is not huge by any means.

Re:Hctree is an experimental high-concurrency database back ... by FpUser on Wednesday January 18, 2023 @07:35PM (#34435205)
>"It makes me wonder why I would use anything else?"

this: "There is no support for recovering from a power failure or operating system crash. Such an event may corrupt the database."

Re:Hctree is an experimental high-concurrency database back ... by gnarbarian on Wednesday January 18, 2023 @07:47PM (#34435297)
You don't always need this at the db level. depending on your use case backups or high availability in multiple datacenters can do fine.
Re:Hctree is an experimental high-concurrency database back ... by metadat on Wednesday January 18, 2023 @08:30PM (#34435621)
But then what is the recovery scenario.. the story could get hairy and complex quickly.
Re:Hctree is an experimental high-concurrency database back ... by gnarbarian on Wednesday January 18, 2023 @08:59PM (#34435838)
you either restore from your snapshot/backup of the database, or replicate from the HA node that didn't fail.

it depends on the nature of your app as to whether either of those scenarios are acceptable. the former comes with downtime.

Re:Hctree is an experimental high-concurrency database back ... by hot_gril on Wednesday January 18, 2023 @08:54PM (#34435802)
Postgres focuses more on this use case. It's probably still going to do a better job with concurrency, or at least have more features. It'll also cost more to pay for as a service, so you decide if it's worth. Whereas HC-tree is an obvious win if you're already using SQLite. It's fine for two things to approach similar use cases from different sides.

Personally I want the opposite direction, a sort of Postgres-lite that uses a single flat file and lives inside a lib, for things where the power of the full thing isn't needed yet but I want to design my backend code against a Postgres interface. I've seen Wasm Postgres examples, and maybe there are others, but nothing mainstream. And yes there was this SQL standard that everything was supposed to conform to, but that went out the window long ago.

Re:Hctree is an experimental high-concurrency database back ... by switchbak on Wednesday January 18, 2023 @09:26PM (#34436017)
I use an embedded postgres testing library for the JVM that does something along those lines.

Well no actually it just unpacks the tar file in a temp dir and runs the full postgres, but it mostly feels like what you describe (minus the single file part) and starts surprisingly fast. That would totally work for a little proof of concept (https://github.com/zonkyio/embedded-postgres)

Re:Hctree is an experimental high-concurrency database back ... by hot_gril on Wednesday January 18, 2023 @09:45PM (#34436141)
That's pretty neat, but not the same level of portability as SQLite.
Re:Hctree is an experimental high-concurrency database back ... by prpl on Thursday January 19, 2023 @01:00AM (#34437192)
I used hypersql/hsqldb for unit tests. The Oracle mode was usually close enough. It’s pretty close for postgres. Sometimes there’s small issues (I think using “INSERT INTO … RETURNING” required column name in caps for some reason) but overall it’s almost always what you want for unit testing with java.
Re:Hctree is an experimental high-concurrency database back ... by kitd on Thursday January 19, 2023 @03:28AM (#34438001)
H2db has a Postgres-compatibility mode too that would work for local testing.

https://www.h2database.com/html/features.html#compatibility

Re:Hctree is an experimental high-concurrency database back ... by nl on Wednesday January 18, 2023 @09:09PM (#34435901)
> direction, a sort of Postgres-lite that uses a single flat file and lives inside a lib,

Can you expand on this? How did you package postgres as a lib?

Re:Hctree is an experimental high-concurrency database back ... by hot_gril on Wednesday January 18, 2023 @09:17PM (#34435950)
I haven't done this, but I'd want it. I'd like to write my code to use a Postgres database, except swap in something similar to a SQLite database instead when I'm either testing or not yet at scale. SQLite does everything in just a library linked with your code, unlike Postgres which is a separate running server. I can't simply use SQLite for this because its API is different from Postgres's.
Re:Hctree is an experimental high-concurrency database back ... by nick__m on Wednesday January 18, 2023 @11:08PM (#34436595)
You should read on the ancient tech called ODBC.
Re:Hctree is an experimental high-concurrency database back ... by hot_gril on Thursday January 19, 2023 @12:15AM (#34436957)
I almost said ODBC too but wasn't sure if I fully understood it.
Re:Hctree is an experimental high-concurrency database back ... by nl on Thursday January 19, 2023 @01:29AM (#34437337)
Doesn't almost every language have some kind of abstraction layer that allows this?

JDBC/ODBC/DB-API/Sequelize ORM (ignoring the ORM part).

This used to be one of the major use cases for SQLite - running automated tests and being able to throw away the database file (or manage it at different points in the tests).

Re:Hctree is an experimental high-concurrency database back ... by deredede on Thursday January 19, 2023 @03:30AM (#34438016)
ODBC doesn't help you if you use any sort of pgsql-specific extension, however.
Re:Hctree is an experimental high-concurrency database back ... by hot_gril on Thursday January 19, 2023 @12:35PM (#34443058)
Yeah, but the abstraction layers get in the way if/when I need to optimize queries or use special features, plus it's easier to just write SQL. I'd rather target a specific DBMS and rewrite my queries if I ever change it.

> ignoring the ORM part

As it should be :)

Re:Hctree is an experimental high-concurrency database back ... by nl on Thursday January 19, 2023 @05:08PM (#34446360)
No, all (?) these things let you pass raw SQL straight to the database.

In the case of JDBC and ODBC (and I think DB-API) thats all they do.

Re:Hctree is an experimental high-concurrency database back ... by hot_gril on Thursday January 19, 2023 @05:36PM (#34446651)
But raw SQL made for Postgres doesn't necessarily work for SQLite and vice versa. That's what I mean by the SQL standard being thrown out the window. You might be able to write SQL that works in both if you're careful and avoid a lot of features.
Re:Hctree is an experimental high-concurrency database back ... by amluto on Wednesday January 18, 2023 @11:18PM (#34436649)
I have an absolutely horrifying Python script that makes a little sort-of-container that spins up a brand new MySQL instance, initializes it with a provided set of statements (from mysqldump), and runs it. And cleans it up when it’s done.

And I have a wrapper that does it in a shell.

This makes it possible to run MySQL-dependent tests, in parallel, on a dev machine, without too much misery.

(MySQL is awful. Don’t use it for new designs. MariaDB isn’t obviously better. AWS RDS MySQL is, in my considered opinion after wasting days on it, even worse. RDS CANNOT INGEST THE OUTPUT OF mysqldump WITHOUT ILL-CONSIDERED AND POORLY DOCUMENTED KLUDGES!!! WTF!! Don’t get me started on how defective every MySQL replication mode is.)

Re:Hctree is an experimental high-concurrency database back ... by LAC-Tech on Wednesday January 18, 2023 @11:34PM (#34436726)
(Don’t get me started on how defective every MySQL replication mode is.)

I was actually reading up on this this the other day (doing a bit of a breadth first search of multi-master replication in industry).

I thought the way it worked was... interesting. Sounds like it's just as interesting in production.

Re:Hctree is an experimental high-concurrency database back ... by hot_gril on Thursday January 19, 2023 @12:17AM (#34436967)
Yeah, I use Postgres. It's good. MySQL only has the advantage of being offered by more cloud providers and thus being cheaper sometimes.
Re:Hctree is an experimental high-concurrency database back ... by tehbeard on Thursday January 19, 2023 @08:31AM (#34440047)
Doesn't MySQL also not need you to configure a bouncer/proxy if you want more than a dozen connections at a time?
Re:Hctree is an experimental high-concurrency database back ... by hot_gril on Thursday January 19, 2023 @12:29PM (#34442996)
Postgres in my experience can handle like 100 connections with the default config I get installing it on my Ubuntu server, but at some point you want pg-bouncer, and I vaguely remember MySQL having higher limits. Idk, it's been a while cause I've almost always limited the number of connections in my own code instead.
Re:Hctree is an experimental high-concurrency database back ... by samuel on Thursday January 19, 2023 @06:41AM (#34439266)
Duckdb should be compatible with postgres to a high degree.

https://duckdb.org/why_duckdb.html

> SQL Parser: We use the PostgreSQL parser that was repackaged as a stand-alone library. The translation to our own parse tree is inspired by Peloton.

Re:Hctree is an experimental high-concurrency database back ... by pbowyer on Thursday January 19, 2023 @07:32AM (#34439622)
Watch out with DuckDB that if you have an open reader you can't open a writer. A writer must be the only connection.

https://duckdb.org/faq#how-does-duckdb-handle-concurrency

Re:Hctree is an experimental high-concurrency database back ... by sargun on Wednesday January 18, 2023 @09:21PM (#34435970)
For workloads that are on the same node -- Putting the database in the same memory space as my code as well as the same I/O and scheduling contexts isn't always what I want. I want to be able to prioritize database I/O far above app I/O. In addition, I want to make sure my database isn't prioritized "lower" than my application, as this can trigger priority inversion issues.

Also, the scaling characteristics of database nodes vs service nodes are very different. I might not want to put reliable storage into every node I have, but I'm probably willing to shell out a couple bucks for my database server's storage.

An example from my last project that used a lot of postgres. The database node was about ~20x the price as the workers.

From an operational perspective, having the database be maintained separately from the app also has its benefits.

Re:Hctree is an experimental high-concurrency database back ... by tomcam on Wednesday January 18, 2023 @10:27PM (#34436369)
You just gave me a tiny database education in about 8 sentences.
Re:Hctree is an experimental high-concurrency database back ... by api on Thursday January 19, 2023 @07:15AM (#34439508)
One scaling paradigm that's occurred to me for SQLite would be to run lots of small replicated instances in a system like Nomad or Kubernetes and even allow many running on the same physical node. So you're replicating multiple times on the same box which wastes some space but storage is cheap.

Wouldn't be good for huge data sets but these days huge means like a terabyte or more. You don't really have to start thinking about sharding or smart fractional replication until you hit many terabytes.

Even many successful SaaS companies don't have databases that big. Several hundred gigs these days is not too big for a brute force replicate everywhere approach and it comes with some benefits like less locking and stronger fault tolerances. If you have 50 replicas the odds of them all being screwed at once gets very low.

Re:Hctree is an experimental high-concurrency database back ... by treis on Thursday January 19, 2023 @10:33AM (#34441369)
To add to this, you want you application to be stateless and immutable. This makes your life so much easier in so many different ways:

(1) You can know exactly what code was running when debugging past issues

(2) Scaling can be done dynamically and relatively easy. Just turn on/off application nodes.

(3) Rollbacks are (relatively) trivial. Just go back to the know good immutable version

(4) Memory leaks can be "solved" by restarting nodes every so often

(5) If, for whatever reason, your application node dies you shrug your shoulders and start a new one

Once you add DBs with state to your application all of become much harder. You want that state in something that's rock solid and rarely changes to avoid all the above problems.

Re:Hctree is an experimental high-concurrency database back ... by ComodoHacker on Thursday January 19, 2023 @03:30AM (#34438020)
Because it won't have as many years of rigorous testing and polishing as current back-end or PostgreSQL or whatever.
Re:Hctree is an experimental high-concurrency database back ... by sedatk on Wednesday January 18, 2023 @10:54PM (#34436517)
Hugged to death currently:

The server load is currently too high. Please try again later. Current load average: 5.190000. Load average limit: 4.000000

Re:Hctree is an experimental high-concurrency database back ... by bufferoverflow on Wednesday January 18, 2023 @11:27PM (#34436702)
Should've used SQLite on the backend.
Re:Hctree is an experimental high-concurrency database back ... by SQLite on Thursday January 19, 2023 @06:56AM (#34439378)
The server is on Linode. Looking at the stats, they appeared to have had an outage of some kind last night at about the time you got this message. Everything seems to be running fine now. Please try again.

https://sqlite.org/tmp/cpu-20230119.jpg