Money Invariants: Reconciliation, Ledgers, and the Double-Charge Taxonomy

The Double-Charge Taxonomy

The guide's central question asks which double-charges the idempotency key doesn't cover. Here is the exhaustive list — every mechanism that produces "the customer paid twice," whether the key helps, and what actually defends against it:

#ScenarioMechanismKey covers it?Actual defense
1Same request retried, same keyNetwork drop, client retries the identical callYesThe idempotency key itself (see Idempotency: the contract, Idempotency: the machinery) — cached response replayed, no second charge
2Retry with a fresh keyClient regenerates the key per attempt, or retries after the 24h key-expiry windowNoDerive the key from business identity — hash(order_id, operation) — not from a random UUID minted per call, so a "fresh" retry of the same logical action still produces the same key
3Double-click "Pay"Two distinct client-side actions, two distinct keys, both technically first-time requestsNoClient-side guard (disable the button on submit) plus a server-side unique constraint on (order_id, operation) — the client guard is UX, the constraint is the actual invariant
4Two systems charge the same orderA retry queue and a human in an admin panel both act on the same order, unaware of each otherNoA uniqueness constraint at the business layer (your orders or ledger schema), not the API layer — the idempotency key is scoped to one caller's request, not to "this order across every caller"
5Crash between charge and recordWorker crashes after the charge succeeds at Stripe but before your system persists that factNo, if the key was ephemeralWrite intent before you act (below) — the recovery path queries Stripe by the stable PaymentIntent ID (see PaymentIntent state machine) instead of re-issuing a new charge
6Response lost, client gives up, charges via a different pathThe charge succeeded at the network layer; the HTTP response never arrived; the client abandons that call entirely and starts a new one (the Card network part's reversal case)NoThe same rule as #5 — query the remote system by stable ID before assuming failure and starting over
7Duplicate webhook processingStripe redelivers an event (the Webhooks part's at-least-once guarantee) and the handler re-runs a non-idempotent side effect — a second fulfilment, a second internal ledger creditNo — different bug classConsumer-side idempotency: log processed event IDs and skip duplicates (see Webhooks) — this isn't a double charge against the card, but it's the same class of "the same real-world action happened twice"
Taxonomy rows7
Covered by the idempotency key alone1
Need an app-layer uniqueness constraint or ledger6

Row 1 is the only one the idempotency key actually closes. Everything else in this table is a gap that has to be closed at the application layer, and rows 2–4 share a pattern worth naming explicitly: the idempotency key's scope is one caller, one key, one 24-hour window — anything outside that scope (a different key, a different caller, a different day) is invisible to it. The key was never meant to be your only defense against duplicate charges; it was meant to make one specific narrow case — the network-level retry — free.

Write Intent Before You Act

Rows 5 and 6 generalize into one rule that recurs across the Idempotency: the machinery part (idempotency machinery), see PaymentIntent state machine (the PaymentIntent state machine), and the Webhooks part (webhook processing): persist a durable record of "I am about to do X, with this key" before the network call, and persist the result after. The window between those two writes is the only state that's genuinely ambiguous — and it must be resolvable by querying the remote system, not by guessing.

  1. Write intent. Insert a row — intent_id, order_id, idempotency_key, status='pending' — in its own transaction, committed before any network call. If the process dies here, recovery sees a pending row with no result and knows exactly what to check.
  2. Make the call.POST /v1/payment_intents with the same idempotency key stored in step 1. This is the only step where a crash produces real ambiguity — the request may have reached Stripe and succeeded, or never arrived at all.
  3. Write the result. On a response — success or a definitive failure — update the intent row with the PaymentIntent ID and final status. This is why the ID being stable and stored matters (see PaymentIntent state machine): it's the join key between "what we tried" and "what Stripe says happened."
  4. Recovery queries, never guesses. A process that finds a pending intent row on restart doesn't re-issue a fresh charge — it retries the same idempotency key (which is safe per row 1 of the taxonomy) or, if it has a PaymentIntent ID already, fetches that object directly to see what actually happened.
The only ambiguous window is between the network call and the result write — and it's resolvable by querying Stripe, not by re-charging
The only ambiguous window is between the network call and the result write — and it's resolvable by querying Stripe, not by re-charging

The Ledger

A payments table with a status column answers "what is the current state of this one payment." It cannot answer "why is our balance $340 short this month," "which entry corresponds to this specific dispute," or "show me every money movement for this customer, in order, with nothing edited in place." Those questions need an append-only double-entry ledger, where every money movement is an immutable row and a balance is derived by summing rows, never updated in place.

Propertypayments table with statusAppend-only double-entry ledger
A refundAn UPDATE on the original row — the pre-refund state is gone unless you kept your own audit log separatelyA new row referencing the original — the original charge entry is untouched, matching the Sagas and compensation part's compensation principle: you don't undo, you record an opposite
Current balanceWhatever the status column and some ad-hoc aggregation says right nowSUM(credits) − SUM(debits) over the entries — reproducible at any point in history by replaying entries up to that timestamp
Audit trailA feature you build separately (change-log table, triggers) and hope stays consistent with the main tableA byproduct of the schema — the entries are the audit trail, nothing extra to build or to drift out of sync
Concurrent writersRace conditions on the same row need explicit lockingInserts don't contend with each other the way updates to a shared row do

✗ Mutation — the refund overwrites the record

UPDATE payments
   SET status = 'refunded',
       amount = amount - 3000
 WHERE stripe_object_id = 'pi_abc';
-- the original $100.00 charge no longer
-- appears anywhere in this table

✓ Append — the refund is a new fact

INSERT INTO ledger_entries
  (account, direction, amount_cents,
   event_type, stripe_object_id, idempotency_key)
VALUES
  ('revenue', 'debit', 3000, 'refund', 're_def', 'refund:pi_abc:1'),
  ('clearing', 'credit', 3000, 'refund', 're_def', 'refund:pi_abc:1');
-- the $100.00 charge entries are still there, untouched

Minimal schema — enough to implement from

CREATE TABLE ledger_entries (
  id                BIGINT PRIMARY KEY,
  created_at        TIMESTAMPTZ NOT NULL,
  account            TEXT NOT NULL,       -- 'clearing', 'revenue', 'stripe_fees',
                                            -- 'customer:cus_123', 'dispute_reserve'
  direction          TEXT NOT NULL CHECK (direction IN ('debit','credit')),
  amount_cents       BIGINT NOT NULL CHECK (amount_cents > 0),
  currency           TEXT NOT NULL,
  event_type         TEXT NOT NULL,       -- 'charge','refund','dispute','dispute_fee','payout'
  stripe_object_id   TEXT NOT NULL,       -- pi_..., re_..., dp_...
  idempotency_key    TEXT NOT NULL,
  UNIQUE (idempotency_key, account, direction)
);
-- balance for any account, as of any time t:
-- SELECT SUM(CASE WHEN direction='credit' THEN amount_cents ELSE -amount_cents END)
-- FROM ledger_entries WHERE account = ? AND created_at <= t;

Walking one $100.00 charge, a $30.00 partial refund, and a subsequent dispute through it:

EventEntriesEffect
Charge succeeds, pi_abcdebit clearing $100.00 / credit revenue $100.00Revenue recognized, $100.00 sitting in transit toward settlement
Partial refund, re_def, $30.00debit revenue $30.00 / credit clearing $30.00The original two rows are untouched — this is a new pair, not an edit; net revenue for the charge is now derivable as $70.00, never overwritten
Dispute opened, dp_ghi, on the remaining $70.00debit revenue $70.00 / credit dispute_reserve $70.00Funds held pending the dispute's outcome — matches Stripe withdrawing the disputed amount from your balance immediately on dispute creation
Dispute fee assesseddebit revenue $15.00 / credit stripe_fees $15.00The $15.00 dispute fee (US) is charged regardless of outcome and is not refunded even if you win — per Stripe's current fee schedule; a separate, refundable $15.00 "dispute countered" fee applies only if you submit evidence, and is returned if you win
Four entries, chronological, none of them ever edited — the balance is whatever they sum to
Four entries, chronological, none of them ever edited — the balance is whatever they sum to

Every one of those rows is an insert, never an update. Querying "what happened to pi_abc" is SELECT * WHERE stripe_object_id = 'pi_abc' OR stripe_object_id IN (refunds/disputes referencing it) ORDER BY created_at — the full history, for free, because nothing was ever destroyed to make room for a new state.

Reconciliation

Three records exist for every dollar that moves, and they routinely disagree: your ledger (what you think happened), Stripe's balance transactions (what Stripe's ledger says happened, net of fees), and your bank statement (what actually landed, batched into payouts). The real sources of drift are specific and recurring, not random noise:

Source of breakWhy it breaks a naive comparison
Fees deducted at settlementYou charged $100.00; the balance_transaction's net field is amount − fee, so what lands is less than what you recorded, by a variable fee percentage — comparing gross amounts across systems looks like a discrepancy that isn't one
Currency conversionA charge in EUR settling to a USD bank account carries an exchange_rate field on the balance transaction; your ledger's original-currency amount and the settled amount are related by a rate that moves daily
Partial capturesAn authorization for $100.00 captured for $80.00 (see Authorize vs capture) produces a balance transaction for $80.00, not $100.00 — reconciling against the original authorization amount instead of the captured amount is a guaranteed false mismatch
Disputes and dispute feesA dispute pulls funds out of your balance immediately and adds a separate, non-refundable fee — both booked as type: adjustment with reporting_category: dispute, distinct from the original charge's own balance transaction — two (or three, with the fee) transactions against one original charge, not one
Payouts crossing a period boundaryA payout batches several days of balance transactions; a payout initiated on the 30th and paid on the 2nd of the next month splits your reconciliation window right through the transactions it contains
Events you never receivedA missed or permanently-failed webhook (see Webhooks) means your ledger simply never recorded an entry Stripe's balance transactions show — the two systems disagree not because either is wrong, but because yours is incomplete
Reconciliation is a periodic join on stable IDs, with a break queue for what doesn't match
Reconciliation is a periodic join on stable IDs, with a break queue for what doesn't match

The operational answer is a scheduled job, not a person eyeballing a spreadsheet: pull balance_transaction records for a window via the API (filterable by payout, by type, by date range), join them against your ledger entries on the stable Stripe object ID — never on amount — and assert that every Stripe-side transaction has a matching ledger entry and vice versa. Anything that doesn't match goes to a break queue for a human, tagged with which side is missing the entry and the transaction type (a payout_minimum_balance_hold or a reserve_hold failing to match is a different investigation than a plain charge failing to match).

Alert on the invariant, not on individual mismatches: the count of unresolved break-queue entries older than one settlement cycle, and the absolute value of your ledger's derived balance minus Stripe's reported available balance, both trending toward zero. A single unmatched transaction is Tuesday; a growing break queue is the early warning for a webhook outage or a code bug that both deserve a page, not a ticket.

Idempotency of the Money You Initiate

Refunds, transfers, and payouts accept the same Idempotency-Key header as any other Stripe API call — this is a property of Stripe's API generally (see Idempotency: the contract), not something special-cased for money-out operations. But a double refund is a materially worse incident than a double charge: a double charge has a counterparty who will notice and dispute it, generating a signal that something went wrong. A double refund sends money out with no counterparty to dispute it — the customer isn't going to complain that they were refunded twice, so the only detection mechanism is your own reconciliation catching it before or during settlement. Treat every refund/transfer/payout call path with the same write-intent-first discipline as a charge, and give it its own idempotency key derived from business identity (row 2 of the taxonomy) — "refund for dispute dp_ghi" should be exactly as replay-safe as "charge for order 4471."

Concretely: a retry-queue worker times out waiting on POST /v1/refunds, assumes failure, and re-issues the refund with a freshly generated key instead of refund:pi_abc:1 — the same bug as taxonomy row 2, but on the money-out side. The customer receives $60.00 back on a $30.00 refund. Nobody files a dispute over being paid extra. The only way this surfaces is the reconciliation job (above) noticing that net across the two refund-typed balance transactions for pi_abc doesn't match your ledger's single expected refund entry — which is exactly why the break-queue alert threshold matters more for refunds than for charges: the customer will never be the one to tell you.

The Invariants

  • Guarantees: An append-only ledger reconciled by stable ID gives you a balance that is always reproducible from history, a complete audit trail with nothing built on top, and a place for every one of the taxonomy's seven scenarios to be caught by a uniqueness constraint or a reconciliation break, even when the idempotency key itself doesn't apply.
  • Does not guarantee: That your ledger and Stripe's records agree in real time — reconciliation is a periodic assertion, not a synchronous transaction, so a window exists between a mismatch occurring and a scheduled job catching it. It also does not prevent a double charge by itself; the ledger's job is to make every double charge detectable and every state explainable, not to make double charges impossible — that's the job of the uniqueness constraints and idempotency keys the ledger's schema enforces.