John Karanja

The field guide · rule 04 of 16

Make actions safe to repeat

Connections drop and people press twice. An action that runs twice should have the same effect as running once.

What it means

Connections drop, servers restart and people press the button twice. A well-built action can run twice and still have the effect of running once. The safe way is a unique number for each request, which the database refuses to accept twice, rather than hoping everyone is careful. Engineers call this idempotency.

What goes wrong without it

A payout times out, the system tries again, and the customer is paid twice.

How I build it

From systems I build and run.

Ask your team

  1. If the same request arrives twice, is the second one refused?
  2. Does a retry first check whether the first attempt already worked?
  3. Is the duplicate check in the database, not only in the code?

A "no" or "not sure" is worth a closer look.

How a review checks this

The payments check forces timeouts and repeats on purpose, and shows whether anything is ever sent twice.

Request a reviewThe offer: Payments and ledger integrity checkCheck your system in one minute

Related rules