# Architecture decision record template

> An architecture decision record captures one significant technical decision, the context that forced it and its consequences, in a short file kept next to the code. Copy the example below into docs/adr, number it after your last record, and replace the context, decision and consequences with yours.

Updated November 30, 2026. Canonical: https://sniptide.com/templates/adr-template
Open it in the Sniptide editor: https://app.sniptide.com/new?template=adr-template
Files as JSON: https://sniptide.com/templates/adr-template.json

## Files

### docs/adr/0007-use-postgres-for-background-jobs.md

```markdown
# 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.
```

## When to write one [#when-to-write-one]

Write an ADR when a decision is expensive to reverse or will confuse someone in a year: a database, a framework, an API style, a hosting choice or a security model. The record answers the question a new teammate asks first, "why is it built like this?", without finding the person who decided.

One decision per file. Records are numbered and never deleted. When a decision changes, write a new record that supersedes the old one, and set the old one's status to `Superseded by` with a link. The history stays readable from start to finish.

## What each section does [#what-each-section-does]

| Section | What it settles | How to write it |
| --- | --- | --- |
| Title | The decision itself. | A short imperative phrase: "Use Postgres for background jobs", not "Job queue discussion". |
| Status and metadata | Whether the decision holds, when it was made and by whom. | `Proposed`, `Accepted`, `Deprecated` or `Superseded by N`. Link the record it supersedes. |
| Context | The forces at play: the problem, constraints and numbers. | Facts a reader can check, such as load, cost and incidents. Leave the decision out of this section. |
| Decision | What you will do. | One paragraph, starting "We will". |
| Consequences | What becomes easier, what becomes harder and what you will watch. | Include the bad consequences. A record without them reads as a sales pitch. |
| Alternatives considered | Options you rejected and why. | One line each, so nobody proposes them again without new information. |

This layout follows [Michael Nygard's original format](https://cognitect.com/blog/2011/11/15/documenting-architecture-decisions), with alternatives added because they are the part readers search for most.

## Keep them with the code [#keep-them-with-the-code]

Store records in `docs/adr/` and change them through pull requests, so a decision gets the same review as code. Name each file with a four-digit number and the title in kebab-case. Link the record from the code it explains when the reason isn't obvious from the code, such as a comment above the queue setup.

Coding agents read the folder too. A line in [AGENTS.md](/templates/agents-md) such as "Read `docs/adr/` before changing infrastructure" stops an agent from undoing a decision it doesn't know about.

## Variant: a lightweight record [#variant-a-lightweight-record]

For smaller decisions, a short form is enough:

```md title="docs/adr/0008-use-zod-for-validation.md"
# 8. Use Zod for request validation

Accepted, 2026-11-30.

We will validate every request body with Zod schemas in `lib/validation`, because the schemas also
give us TypeScript types and we already use Zod in the frontend. Hand-written checks are removed as
the routes are touched.
```
