| ▲ | hackingonempty 12 hours ago |
| > The enterprise mindset dictates that you need an out-of-process database server. But the truth is, a local SQLite file communicating over the C-interface or memory is orders of magnitude faster than making a TCP network hop to a remote Postgres server. I don't want to diss SQLite because it is awesome and more than adequate for many/most web apps but you can connect to Postgres (or any DB really) on localhost over a Unix domain socket and avoid nearly all of the overhead. It's not much harder to use than SQLite, you get all of the Postgres features, it's easier to run reports or whatever on the live db from a different box, and much easier if it comes time to setup a read replica, HA, or run the DB on a different box from the app. I don't think running Postgres on the same box as your app is the same class of optimistic over provisioning as setting up a kubernetes cluster. |
|
| ▲ | andersmurphy 10 hours ago | parent | next [-] |
| Sqlite smokes postgres on the same machine even with domain sockets [1]. This is before you get into using multiple sqlite database. What features postgres offers over sqlite in the context of running on a single machine with a monolithic app? Application functions [2] means you can extend it however you need with the same language you use to build your application. It also has a much better backup and replication story thanks to litestream [3]. - [1] https://andersmurphy.com/2025/12/02/100000-tps-over-a-billio... - [2] https://sqlite.org/appfunc.html - [3] https://litestream.io/ The main problem with sqlite is the defaults are not great and you should really use it with separate read and write connections where the application manages the write queue rather than letting sqlite handle it. |
| |
| ▲ | andriy_koval 3 hours ago | parent | next [-] | | > Sqlite smokes postgres on the same machine even with domain sockets [1] for inserts only into singe table with no indexes. Also, I didn't get why sqlite was allowed to do batching and pgsql was not. | | |
| ▲ | andersmurphy 3 hours ago | parent [-] | | > for inserts only into singe table with Actually, there are no inserts in this example each transaction in 2 updates with a logical transaction that can be rolled back (savepoint). So in raw terms you are talking 200k updates per second and 600k reads per second (as there's a 75%/25% read/write mix in that example). Also worth keeping in mind updates are slower than inserts. > no indexes. The tables have an index on the primary key with a billion rows. More indexes would add write amplification which would affect both databases negatively (likely PG more). > Also, I didn't get why sqlite was allowed to do batching and pgsql was not. Interactive transactions [1] are very hard to batch over a network. To get the same effect you'd have to limit PG to a single connection (deafeating the point of MVCC). - [1] An interactive transaction is a transaction where you intermingle database queries and application logic (running on the application). | | |
| ▲ | andriy_koval 2 hours ago | parent [-] | | Thank you for clarification, I was wrong in my prev comment. > - [1] An interactive transaction is a transaction where you intermingle database queries and application logic (running on the application). could you give specific example why do you think SQlite can do batching and PG not? | | |
| ▲ | hedora 5 minutes ago | parent [-] | | Not the person you are responding to, but sqlite is single threaded (even in multi process, you get one write transaction at a time). So, if you have a network server that does BEGIN TRANSACTION (process 1000 requests) COMMIT (send 1000 acks to clients), with sqlite, your rollback rate from conflicts will be zero. For PG with multiple clients, it’ll tend to 100% rollbacks if the transactions can conflict at all. You could configure PG to only allow one network connection at a time, and get a similar effect, but then you’re paying for MVCC, and a bunch of other stuff that you don’t need. |
|
|
| |
| ▲ | maccard 8 hours ago | parent | prev | next [-] | | Thing is though - either of those options is still multiple orders of magnitude faster than running on a remote host. Either will work, either will scale way farther than you reasonably expect it to. | |
| ▲ | eduction 2 hours ago | parent | prev | next [-] | | > What features postgres offers over sqlite in the context of running on a single machine with a monolithic app The same thing SQL itself buys you: flexibility for unforeseen use cases and growth. Your SQLite benchmark is based in having just one write connection for SQLite but all eight writable connections for Postgres. Even in the context of a single app, not everyone wants to be tied down that way, particularly when thinking how it might evolve. If we know our app would not need to evolve we could really maximize performance and use a bespoke database instead of an rdbms. It seems a little aggressive for you to jump on a comment about how it’s reasonable to run Postgres sometimes with “SQLite smokes it in performance.” That’s true, when you can accept its serious constraints. As a wise man once said, “Postgres is great and there's nothing wrong with using it!” | |
| ▲ | locknitpicker 10 hours ago | parent | prev | next [-] | | > Sqlite smokes postgres on the same machine even with domain sockets [1]. SQLite on the same machine is akin to calling fwrite. That's fine. This is also a system constraint as it forces a one-database-per-instance design, with no data shared across nodes. This is fine if you're putting together a site for your neighborhood's mom and pop shop, but once you need to handle a request baseline beyond a few hundreds TPS and you need to serve traffic beyond your local region then you have no alternative other than to have more than one instance of your service running in parallel. You can continue to shoehorn your one-database-per-service pattern onto the design, but you're now compelled to find "clever" strategies to sync state across nodes. Those who know better to not do "clever" simply slap a Postgres node and call it a day. | | |
| ▲ | andersmurphy 10 hours ago | parent | next [-] | | > SQLite on the same machine is akin to calling fwrite. Actually 35% faster than fwrite [1]. > This is also a system constraint as it forces a one-database-per-instance design You can scale incredibly far on a single node and have much better up time than github or anthropic. At this rate maybe even AWS/cloudflare. > you need to serve traffic beyond your local region Postgres still has a single node that can write. So most of the time you end up region sharding anyway. Sharding SQLite is straight forward. > This is fine if you're putting together a site for your neighborhood's mom and pop shop, but once you need to handle a request baseline beyond a few hundreds TPS It's actually pretty good for running a real time multiplayer app with a billion datapoints on a 5$ VPS [2]. There's nothing clever going on here, all the state is on the server and the backend is fast. > but you're now compelled to find "clever" strategies to sync state across nodes. That's the neat part you don't. Because, for most things that are not uplink limited (being a CDN, Netflix, Dropbox) a single node is all you need. - [1] https://sqlite.org/fasterthanfs.html - [2] https://checkboxes.andersmurphy.com | | |
| ▲ | shimman 3 hours ago | parent | next [-] | | May be an "out" there question, but any tech book suggestions you'd recommend that can teach an average dev on how to build highly performant software with minimal systems? I feel like the advice from people with your experience is worth way way way way more than what you'd hear from big tech. Like what you said yourself, big tech tends to recommend extremely complicated systems that only seem worth maintaining if you have a trillion dollar monopoly behind it. | | |
| ▲ | andersmurphy 16 minutes ago | parent [-] | | Not specific books per say. Though I'd advise starting with some constraints. As that really helps you focus. Your reading/learning material can spin out of those constraints. So for me my recent constraints were: 1. Multiplayer/collaborative web apps built by small teams. 2. Single box. 3. I like writing lisp. So single box pushes me towards a faster language, and something that's easy to deploy. Go would be the natural choice here, but I want a lisp so Clojure is probably the best option here (helps that I already know it). JVM is fast enough and has a pretty good deployment story. Multiplayer web apps, pushed me to explore distributed state vs streaming with centralised state. This became a whole journey which ended with Datastar [1]. Thing is immediate mode streaming HTML needs your database queries to be fast and that's how I ended up on SQLite (I was already a fan, and had used it in production before), but the constraints of streaming HTML forced me to revisit it in anger. Your constraints could be completely different. They could be: 1. Fast to market. 2. Minimise risk. 3. Mobile + Web 4. Try something new. Fast to market might mean you go with something like Rails/Django. Minimise risk might mean you go with Rails because you have a load of experience with it. Mobile + web means you read up on Hotwire. Try something new might mean you push more logic into stored procedures and SQL queries so you can get the most out of Postgres and make your Rails app faster. So you read The Art of Postgresql [2] (great book). Or maybe you try hosting rails on a VPS and set up/manage your own postgres instance. A few companies back mine were: 1. JVM but with a more ruby/rails like development experience. 2. Mobile but not separate iOS/Android projects. 3. Avoid the pain of app store releases. 4. You can't innovate everywhere. That meant Clojure. React native. Minimal clients with as much driven from the backend as possible. Sticking to postgres and Heroku because it's what we knew and worked well enough. - [1] https://data-star.dev - [2] https://theartofpostgresql.com There's no right answer. Hope that's helpful. |
| |
| ▲ | wookmaster 8 hours ago | parent | prev | next [-] | | How do you manage HA? | | |
| ▲ | andersmurphy 7 hours ago | parent | next [-] | | Backups, litestream gives you streaming replication to the second. Deployment, caddy holds open incoming connections whilst your app drains the current request queue and restarts. This is all sub second and imperceptible. You can do fancier things than this with two version of the app running on the same box if that's your thing. In my case I can also hot patch the running app as it's the JVM. Server hard drive failing etc you have a few options: 1. Spin up a new server/VPS and litestream the backup (the application automatically does this on start). 2. If your data is truly colossal have a warm backup VPS with a snapshot of the data so litestream has to stream less data. Pretty easy to have 3 to 4 9s of availability this way (which is more than github, anthropic etc). | | |
| ▲ | rienbdj 6 hours ago | parent | next [-] | | My understanding is litestream can lose data if a crash occurs before the backup replication to object storage. This makes it an unfair comparison to a Postgres in RDS for example? | | |
| ▲ | andersmurphy 6 hours ago | parent | next [-] | | Last I checked RDS uploads transaction logs for DB instances to Amazon S3 every five minutes. Litestream by default does it every second (you can go sub second with litestream if you want). | |
| ▲ | sudodevnull 6 hours ago | parent | prev [-] | | your understanding is very wrong. please read the docs or better yet the actual code. |
| |
| ▲ | locknitpicker 6 hours ago | parent | prev [-] | | > Backups, litestream gives you streaming replication to the second. You seem terribly confused. Backups don't buy you high availability. At best, they buy you disaster recovery. If your node goes down in flames, your users don't continue to get service because you have an external HD with last week's db snapshots. | | |
| ▲ | andersmurphy 6 hours ago | parent [-] | | If anything backups are the key to high availability. Streaming replication lets you spin up new nodes quickly with sub second dataloss in the event of anything happening to your server. It makes having a warm standby/failover trivial (if your dataset is large enough to warrant it). If your backups are a week old snapshots, you have bigger problems to worry about than HA. |
|
| |
| ▲ | rovr138 7 hours ago | parent | prev [-] | | No offense, you wait. Like everyone's been doing for years in the internet and still do - When AWS/GCP goes down, how do most handle HA? - When a database server goes down, how do most handle HA? - When Cloudflare goes down, how do most handle HA? The down time here is the server crashed, routing failed or some other issue with the host. You wait. One may run pingdom or something to alert you. | | |
| ▲ | locknitpicker 6 hours ago | parent [-] | | > When AWS/GCP goes down, how do most handle HA? This is a disingenuous scenario. SQLite doesn't buy you uptime if you deploy your app to AWS/GCP, and you can just as easily deploy a proper RDBMS such as postgres to a small provider/self-host. Do you actually have any concrete scenario that supports your belief? | | |
| ▲ | runako 5 hours ago | parent [-] | | > SQLite doesn't buy you uptime if you deploy your app to AWS/GCP This is...not true of many hyperscaler outages? Frequently, outages will leave individual VMs running but affect only higher-order services typically used in more complex architectures. Folks running an SQLite on a EC2 often will not be affected. And obviously, don't use us-east-1. This One Simple Trick can improve your HA story. |
|
|
| |
| ▲ | locknitpicker 6 hours ago | parent | prev [-] | | > You can scale incredibly far on a single node Nonsense. You can't outrun physics. The latency across the Atlantic is already ~100ms, and from the US to Asia Pacific can be ~300ms. If you are interested in performance and you need to shave off ~200ms in latency, you deploy an instance closer to your users. It makes absolutely no sense to frame the rationale around performance if your systems architecture imposes a massive performance penalty in networking just to shave a couple of ms in roundtrips to a data store. Absurd. | | |
| ▲ | klooney 5 hours ago | parent | next [-] | | You need regional state, or you're still back hauling to the db with all the lag. | |
| ▲ | andersmurphy 6 hours ago | parent | prev [-] | | That only solves read latency not write latency. Unless you don't care about consistency. |
|
| |
| ▲ | tl 8 hours ago | parent | prev | next [-] | | https://antonz.org/sqlite-is-not-a-toy-database/ — 240K inserts per second on a single machine in 2021. The problem you describe is real, but the TPS ceiling is wrong by three orders of magnitude on modern hardware. | | |
| ▲ | pdhborges 4 hours ago | parent [-] | | Do you know why it is a toy? Because in a real prod environment after inserting 240k rows per second for a while you have to deal with the fact that schema evolution is required. Good luck migrating those huge tables with Sqlite ALTER table implementation | | |
| ▲ | shimman 3 hours ago | parent | next [-] | | This doesn't seem like a toy but you know... realizing different systems will have different constraints. Not everyone needs monopolistic tech to do their work. There's probably less than 10,000 companies on earth that truly need to write 240k rows/second. For everyone else, we can focus on better things. | |
| ▲ | devmor 4 hours ago | parent | prev [-] | | Try doing that on a “real” DB with hundreds of millions of rows too. Anything more than adding a column is a massive risk, especially once you’ve started sharding. | | |
| ▲ | pdhborges 3 hours ago | parent [-] | | Yes it might be risky. But most schema evolution changes can be done with no or minimal downtime even if you have to do then in multiple steps. When is a simple ALTER going to be totally unacetable if youare using Sqlite? |
|
|
| |
| ▲ | rpdillon 10 hours ago | parent | prev | next [-] | | I wonder what percentage of services run on the Internet exceed a few hundred transactions per second. | | |
| ▲ | icedchai 9 hours ago | parent | next [-] | | I’ve seen multimillion dollar “enterprise” projects get no where close to that. Of course, they all run on scalable, cloud native infrastructure costing at least a few grand a month. | |
| ▲ | egwor 10 hours ago | parent | prev [-] | | I think the better question to ask is what services peak at a few hundred transactions per second? |
| |
| ▲ | darkwater 7 hours ago | parent | prev [-] | | I mean, your "This is fine for" is almost literally the whole point of TFA, that you can go a long way, MRR-wise, with a simpler architecture. |
| |
| ▲ | noahbp 7 hours ago | parent | prev [-] | | FYI, the color gradient on your website is an easy tell that it was vibe coded: https://prg.sh/ramblings/Why-Your-AI-Keeps-Building-the-Same... | | |
| ▲ | andersmurphy 7 hours ago | parent [-] | | A blog that's 11 years old and uses a minimalist CSS framework https://picocss.com ? It's a static blog that renders markdown... there's literally nothing to code, let alone vibe code. |
|
|
|
| ▲ | eurleif 12 hours ago | parent | prev | next [-] |
| Looks like the overhead is not insignificant: Running 100,000 `SELECT 1` queries:
PostgreSQL (localhost): 2.77 seconds
SQLite (in-memory): 0.07 seconds
(https://gist.github.com/leifkb/1ad16a741fd061216f074aedf1eca...) |
| |
| ▲ | piker 12 hours ago | parent | next [-] | | I love them both too but that might not be the best metric unless you’re planning to run lots of little read queries. If you’re doing CRUD, simulating that workflow may favor Postgres given the transactional read/write work that needs to take place across multiple concurrent connections. | | |
| ▲ | locknitpicker 10 hours ago | parent [-] | | > I love them both too but that might not be the best metric unless you’re planning to run lots of little read queries. Exactly. Back in the real world,anyone who is faced with that sort of usecase will simply add memory cache and not bother with the persistence layer. | | |
| ▲ | piker 8 hours ago | parent [-] | | Not sure that’s always right either though. For example Mapbox used to use an SQLite database as the disk cache for map tile info. You cannot possibly store that amount of data in memory, so it’s a great use case. |
|
| |
| ▲ | bob1029 12 hours ago | parent | prev | next [-] | | This is mostly about thread communication. With SQLite you can guarantee no context switching. Postgres running on the same box gets you close but not all the way. It's still in a different process. | | |
| ▲ | andersmurphy 9 hours ago | parent [-] | | This. Run an app on the same box as PG and you can easily be plagued by out of memory etc (as there's memory contention between the two processes). |
| |
| ▲ | madduci 11 hours ago | parent | prev | next [-] | | Most important is that that local SQLite gets proper backups, so a restore goes without issues | | | |
| ▲ | vixalien 11 hours ago | parent | prev | next [-] | | Would be nice to see PGLite[1] compared too 1: https://pglite.dev/ | | |
| ▲ | j45 39 minutes ago | parent [-] | | Interesting, but I'm not sure how relevant it would be for a SaaS that on average queries hundreds to thousands of rows. |
| |
| ▲ | locknitpicker 10 hours ago | parent | prev | next [-] | | A total performance delta of <3s on ~300k transactions is indeed the definition of irrelevant. Also: > PostgreSQL (localhost): (.
.) SQLite (in-memory): This is a rather silly example. What do you expect to happen to your data when your node restarts? Your example makes as much sense as comparing Valkey with Postgres and proceed to proclaim that the performance difference is not insignificant. | |
| ▲ | iLoveOncall 11 hours ago | parent | prev | next [-] | | Why are you comparing PostgreSQL to an in-memory SQLite instead of a file-based one? Wow, memory is faster than disk, who would have thought? | | |
| ▲ | eurleif 11 hours ago | parent [-] | | Because it doesn't make a difference, because `SELECT 1` doesn't need to touch the database: Running 100,000 `SELECT 1` queries:
PostgreSQL (localhost): 2.71 seconds
SQLite (in-memory): 0.07 seconds
SQLite (tempfile): 0.07 seconds
(https://gist.github.com/leifkb/d8778422d450d9a3f103ed43258cc...) | | |
| ▲ | oldsecondhand 10 hours ago | parent | next [-] | | Why are you doing meaningless microbenchmarks? | | |
| ▲ | saturn_vk 7 hours ago | parent [-] | | Are you claiming that this does not show the speed difference between socket vs in process communication? |
| |
| ▲ | j45 an hour ago | parent | prev | next [-] | | Queries for small SaaS are usually in the thousands of records, if not hundreds. | |
| ▲ | locknitpicker 10 hours ago | parent | prev | next [-] | | > Because it doesn't make a difference, because `SELECT 1` doesn't need to touch the database: I hope you understand that your claim boils down to stating that SQLite is faster at doing nothing at all, which is a silly case to make. | | |
| ▲ | eurleif 10 hours ago | parent [-] | | The original claim being discussed is about the overhead of an in-process database vs. a database server in a separate process, not about whether SQLite or PostgreSQL have a faster database engine. |
| |
| ▲ | nchmy 4 hours ago | parent | prev [-] | | How about pg on Unix socket? | | |
|
| |
| ▲ | stavros 10 hours ago | parent | prev | next [-] | | It is insignificant if you're doing 100k queries per day, and you gain a lot for your 3 extra seconds a day. | |
| ▲ | Izmaki 10 hours ago | parent | prev [-] | | What a useful "my hello-world script is faster than your hello-world script" example. |
|
|
| ▲ | usernametaken29 11 hours ago | parent | prev | next [-] |
| I have used SQLite with extensions in extreme throughput scenarios. We’re talking running through it millions of documents per second in order to do disambiguation.
I won’t say this wouldn’t have been possible with a remote server, but it would have been a significant technical challenge.
Instead we packed up the database on S3, and each instance got a fresh copy and hammered away at the task. SQLite is the time tested alternative for when you need performance, not features |
|
| ▲ | eikenberry 2 hours ago | parent | prev | next [-] |
| > It's not much harder to use than SQLite, you get all of the Postgres features [..] More features is a net negative if you don't need those features. Ideally you want your DB to support exactly what you need and nothing more. Not typically realistic but the closer you can get the better. |
| |
| ▲ | leptons an hour ago | parent [-] | | A feature you don't think you need today, might be one you actually need tomorrow. It would be short-sighted to choose some tech based only on what you need today. If the extra features don't cost you anything, I can't see that as a "net negative". | | |
| ▲ | eikenberry 4 minutes ago | parent [-] | | It is better to keep it simple and rework as needed than to try to anticipate everything ahead of time. |
|
|
|
| ▲ | jampekka 12 hours ago | parent | prev | next [-] |
| > It's not much harder to use than SQLite, you get all of the Postgres features, it's easier to run reports or whatever on the live db from a different box, and much easier if it comes time to setup a read replica, HA, or run the DB on a different box from the app. Isn't this idea to spend a bit more effort and overhead to get YAGNI features exactly what TFA argues against? |
|
| ▲ | jbverschoor 11 hours ago | parent | prev | next [-] |
| I've been doing that for decades.. People seem to simply not know about unix architecture. What I like about sqlite is that it's simply one file |
| |
| ▲ | dxxvi 7 hours ago | parent [-] | | But ... when you use the WAL mode, you have 3 files :-) |
|
|
| ▲ | pipeninja an hour ago | parent | prev | next [-] |
| You can't simply copy/paste a Postgres database though...also you'd be surprised how fast SQLite can be...I've used SQLite for projects where I just couldn't get the performance elsewhere. For example, I had a names database with over 100 million rows in it for converting names to diminutives (e.g. David to Dave) and the inverse...after I precomputed a metric ton of indices it went like a rocket. Sure the file was quite big but oh boy was it quick. |
|
| ▲ | himata4113 2 hours ago | parent | prev | next [-] |
| As someone who sets up a k3s cluster for a single user project I feel called out. The thing is one you learn the technology, everything else seems more work than the "easy way". |
|
| ▲ | weego 10 hours ago | parent | prev | next [-] |
| Thats just swapping another enterprise focused concern into the mix. Your database connection latency is absolutely not a concerning part of your system. |
| |
| ▲ | 9rx an hour ago | parent [-] | | Its not a significant concern because we've learned the hacks to work around it, but it is pretty freeing to not have to put hacks into your app. |
|
|
| ▲ | Jolter 12 hours ago | parent | prev | next [-] |
| I mean, you’re not wrong about the facts, but it’s also pretty trivial to migrate the data from SQLite into a separate Postgres server later, if it turns out you do need those features after all. But most of the time, you don’t. |
| |
| ▲ | pdhborges 11 hours ago | parent [-] | | I bet that takes more time than the 5 extra minutes you take to setup Postgres in the same box upfront. | | |
| ▲ | SpaceNoodled 4 hours ago | parent [-] | | To export a database? Probably even faster. And that's ignoring the difference in performance. | | |
| ▲ | pdhborges 3 hours ago | parent [-] | | So you are migrating from Sqlite to Postgres because you need it. What is the state of your product when you need to do this migration? Is your product non trivial? Are you now dependent on particular performance characteristics of Sqlite? Do you now need to keep your service running 24/7? Accounting for all of that takes way more than 5 minutes. The only way to beat that is if you still have a toy product and you can just export the database and import it and pray that it all works as a migration strategy. |
|
|
|
|
| ▲ | dizhn 11 hours ago | parent | prev | next [-] |
| Author's own 'auth' project works with sqlite and postgres. |
|
| ▲ | winrid 4 hours ago | parent | prev | next [-] |
| you also get a much better query execution engine, so if you need to run reports or analytics they will be faster |
|
| ▲ | direwolf20 10 hours ago | parent | prev | next [-] |
| IIRC TCP/IP through localhost actually benchmarked faster than Unix sockets because it was optimized harder. Might've been fixed now. Unix sockets gives you the advantage of authentication based on the user ID of who's connecting. My experience with sqlite for server-based apps has been that as your app grows, you almost always eventually need something bigger than sqlite and need to migrate anyway. For a server-based app, where minimizing deployment complexity isn't an extremely important concern, and with mixed reads and writes, it's rarely a bad idea to use Postgres or MariaDB from the start. Yes there are niche scenarios where sqlite on the server might be better, but they're niche. |
| |
|
| ▲ | lichenwarp 10 hours ago | parent | prev [-] |
| ORDERS OF MAGNITUDE NEWS |