

taskq
A distributed job queue in Go built on Postgres with no message broker: leased claims, retries with backoff, a dead-letter queue, and zero lost tasks when workers are killed mid-run.
GoPostgresPrometheusGitHub Actions
- Workers claim tasks with a single UPDATE over SELECT ... FOR UPDATE SKIP LOCKED, so concurrent claimers skip each other's rows instead of queuing on the head of the queue.
- Each claim is a lease with a visibility timeout kept alive by heartbeats. A worker that dies is recovered by the same query that hands out new work, with no separate reaper process.
- Every completion is fenced on a lease token regenerated at each claim, so a slow worker whose lease expired cannot overwrite the new owner's result.
- Failures retry with full-jitter exponential backoff and land in a dead-letter queue. Attempts are counted at claim time, so a task that crashes its worker still dies instead of looping forever.
- In a chaos test, 3 of 5 worker processes are SIGKILLed mid-run: across 30,000 tasks, none were lost and idempotent writes absorbed every duplicate delivery.
- Peaks at about 19,300 tasks/s with 16 workers and holds p99 latency at 15 ms up to 1,000 tasks/s, measured with shuffled runs after finding that back-to-back benchmarks drifted 2.1x.
- One dependency (the pgx driver): Prometheus metrics are written by hand. 15 integration tests run against a real Postgres under the race detector in CI.