Joseph Leporati

Engineering notes

Writing: distributed systems

Notes on building and running production systems: payments and ledgers, multi-tenant architecture, reliability and performance, and applied AI. By Joseph Leporati, software engineer and technical program manager in Monroe, Louisiana.

· 7 min read · payments

Why Did We Get Charged Twice? Designing Idempotency for Payments

Most double charges come from a timeout. The first request reaches the processor, the response gets lost, and the client retries, so the system charges again. The fix is a client-generated idempotency key, stored atomically with the first attempt and backed by a database uniqueness constraint. An optional distributed lock covers the check-then-create race. Before you trust it with real money, test deliberate replays, timeouts and concurrent duplicates.

Read the article