SPB Git

Repository Public

ADR-0002-postgresql-queue.md 1.1 KB

# ADR-0002 — PostgreSQL as the durable queue (no NATS JetStream)

Status: accepted, 2026-12-04. Reversible.

Decision. Tasks are rows; a lease is an UPDATE … FOR UPDATE SKIP LOCKED that sets an owner, an expiry and a fencing token from a sequence. Completion is one transaction that checks the token, stores the results and acknowledges. Expired leases are re-queued by the maintenance loop; attempts are bounded and exhausted tasks are dead-lettered.

Why not NATS. The binding constraint of a polite crawler is the per-host rate (one request in flight per host for the whole fleet), which needs transactional state next to the queue: the same transaction must pick a task, check the host is free and mark it busy. With a broker this state would live in a second system and the two would have to be reconciled. NATS is not installed on any node, and no measurement shows the queue to be a bottleneck: at one request per host per second, PostgreSQL leases are orders of magnitude above the need.

Revisit when: sustained lease throughput above ~1 000 tasks/s is required, or workers must be served across unreliable links without a gateway round-trip.

Files main
Menu

Theme