SPB Git

Repository Public

ADR-0002-postgresql-queue.md 1.1 KB 19 lines markdown

1# ADR-0002 — PostgreSQL as the durable queue (no NATS JetStream)23Status: accepted, 2026-12-04. Reversible.45Decision. Tasks are rows; a lease is an `UPDATE … FOR UPDATE SKIP LOCKED` that sets an owner, an6expiry and a **fencing token** from a sequence. Completion is one transaction that checks the7token, stores the results and acknowledges. Expired leases are re-queued by the maintenance loop;8attempts are bounded and exhausted tasks are dead-lettered.910Why not NATS. The binding constraint of a polite crawler is the per-host rate (one request in11flight per host for the whole fleet), which needs transactional state next to the queue: the same12transaction must pick a task, check the host is free and mark it busy. With a broker this state13would live in a second system and the two would have to be reconciled. NATS is not installed on any14node, and no measurement shows the queue to be a bottleneck: at one request per host per second,15PostgreSQL leases are orders of magnitude above the need.1617Revisit when: sustained lease throughput above ~1 000 tasks/s is required, or workers must be18served across unreliable links without a gateway round-trip.19
Files main
Menu

Theme