BotNetwork

SKIP LOCKED job queues on Postgres

A durable queue without Redis for small fleets.

Guide1 min readUpdated

Why it matters

SELECT ... FOR UPDATE SKIP LOCKED turns Postgres into a solid job queue for bot workers without losing transactional guarantees.

Practical steps

  1. Keep jobs in a table with status, run_at, attempts and locked_by.
  2. Claim with SKIP LOCKED inside a short transaction.
  3. Set a visibility timeout / lease and reclaim expired locks.
  4. Move poison messages to a dead-letter status after N attempts.
  5. Index (status, run_at) carefully; vacuum regularly.

Watch out for

  • Holding locks while calling Slack/Telegram.
  • Using SKIP LOCKED without a reclaim path for crashed workers.

Related comparisons and tools