Skip to content

Blog

Why an invoice’s balance is never stored

The most important decision in Veilux is a column that does not exist. Here is what it costs, and why it is worth it.

Open any invoice in Veilux and it tells you what is still owed. That number is not kept anywhere. It is worked out, every time you look, from the invoice's lines, the payments recorded against it and any credit applied to it.

The obvious design is a balance column. Record a payment, subtract it from the balance, save. It is fast, it is simple, and it is how most invoicing tools start. It is also wrong the first time anything behind it changes without passing through the one line of code that updates it: a payment reversed, a credit note withdrawn, a line corrected on a draft, an import that wrote payments directly. Each of those is rare. Together they are certain, and a stored balance that is wrong stays wrong — every report that reads it inherits the error, quietly, for years.

So there is nothing to drift. A balance is a question, and Veilux answers it from the ledger each time it is asked. The list of invoices, the invoice itself, the PDF your customer receives, the portal they sign in to and the reports your accountant reads all ask the same question of the same records, through the same function. They cannot disagree, because there is no second copy for one of them to be reading.

Money is whole pence. Every amount is stored as a whole number, and every tax rate is too: 20% is stored as 2000, not 0.2. A percentage stored as a fraction is how a tax line quietly becomes 17.499999 and a total is out by a penny nobody can explain. Rounding happens once, when a line is saved, and never again.

What it costs. Working a balance out is more work than reading a column, so the queries are written for it: the facts an invoice needs are loaded together, once, and folded in memory. It is a cost we pay on every page load so that you never pay it in a reconciliation.

What it means for you. Reverse a payment and every screen knows at once. Two currencies are never added together into a number that means nothing. And when a customer says the invoice is wrong, the answer is on the page — every payment and credit that made the number, in order.

Why an invoice’s balance is never stored · Veilux