What Would Uzair Do? · Issue #11

Why Your System Pays the Same Customer Twice

Nobody writes code that pays a customer twice. It happens because a partner sends the same message twice and your system politely believes it both times. It rarely shows up in testing. It shows up on your busiest day, when retries are most common and money moves fastest.

1. How a Retry Becomes a Payout

Payment providers, affiliate networks and marketplaces tell your system about events through webhooks: “this order was confirmed”, “this payment succeeded”. If they don't receive a quick enough reply, they send the same message again. Some send it out of order. Under load, some send it several times.

If your system treats every incoming message as new, each retry credits the wallet, issues the refund or triggers the payout again. On a normal day that might be a handful of cases a support agent catches. On a sale day, when partner traffic spikes and your servers reply more slowly, the retries multiply, and so do the duplicate payments.

2. Where I Ran Into It

At Savyour, a cashback platform connecting affiliate networks to consumer wallets, mega-sale campaigns like 11.11 and Black Friday brought bursts of simultaneous webhooks from merchant partners. Those notifications arrived with unpredictable retries, out-of-order deliveries and duplicate payloads. Every one of them carried money. A single duplicate-processing bug would have credited real money to a user's wallet twice.

A useful pre-mortem is to assume a duplicate credit on the busiest day, then work backwards to the ways it could happen. This is a hypothetical failure scenario, not a reported sale-day incident.

3. Four Controls That Stop Paying Twice

  1. Prove the message is genuine. Verify each partner's cryptographic signature (HMAC) before doing anything else. Reject messages that fail signature validation before processing them.
  2. Remember what you have already processed. Give every event an idempotency key, check it atomically before processing, and keep it for longer than the partner's retry window. At Savyour, duplicates were answered with the same “OK” as the original, without touching the database, to avoid reprocessing known duplicates within the retention window. A Redis key alone is not a durable exactly-once guarantee: a worker can fail after taking the key or after committing a credit. Design the authoritative ledger transaction with a durable unique event or order identifier, atomic recording and reconciliation before acknowledging successful processing. Those are recommended safeguards, not additional claims about the historical implementation.
  3. Never overwrite a balance. Record every credit and debit as an immutable line in a double-entry ledger and compute balances from those lines. If something does go wrong, you can trace exactly where each rupee or dollar came from instead of running manual forensic queries.
  4. Don't pay before the money is real. Hold rewards in stages (Pending, Verified, Cleared) until the merchant's return window closes, to reduce payout exposure from returns. Late reversals still need reconciliation.

4. Questions to Ask Your Team This Week

  • If a partner sends the same payment webhook three times in one second, what happens? Has anyone tested it?
  • How long do we remember processed event IDs, and is that longer than each partner's retry window?
  • Can we rebuild any customer's balance from a list of recorded transactions, or only read a number from a column?
  • Do we pay out before or after the refund or return window closes?
  • Has our webhook handling been load-tested at sale-day volume, or only one request at a time?

If any answer is “I'm not sure”, you have found a financial risk worth investigating before customers encounter it.

Related reading: Why Two Customers Can Book the Same Slot, What to Do When Growth Outpaces Your Software, and the Savyour sale-day case study.

Not sure your payment flow survives a duplicate webhook?

A fixed-scope $250 Pre-Mortem examines one critical flow, such as webhook ingestion, payouts or balance updates, and identifies likely failure risks and recommended controls. You get 3–5 pages of findings and a 30-minute walkthrough.

Explore The Architecture Pre-Mortem →