News for hackers. Stuff that matters.
Re:How the SQLite virtual machine works by endisneigh on Wednesday September 07, 2022 @11:59AM (#32752366)
I see so many SQLite posts these days, but which companies with a lot (>1M) concurrent users are using SQLite in a non embedded fashion?

It just seems so academic. I’d like to use a web service or app backed primarily by SQLite and see how it goes.

Re:How the SQLite virtual machine works by tptacek on Wednesday September 07, 2022 @12:26PM (#32752723)
It works fine for read-heavy apps (ie: most apps) and, with things like Litestream, is especially attractive in distributed and edge settings, where you can stream out read replicas to a bunch of regions and direct writes to a single central region.

That might sound confining, but it's what people already do with Postgres: read replicas, single write master.

And the benefits aren't academic: having your database in-process not only simplifies your database code (because N+1 queries are no longer perf emergencies), but can also drastically speed up response times, because you're not dealing with compounding intra-DC latency responding to an HTTP request that incurs multiple database queries.

And, finally: SQLite wants a single writer per database. But there's no rule that says your entire app has to land in a single .db file. That's what you'd naturally do in a Postgres app, but it's not necessarily the natural answer for a SQLite-backed app, where it's pretty trivial to pull from multiple databases with a single SQL statement.

Don't get me wrong, I think it's still pretty niche-y as an alternative to standard n-tier app databases. You'd use it deliberately; it's unlikely to be a full-stack default. But people have definitely been sleeping on SQLite, and I think what you're seeing is some of those people beginning to wake up.

Re:How the SQLite virtual machine works by endisneigh on Wednesday September 07, 2022 @05:33PM (#32757257)
> It works fine for read-heavy apps (ie: most apps) and, with things like Litestream, is especially attractive in distributed and edge settings, where you can stream out read replicas to a bunch of regions and direct writes to a single central region.

This is what I'm saying - I keep hearing this, which popular website is using SQLite as their main database?

I don't have any doubt you can serve 1000 users, or even 10,000 current users using SQLite. There's a power law distribution with the popularity of sites. The most popular sites have multiple orders of magnitude.

Can SQLite serve 500,000 current users with 75% reads and writes with the consistency you'd expect?

> And, finally: SQLite wants a single writer per database. But there's no rule that says your entire app has to land in a single .db file. That's what you'd naturally do in a Postgres app, but it's not necessarily the natural answer for a SQLite-backed app, where it's pretty trivial to pull from multiple databases with a single SQL statement.

Sounds reasonable in theory. How do you maintain consistency between all of these databases? Schema migrations? Backups and restores and maintaining referential consistency?

By the time you implement all of this, and you certainly can, why not just use Postgres?

Re:How the SQLite virtual machine works by ok_dad on Wednesday September 07, 2022 @05:49PM (#32757453)
> which popular website is using SQLite as their main database

First, I don't think this is a good metric for software quality or use-case analysis. Just because people don't use X doesn't mean X wouldn't be a superior tool for their use-case.

> How do you maintain consistency between all of these databases?

You don't, in the GP's example, you would shard the database schema. Sharding is easy to figure about, because many database services do this already to spread data and analysis across several servers. You might use Litestream to then send those thousands/millions of database files to some S3 bucket somewhere. Then, you could analyze the shards together in that bucket using one of the many available solutions for such things, like Apache Hive or whatever the BigCo clouds provide.

> By the time you implement all of this, and you certainly can, why not just use Postgres?

Because you analyzed the pros and cons to SQLite vs. Postgres for your specific use-case and determined SQLite will be better in the long run. Perhaps your particular use-case will turn up "Postgres" and you won't use SQLite, or maybe you'll use both of them, but for different data stores.

No one technology is "the chosen one", sometimes you need several different options.

Re:How the SQLite virtual machine works by endisneigh on Wednesday September 07, 2022 @05:58PM (#32757570)
> You don't, in the GP's example, you would shard the database schema. Sharding is easy to figure about, because many database services do this already to spread data and analysis across several servers. You might use Litestream to then send those thousands/millions of database files to some S3 bucket somewhere. Then, you could analyze the shards together in that bucket using one of the many available solutions for such things, like Apache Hive or whatever the BigCo clouds provide.

I'm not sure if you're being serious. Sharding isn't easy at all. Especially if you're doing it across different files that need to be synced in tandem with schema migrations that also need to be applied in tandem.

> Because you analyzed the pros and cons to SQLite vs. Postgres for your specific use-case and determined SQLite will be better in the long run. Perhaps your particular use-case will turn up "Postgres" and you won't use SQLite, or maybe you'll use both of them, but for different data stores.

The use case is already defined in my original post. A popular app with a lot of concurrent users. People claim SQLite is superior to Postgres for such a scenario, I'm curious to read about and use a service using SQLite for an app with a lot of users (>1M 75% reads)

From looking at the issues for Litestream on GitHub I'm not really convinced it's production ready. For some small app I'm sure it's fine, I'm talking about an app with a lot of users generating a lot of money and you need high availability.

All of this makes it sound like I dislike SQLite, I really don't - I've used it successfully for local apps on the web, Android and iOS. However I feel this popularity for SQLite on the web may be misplaced.

Re:How the SQLite virtual machine works by ok_dad on Wednesday September 07, 2022 @06:08PM (#32757677)
> People claim SQLite is superior to Postgres for such a scenario

Only idiots would claim some technology is superior without doing some use-case analysis and experimentation.

> I'm not sure if you're being serious...

I am, but still it depends on use case. If you have an application that can support it for the use-case, then you can do simple things like making one DB per user and then doing aggregate functions on Apache Hive or something. If you have a schema that will absolutely NOT support sharding, then I guess it might not work in that case. I would argue I could design a SQLite solution for 95% of the applications that need a SQL database, but there are some which, for whatever reason, may require other solutions. I am also NOT saying that all of those designs would be the best for that use-case, but it would work.

Unequivocally: Your use cases define the tools you need to use.

> The use case is already defined in my original post. A popular app with a lot of concurrent users. People claim SQLite is superior to Postgres for such a scenario, I'm curious to read about and use a service using SQLite for an app with a lot of users (>1M 75% reads).

Still, you didn't define it. What's the data schema? What is the application? I don't know what to say, if your app is a TODO list app that's wildly popular, then I guarantee I can do what you want with SQLite easily. If it's Spotify-level stuff with special aggregation and data analysis, maybe not?

Re:How the SQLite virtual machine works by endisneigh on Wednesday September 07, 2022 @06:12PM (#32757727)
> Still, you didn't define it. What's the data schema? What is the application? I don't know what to say, if your app is a TODO list app that's wildly popular, then I guarantee I can do what you want with SQLite easily. If it's Spotify-level stuff with special aggregation and data analysis, maybe not?

sigh. any app based on SQLite with more than 1 million concurrent users, 75% reads.

Re:How the SQLite virtual machine works by ok_dad on Wednesday September 07, 2022 @06:23PM (#32757892)
Here's one specific one, I would imagine they have a pretty big user base: https://tailscale.com/blog/database-for-2022/

Here are a few other sources I googled:

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

https://stackshare.io/sqlite

This is the best I can do, because I have no idea what else you want. If I had the time, I could throw up a simulated million users doing a TODO app with SQLite as the backing DB engine, but I don't have time, I have a 2 year old. Do your own research from here, or don't and just use Postgres until you retire, I don't really care that much.

Re:How the SQLite virtual machine works by tptacek on Wednesday September 07, 2022 @06:57PM (#32758287)
A million concurrent, with a database-backed website? Is that a useful threshold? How many monthly actives is a million concurrent? And, at that scale, is your database your gating factor, or is app architecture?
Re:How the SQLite virtual machine works by kasey_junk on Wednesday September 07, 2022 @07:07PM (#32758405)
Can you name a single application that has 250k concurrent writes (per second I assume as you didn’t stipulate) using a consistent sql backend (that is no external caching/sharing layer)?

I don’t think your example is a good fit for SQLite as it’s not a good fit for any sql store that I know of.

Re:How the SQLite virtual machine works by rrdharan on Wednesday September 07, 2022 @08:10PM (#32759171)
Uber, on Google Cloud Spanner, seems to be in this ballpark though they aren’t quite explicit about it:

https://www.uber.com/blog/building-ubers-fulfillment-platfor...

Re:How the SQLite virtual machine works by kasey_junk on Wednesday September 07, 2022 @09:56PM (#32760070)
Spanner is explicitly sharded. Sort of famously so.
Re:How the SQLite virtual machine works by rrdharan on Thursday September 08, 2022 @12:50AM (#32761311)
All scale out databases use some form of sharding, tautologically.

The parent asked about use cases where there wasn’t an _external_ (which I interpret to mean “handled explicitly by the app, not the database”) sharding / caching layer.

Spanner internally handles splits based on load / size.

That having been said, more careful reading of the Uber post shows that they still do employ additional app-level explicit sharding to resolve hot-spots, so it’s probably a fair point that this doesn’t qualify as an example the parent was looking for.

Re:How the SQLite virtual machine works by endisneigh on Wednesday September 07, 2022 @08:56PM (#32759611)
A few vendors doing time series data. Even if you lowered it a couple orders of magnitude. I haven’t seen any app doing even 5K concurrent writes backed by SQLite.
Re:How the SQLite virtual machine works by kasey_junk on Wednesday September 07, 2022 @09:55PM (#32760061)
What time series vendor is offering high write throughput consistent sql?

Legitimately interested as this is something I have more than a little professional interest.

That said, “show me an app doing 5k concurrent writes with SQLite” seems like a much more reasonable standard.

Re:How the SQLite virtual machine works by lenkite on Thursday September 08, 2022 @12:21AM (#32761158)
Don't even bother with a million. Even 1k concurrent users with 75% read/25% write is not something plain SQLite can handle without significant latency compared to Postgres.
Re:How the SQLite virtual machine works by Scarbutt on Wednesday September 07, 2022 @06:32PM (#32758013)
sigh. any app based on SQLite with more than 1 million concurrent users, 75% reads.

Definitely not the use case for SQLite unless you can easily do sharding but as you said, why bother?

Re:How the SQLite virtual machine works by bob1029 on Wednesday September 07, 2022 @05:14PM (#32756981)
> And, finally: SQLite wants a single writer per database. But there's no rule that says your entire app has to land in a single .db file.

I like finding hints of our architecture scattered across these SQLite threads :D

It's very sketchy trying to slam all users into a single physical database. If you can slice up the users along unit of work, session, customer, account, etc., you can go horizontal very quickly.

Re:How the SQLite virtual machine works by sgbeal on Wednesday September 07, 2022 @02:00PM (#32753914)
> I’d like to use a web service or app backed primarily by SQLite and see how it goes.

Look no further than sqlite's own source control system: <https://fossil-scm.org>

i've used that site almost daily since the end of 2007 and have encountered maybe (maybe) three "db is locked" errors.

Re:How the SQLite virtual machine works by TillE on Wednesday September 07, 2022 @12:16PM (#32752589)
Not everyone is doing only web development for millions of concurrent users.

SQLite has been deployed on billions of devices, so "academic" is an odd term here.

Re:How the SQLite virtual machine works by endisneigh on Wednesday September 07, 2022 @01:10PM (#32753320)
Non embedded. fly.imo for example exposes SQLite in a non embedded fashion.
Re:How the SQLite virtual machine works by ok_dad on Wednesday September 07, 2022 @06:14PM (#32757755)
I don't understand your claim, with fly.io it seems like you attach some storage to your application and store the SQLite file there, semi-locally, much the same as any other use of SQLite. The SQLite database code is still inside your chosen application, it's just loading the file from some "persistent volume" abstraction.
Re:How the SQLite virtual machine works by jcwayne on Wednesday September 07, 2022 @12:05PM (#32752445)
I'm curious how many companies building for >1M concurrent users have even a tenth of that in reality.
Re:How the SQLite virtual machine works by pjc50 on Wednesday September 07, 2022 @12:13PM (#32752545)
That's pretty much the anti-use-case for SQLite?
Re:How the SQLite virtual machine works by bob1029 on Wednesday September 07, 2022 @05:11PM (#32756942)
> I’d like to use a web service or app backed primarily by SQLite and see how it goes.

We've been doing this in production for over half a decade now. It goes so well it becomes boring very quickly.

Re:How the SQLite virtual machine works by endisneigh on Wednesday September 07, 2022 @05:46PM (#32757408)
Stats on your service/app and workload?
Re:How the SQLite virtual machine works by bob1029 on Wednesday September 07, 2022 @07:41PM (#32758841)
We shard out to 1 SQLite database per user's working session, so there really isn't a meaningful figure if you are looking for apples-to-apples in a traditional sense.

Our most heavily loaded SQLite instance probably sees 100 writes per second. In aggregate, we can handle tens of thousands of requests per second.

Re:How the SQLite virtual machine works by Abishek_Muthian on Thursday September 08, 2022 @03:38AM (#32762478)
> 1 SQLite database per user's working session

I presume you've designed your application to accommodate only the data types offered by SQLite and without any concurrent writing?

Re:How the SQLite virtual machine works by Thaxll on Wednesday September 07, 2022 @02:32PM (#32754395)
You won't find anyone because it would mean that you have a single service talking to SQLite which most webservices won't do for HA reasons, you have a few of them behind a loadbalancer.

Using SQLite for any serious webservices is bad thing because you can only have a single app. Then you have other tools on top of SQLite for those shortcoming.

Re:How the SQLite virtual machine works by tptacek on Wednesday September 07, 2022 @02:40PM (#32754554)
Having a single database service as a write master is already commonplace in HA Postgres.
Re:How the SQLite virtual machine works by Thaxll on Wednesday September 07, 2022 @03:12PM (#32755117)
Right but they do that over the network not using the filesystem.
Re:How the SQLite virtual machine works by tptacek on Wednesday September 07, 2022 @04:04PM (#32755991)
I'm not sure what's complicated about this. Instead of exposing a database instance as the write master, you expose a service as the write master. You can even do it transparently, if your load balancing fabric cooperates: just arrange to have read replicas redirect write requests to the write master.
Re:How the SQLite virtual machine works by avl999 on Wednesday September 07, 2022 @05:15PM (#32757006)
With that setup you have essentially lost any benefits that SQLite provides, specifically any performance benefits by making a DB read/write a network call instead of a local call in the same process that manipulates some file on the same machine. You are closer to a postgres/mysql patterne except now your writes don't scale as well. What are we actually gaining with this setup other than perhaps easier administration of the "db service" compared to a mysql/postgres deployment?
Re:How the SQLite virtual machine works by tptacek on Wednesday September 07, 2022 @05:29PM (#32757211)
Obviously, you have not lost those benefits: reads are satisfied from an in-process database, and, for most applications, most requests are reads.
Re:How the SQLite virtual machine works by adamrezich on Wednesday September 07, 2022 @12:28PM (#32752752)
you've almost certainly used software that uses sqlite today, possibly even right now https://www.sqlite.org/mostdeployed.html
Re:How the SQLite virtual machine works by tptacek on Wednesday September 07, 2022 @12:30PM (#32752783)
They stipulated non-embedded use cases for it --- really, their subtext is "show me places that use SQLite where ordinarily people would use an n-tier architecture", which is to say, Rails, Node, or Django. I think it's obvious to everyone that SQLite gets a lot of important use behind the scenes.
Re:How the SQLite virtual machine works by adamrezich on Wednesday September 07, 2022 @12:35PM (#32752864)
"embedded" can mean a few different things so that's a bit confusing for me, but if the intent was "show me places sqlite is used as a database backend for user-facing web software", the Nim forum (https://github.com/nim-lang/nimforum) uses sqlite as its database backend.
Re:How the SQLite virtual machine works by sgbeal on Wednesday September 07, 2022 @03:06PM (#32755016)
> but if the intent was "show me places sqlite is used as a database backend for user-facing web software", the Nim forum

Perhaps more appropriately, sqlite's own forum is sqlite-backed: <https://sqlite.org/forum> (running the Fossil SCM's forum interface, which itself exclusively uses sqlite for storage: <https://fossil-scm.org> (that whole site is an instance of fossil, serving all content from an sqlite db))

Re:How the SQLite virtual machine works by tptacek on Wednesday September 07, 2022 @12:37PM (#32752890)
That's a good example.
Re:How the SQLite virtual machine works by zerr on Wednesday September 07, 2022 @03:33PM (#32755517)
That's because of its prevalence usage as a better flat file or config file.