Ledgerline
A small, correct double-entry accounting engine with an append-only journal and a queryable balance API.
- Year
- 2025
- Role
- Architecture, backend
- Status
- Shipped
- Stack
- Go
- Postgres
- gRPC
Ledgerline is the accounting core behind a payments product. It does one job: record immutable double-entry transactions and answer questions about balances, without ever letting the books drift.
The invariant
Every transaction must balance. That rule is enforced in the database, not in application code:
create table postings (
tx_id uuid not null references transactions(id),
account_id uuid not null references accounts(id),
amount numeric(20, 4) not null,
currency char(3) not null
);
-- A deferred constraint trigger checks that each transaction sums to zero.
Amounts are stored as exact decimals with an explicit currency. There are no floats anywhere in the system, and no balance column to update. A balance is a query over postings, which makes it impossible for a cached total to disagree with the journal.
Design notes
- Append-only. Corrections are new, reversing transactions. Nothing is updated or deleted.
- Idempotent ingestion. Every write carries a client-supplied key, so retried requests cannot double-post.
- Time is explicit. Each transaction records both the business date and the insertion time. Reports use the business date; reconciliation uses the other.
- Boring dependencies. One Postgres database, one binary. No queue between the API and the journal.
The API is gRPC with a thin JSON gateway. The core library is usable without the server, which made it possible to write property-based tests that generate thousands of random transactions and assert the ledger stays balanced.
Result
The engine has processed tens of millions of postings with no manual reconciliation drift. Its slowest query — a point-in-time balance across all accounts — runs in single-digit milliseconds on modest hardware.