RELIABILITY, SECURITY & CASE STUDIES · SUBTOPIC
Idempotent Payments & Double-Entry Ledgers
Prevent double charges, race conditions, and silent drift in financial systems.
AdvancedPart of Security, Auth & Payment Systems
Subtopics in Security, Auth & Payment Systems (2)
In plain words
Every payment gets a unique tracking sticker (idempotency key) so flaky Wi-Fi retries never charge twice, and every dollar moved writes a matching "-$50 from Alice" and "+$50 to Bob" receipt that can never be erased.
Think of it like…
Pen-written checkbook ledger where mistakes are fixed with a new adjustment entry, never white-out.
Loading interactive diagram
Loading interactive exercise
Theory & how it works
Always use integer minor units (cents), NEVER floating point
In IEEE-754 floating point, 0.1 + 0.2 === 0.30000000000000004. Store $19.99 as 1999 (BIGINT in cents) plus an explicit ISO currency code (USD).
Key points & practical guide
Summary checklist
- Store money as integer minor units (
1999cents) + currency - Enforce idempotency keys end-to-end (Client → API → Stripe)
- Run daily settlement reconciliation against PSP reports
When to use it
- E-commerce checkout, wallets, marketplaces, billing
Watch out for
- Using
FLOAT/DOUBLEfor prices or updating balances without row locking / optimistic version checks
Quick check
Loading quiz