Skip to content

The automation mistake that pays twice: idempotency in plain English

Webhooks arrive twice. Answers arrive late. If your automation moves money, sends messages or creates records, this one idea will save you.

Emmanuel Ohanwe··6 min read

There is a costly bug hiding in most automations that touch money: acting on the same event twice. It is easy to create and painful to clean up, and it is avoided with one idea that has an awkward name: idempotency.

What goes wrong

Payment providers send webhooks to tell you a payment or payout succeeded or failed. But:

  • The same webhook can arrive more than once.
  • An answer can arrive late, sometimes days later.
  • Your own retry can run while the first attempt is still in flight.

If your automation simply "does the thing" each time a message arrives, you get double receipts, double credits, or a refund issued for a payout that actually went through.

The idea: the same input gives the same result, however many times

An operation is idempotent if running it twice has the same effect as running it once. In practice:

  1. Give every action a unique key: the provider's transaction ID, or one you generate.
  2. Record the key before acting, and check it first. Seen it already? Do nothing.
  3. Apply a final answer once. When a payout's status changes from pending to final, update it only if it is still pending. In a database that is one conditional update, and it is enough to stop a second answer being applied.
  4. When the final answer changes, verify it. If a provider later says "actually it failed", ask the provider's API directly before you act.

Don't wait for the webhook

Webhooks get lost. Good systems also run a settler: a scheduled job that finds anything still open after a set time and asks the provider for the real status. In Kobocent, withdrawals and bank transfers each have one. In QuantumHire, job queues retry at 30 seconds, 2 minutes and 10 minutes, with crash recovery that never submits an application twice.

Don't say "done" until it's done

A "queued" response is not a success. A system that sends a receipt when the provider has only queued the payment will one day send a receipt for money that never arrived. Keep the record as processing until a final answer comes back.

A checklist for any automation that moves money

  • Unique key per action, checked before acting
  • Final answers applied once, with a conditional update
  • A changed final answer verified with the provider's API
  • A settler for anything open too long
  • "Queued" never shown as "paid"
  • Every step logged, with no secrets in the logs

We build payment workflows this way for fintech teams and for every product we ship. If yours moves money, let's review it.

Put this to work

Want this built for your team?