Skip to content

Decisions ​

Architecture decision records (ADRs): one page per significant choice, with the context that forced it, the options that lost, and what it costs. Code shows what the system does; these pages explain why it does it that way and what would have to change to decide otherwise.

#DecisionIn one line
0001Double-entry ledger with a balance cacheBalances are derived from append-only entries that always sum to zero
0002Money as integer centsbigint in Postgres, safe integers in JS, and a parser that refuses to round
0003Explicit SQL with pg, no ORMLocks, on conflict and unnest are the core of the system; they stay visible
0004One transaction per requestTransactionHost carries the client in AsyncLocalStorage; services never connect
0005Idempotency inside the same transactionKey, stored response and ledger entries commit together, or not at all
0006Pessimistic row locks in a fixed orderFOR UPDATE sorted by account id: overdrafts fail cleanly, deadlocks can't happen
0007Append-only ledger, fixes by reversalTriggers reject UPDATE/DELETE; mistakes are corrected with new entries
0008Serverless on Vercel + NeonMigrations in the build, transaction-scoped locks, and no top-level await
0009Tests against a real PostgresThe behaviour under test is the database's: locks, constraints, triggers
0010Docs site with VitePress, served by the APIThe markdown in the repo is the single source; one deployment, one origin

Format ​

Each record has the same sections:

  • Context: the problem and the forces at play.
  • Decision: what was chosen, concretely, with pointers into the code.
  • Alternatives considered: what was rejected, and why.
  • Consequences: what gets easier, what gets harder, and what would make us revisit it.

A decision that changes gets a new record that supersedes the old one; old records are not rewritten.

Money is an integer number of cents. Every movement sums to zero.