Here’s what frustrates me about all these “Postgres is all you need” kinds of posts. Most of the design decisions, the backing store for the data is only a small piece of the overall puzzle. It’s an important part, but still, just saying, for example, that you don’t need to use Kafka, just store it in Postgres misses a whole lot of the reasons why you would use something like Kafka.
Such as?
The article fails to actually explain how to do durable workflows in Postgres:
In a Postgres-backed durable workflows system, application servers directly communicate with Postgres to execute workflows instead of going through a central orchestrator. A client submits a workflow for execution by creating an entry for it in a Postgres workflows table. Application servers poll the table for workflows to dequeue and execute. As a server executes a workflow, it checkpoints the output of each step to Postgres. If a server executing workflows crashes or fails, another server can recover its workflows from their checkpoints.
What you want are a locking clause (
FOR UPDATEfor example) to “acquire” an item from your queue andSKIP LOCKEDto skip over rows that are being processed. Contrary to what you’d normally do, you’d hold a long-running transaction which maintains a lock on the row you’re processing, then on completion either commits (success) or rolls back (failure) its changes to that row.You also don’t want to poll. Use
LISTENinstead.Don’t forget
NOTIFYI think this is a decent explanation: https://www.mgaillard.fr/2024/12/01/job-queue-postgresql.html




