Zero double charges on a payments platform
Payment and ledger workflows that carried more than $10M across 50,000+ transactions without a single double charge in their production lifetime.
The problem
Money moves through networks that time out, retry and deliver twice. A client that never saw a response will try again; a worker can crash after the provider accepted a charge but before it recorded that fact. Each of those is a normal Tuesday, and each one is a double charge unless the system is built to absorb it.
What I built
Idempotent orchestration
Every mutating request carries an idempotency key. The key and the result are stored with the state change, so a retry replays the stored outcome instead of charging again.
Outbox delivery
The state change and the message that announces it are committed in one transaction. A relay delivers the outbox at least once; consumers deduplicate on the same key.
Dead-letter recovery
Messages that keep failing are parked with their full context instead of being retried forever, then inspected and replayed safely once the cause is fixed.
Observability and release discipline
Payment paths are traced end to end, and changes ship behind checks that make a bad release visible and reversible before it touches money.
Failure modes the design absorbs
| Fault | What happens |
|---|---|
| Client retries after a timeout | Same key, stored result replayed: one charge. |
| Worker crashes after the provider call | Outbox redelivers; the provider call is keyed, so it is absorbed. |
| Duplicate delivery of a message | Consumer sees a key it already processed and acknowledges it. |
| A message that can never succeed | Parked in the dead-letter queue with context, not lost and not looping. |