Designing a Commission Engine That Survives Refunds and Chargebacks
Commission balances drift because a single mutable number can't record why it changed. Build the engine as a double-entry ledger instead. Postings are insert-only, every entry sums to zero, and refunds or chargebacks are posted as exact reversals of the original entry, never as edits. Give each party and holdback its own account, derive balances from postings, and run trial-balance and clearing-account checks on every batch so drift shows up within a day.

