Why it matters
SELECT ... FOR UPDATE SKIP LOCKED turns Postgres into a solid job queue for bot workers without losing transactional guarantees.
Practical steps
- Keep jobs in a table with status, run_at, attempts and locked_by.
- Claim with SKIP LOCKED inside a short transaction.
- Set a visibility timeout / lease and reclaim expired locks.
- Move poison messages to a dead-letter status after N attempts.
- 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.