Payment Reconciliation in SQL: Match Your Ledger to the Bank
Payment reconciliation in SQL: match every ledger row to the provider's report and every payout to one bank deposit, then explain what is left over.
I write about whatever catches my attention. Lately that's mostly databases and how backends hold up under load.
Start with the series →New posts also come out on the RSS feed.
Payment reconciliation in SQL: match every ledger row to the provider's report and every payout to one bank deposit, then explain what is left over.
Double-entry ledger design in Postgres: a deferred trigger rejects unbalanced transactions at COMMIT, and row locks in id order stop two payouts overdrawing.
Store money in a database as integer minor units plus a currency code. Why 19.99 * 100 loses a cent, why yen and dinars break 'cents', and how to split 10.00.
SQLITE_BUSY: database is locked still fires in WAL mode with busy_timeout set. Why a read-then-write transaction skips the wait, and the fix for each driver.
502 Bad Gateway on every deploy? Two causes: the old pod dies mid-request, or the proxy reuses a closed keep-alive socket. Fixes for Kubernetes, ALB and nginx.
How the transactional outbox pattern fixes the dual write problem, with diagrams, Postgres SQL, polling vs CDC, ordering, duplicates and the metric to watch.
What idempotency keys are, why every payments API uses them, and how to build them on the server with Postgres, with diagrams, SQL and common mistakes.
PostgreSQL 'FATAL: sorry, too many clients already': count who holds the connections, do the pool math, and use PgBouncer without breaking your sessions.
How to build a reliable job queue in PostgreSQL with FOR UPDATE SKIP LOCKED, with copy-paste SQL, diagrams, and the three ways it breaks in production.