---
title: "Discussion on \"A Job Queue in Plain Postgres with SKIP LOCKED\" | Hashnode"
description: "Discussion on \"A Job Queue in Plain Postgres with SKIP LOCKED\". I benchmarked a Postgres job queue with up to 16 workers. Naive claiming ran jobs twice; SKIP LOCKED hit 35,000 jobs/s in batches, with zero duplicates."
url: "https://hashnode.com/posts/a-job-queue-in-plain-postgres-with-skip-locked-ds98e/6b0ff38ebae13f8e14a954d7"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [A Job Queue in Plain Postgres with SKIP LOCKED](https://blog.zyvop.com/a-job-queue-in-plain-postgres-with-skip-locked-ds98e?utm_source=hashnode&utm_medium=feed)

I benchmarked a Postgres job queue with up to 16 workers. Naive claiming ran jobs twice; SKIP LOCKED hit 35,000 jobs/s in batches, with zero duplicates.

16h ago · 19 min read · blog.zyvop.com  
Read the article

-   [#backend](https://hashnode.com/tag/backend)
-   [#concurrency](https://hashnode.com/tag/concurrency)
-   [#databaseperformance](https://hashnode.com/tag/databaseperformance)
-   [#jobqueue](https://hashnode.com/tag/jobqueue)
-   [#postgresql](https://hashnode.com/tag/postgresql)

## Written by

[ZyVOP](https://hashnode.com/@zyvop)

@zyvop · Delhi, India

  
[View profile](https://hashnode.com/@zyvop)

The Developer Publishing Hub

One platform to write, cross-post to Dev.to, Medium, WordPress, Hashnode, and Bluesky, and protect your SEO with canonical links. Zero paywalls and full content ownership.

## Responses 3

Markdown supported · ⌘↵ to post

[Jesse M. Hoffer](https://hashnode.com/@jessemhoffer)

[12h ago](https://hashnode.com/posts/a-job-queue-in-plain-postgres-with-skip-locked-ds98e/6b0ff38ebae13f8e14a954d7/comment/6b1026f663b74b9ae4afde83)

The fencing token point is the part people often skip. SKIP LOCKED solves claiming, but lease expiry is where duplicate side effects can sneak back in, so pairing attempts with complete() is a neat way to close that hole without extra machinery.

[ZyVOP](https://hashnode.com/@zyvop)

[12h ago](https://hashnode.com/posts/a-job-queue-in-plain-postgres-with-skip-locked-ds98e/6b0ff38ebae13f8e14a954d7/comment/6b1026f663b74b9ae4afde83#reply-6b102ad1c47536a50720cd38)

Absolutely. One important distinction, though: the attempts check in complete() prevents a stale worker from updating the job record, but it doesn't prevent duplicate external side effects like sending an email or webhook. That's where idempotency keys become important. Queue-level safety and side-effect safety need to work together.

[SqlOtter](https://hashnode.com/@sqlotter)

[57m ago](https://hashnode.com/posts/a-job-queue-in-plain-postgres-with-skip-locked-ds98e/6b0ff38ebae13f8e14a954d7/comment/6b10cefe18e953dd1e4c9ba8)

Your long-transaction section is a useful reminder that an apparently idle client can still hold back cleanup. A read-only first check is:

```sql
SELECT pid, usename, application_name, state,
       now() - xact_start AS transaction_age,
       wait_event_type, wait_event, left(query, 160) AS query
FROM pg_stat_activity
WHERE xact_start IS NOT NULL
ORDER BY xact_start;
```

A role may need `pg_read_all_stats` to see other sessions’ query text. I would review the owning application before terminating any session. Disclosure: I’m affiliated with SqlOtter; its SQL Editor can run this check against the target PostgreSQL connection.
