# 7. Use Postgres for background jobs - Status: Accepted - Date: 2026-11-30 - Deciders: Platform team - Supersedes: [3. Use Redis for background jobs](0003-use-redis-for-background-jobs.md) ## Context The app sends emails, generates exports and calls webhooks in background jobs. Since ADR 3, jobs run on a Redis queue. Two problems keep coming up: - A job and the database write that created it are not atomic. When Redis is unavailable after a commit, the job is lost, which happened three times last quarter. - Redis is the only reason we run a second stateful service. It needs its own backups, monitoring and upgrades. We process about 40,000 jobs a day, with peaks of 30 a second. Postgres handles our current load at under 20% CPU. ## Decision We will run background jobs from a `jobs` table in Postgres, using `SELECT ... FOR UPDATE SKIP LOCKED` to claim work. Jobs are inserted in the same transaction as the change that creates them. We will use an existing library for the queue instead of writing our own. ## Consequences - A job exists if and only if its transaction committed. Lost jobs stop. - We remove Redis from production, its backups and its alerts. - Polling adds load to Postgres. We will alert when job claims take longer than 50 ms at the 95th percentile, and revisit this decision if they do. - The workers need a migration path: both queues run side by side for two weeks, then the Redis queue is drained and removed. ## Alternatives considered - **Keep Redis and add an outbox table.** Fixes lost jobs, but keeps both services and adds a relay process. - **A managed queue such as SQS.** Removes operations work, but jobs still aren't transactional and local development needs an emulator.