polycratia

The ledger was off by a few cents on one repayment, and I came close to closing the ticket as rounding noise.

The deal had multiple investors, each owed a pro-rata share of what the borrower paid. The code did the straightforward thing: take each investor's fraction, multiply, round to the nearest minor unit. Every payout looked right. Taken alone, each one was right.

The sum was not. Depending on the split, the parts landed a hair over or under the amount actually received. No exception, no alert, just a ledger that quietly stopped conserving money, once per repayment, across every active deal.

It surfaced during reconciliation against the bank side, and by then I was not holding a bug report. I was holding a backfill: recompute historical distributions, decide who absorbs each residual, and explain the drift to people whose entire job is trusting those numbers.

So distribution I now treat as an allocation problem rather than a multiplication problem. Integer minor units only. Compute the shares, then hand out the leftover units deterministically by a fixed ordering rule that someone wrote down on purpose. Assert that the parts sum to the whole before anything is persisted, and fail loudly when they do not.

Rounding bugs hide well because every individual row passes review. The damage lives in the sum, and no normal code path ever looks at the sum.

If you split money between parties, your residual goes somewhere: I think it is worth checking whether that somewhere was documented, or just accidental...

react

$ new-project --brief

or email hey@polycratia.com