ART OF INTELLIGENCE

6 December 2026

Never send twice: idempotent side effects in automation

Retries create duplicates. Reserve, act, confirm, and never retry an unknown outcome blindly.

A workflow that sends an email, books a slot, posts a message or creates an invoice can run twice for the same item: a webhook is retried, a crashed execution is resumed, two triggers overlap, someone re-runs a failed run. The customer receives the email twice, the slot is booked twice, the invoice is issued twice.

Retry settings do not fix this. Retrying is exactly what creates the duplicate when the first attempt did reach the other system and only the answer was lost.

Reserve, act, confirm

Give every side effect an idempotency key built from what makes it unique, for example channel, recipient and business id. Record the key before acting, in a table where the database enforces uniqueness. Only the execution whose insert succeeds may act; every other one stops quietly. After the provider answers, mark the key as sent with the provider's id.

CREATE TABLE side_effects (
  key        text PRIMARY KEY,
  state      text NOT NULL DEFAULT 'reserved',  -- reserved | sent | failed | uncertain
  proof      text,
  created_at timestamptz NOT NULL DEFAULT now()
);

-- reserve: returns a row only for the ONE execution that wins
INSERT INTO side_effects(key) VALUES ($1)
ON CONFLICT (key) DO NOTHING
RETURNING key;

-- confirm after the provider answered
UPDATE side_effects SET state = 'sent', proof = $2 WHERE key = $1;

The part most implementations miss is the unknown outcome. If the run dies after acting and before confirming, the key stays reserved. After a timeout it becomes uncertain, and an uncertain key is never retried blindly: first check the other system (is the email in Sent, does the booking exist), then confirm it or release it. A timeout is not proof of failure.

The uniqueness must come from the store, not from the workflow. A lookup in a spreadsheet or an Airtable view followed by an insert is not atomic: two parallel runs can both see nothing and both act.

What we measured

We run this design in our own operations for every outbound message, across email, forms and platform messages. In a test on the production machine, twelve separate processes raced to contact the same recipient through three channels, five rounds in a row: exactly one reservation won each round, and every later attempt was refused.

If a workflow of yours sends duplicates, or nobody can say what happens on a retry, this is a small, fixed-scope repair: we add the key, the reservation, the confirmation and the uncertain check, with a test you can rerun.

Next

Write the problem. We will answer if we should take it.

Request a quote