Templates / Engineering / Architecture decision record
0012-use-postgres-for-billing.md

ADR template

One decision that is hard to undo, why you made it, and what it costs, so people and agents stop reopening it.

docs/adr/, one numbered file per decision. Agents read the matching one before changing the code it covers.

Use in Almanac
docs/adr/0012-use-postgres-for-billing.md
# ADR 0012: Use Postgres for billing data- Status: Accepted- Date: 2026-11-28- Decided by: Priya Shah, Sam Ortiz- Replaces: none## ContextWhat is happening that makes us decide now? State the facts and the pressures, not the answer.Billing runs on a key-value store we picked in 2024 for speed. Finance now needs monthly reports that join invoices, credits, and refunds, and we write those joins by hand in code. Last month two reports disagreed because they joined the data differently.## DecisionWhat we will do, in one or two sentences that start with "We will".We will move billing data to Postgres and write every report as a SQL view that all reports read from.## Options we considered1. **Postgres (chosen).** Joins and transactions are built in, and we already run it for accounts.2. **Keep the key-value store and add a reporting copy.** Quick to start, but two copies that can disagree.3. **A data warehouse.** Good for reports, but too slow and too costly for the live app.## Consequences- Better: one source of truth for invoices, and reports that agree.- Worse: a two-week move, and writes about 20 ms slower at peak (measured on a copy of production).- New work: a script to copy old data, and one week of reading from both stores to compare.## How we'll know it workedEvery finance report matches the invoice totals for a full month after the switch.## For agentsRead this before you change anything under `api/billing/`.If a change goes against this decision, don't edit this file. Write a new ADR that replaces it, and set this one's status to "Replaced by ADR 00NN".

Questions people ask.

About decision records and when to write one.

What is an architecture decision record?

A short doc about one decision that is hard to undo: what you decided, why, what else you considered, and what it costs. It stops the same question from being argued again.

When should I write an ADR?

When a choice would take more than a week to reverse, like a database, a framework, or how two services talk.

Can I change an ADR after it is accepted?

Leave it as it was and write a new ADR that replaces it. The old one explains why things were done that way.

Keep your decisions where your agents can read them.

Almanac shows your repo's docs as a wiki that people and agents edit together.

Get started free