I apply a specific set of rules to every line of code that touches financial data. These are not aspirational — they are non-negotiable in every system I have built.
Rule one: every financial operation is idempotent. If the same operation is executed twice, the financial result is identical to executing it once.
Rule two: every financial state change is logged with before-and-after values, a timestamp, a user or system identifier, and a correlation ID that links it to the originating request.
Rule three: no financial calculation uses floating-point arithmetic. All monetary amounts are integers in the smallest currency unit.
Rule four: every financial write is wrapped in a database transaction. If any part of the write fails, the entire transaction rolls back. No partial writes.
Rule five: reconciliation runs daily. The internal ledger is compared against the payment gateway's settlement report. Discrepancies are alerted immediately, not batched for weekly review.
These rules add development time. They eliminate the class of production incident where money is involved.
— Dick Bassey | DevDick | 2023