01 · Payments · Ledger · Correctness under partial failure

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.

$10M+cumulative payment flows
50K+transactions
0double-charge incidents
clientIdempotency-Key: k1payments APIreplay stored resultledger txncharge + key + outboxoutbox relayat-least-onceproviderkeyed calldead letterspark · inspect · replayobservabilitytrace every hop
Every mutating request carries a key; the ledger commits the charge, the key and the outbox row together.

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

FaultWhat happens
Client retries after a timeoutSame key, stored result replayed: one charge.
Worker crashes after the provider callOutbox redelivers; the provider call is keyed, so it is absorbed.
Duplicate delivery of a messageConsumer sees a key it already processed and acknowledges it.
A message that can never succeedParked in the dead-letter queue with context, not lost and not looping.
Idempotency keysTransactional outboxDead-letter recoveryObservabilityRelease discipline