SELECT FOR UPDATE SKIP LOCKED, and the queue in a table

SKIP LOCKED lets several workers claim different rows from one table without blocking each other, which is what makes a database usable as a queue.

START TRANSACTION;

SELECT id FROM jobs
WHERE state = 'pending'
ORDER BY id
LIMIT 1
FOR UPDATE SKIP LOCKED;

UPDATE jobs SET state = 'running', worker = ? WHERE id = ?;

COMMIT;

-- without SKIP LOCKED every worker queues on the same row.

This is genuinely good enough for a modest queue and removes a whole component from the stack, which is worth something. What it does not give you is delayed delivery, priorities that do not degrade into a sort on every poll, or a consumer that blocks rather than polls — those are the reasons to reach for a real broker. The polling interval is the other cost: a second of latency per job, or a busy loop against the database.