Problem. A workflow that sends an email, posts a message, creates an invoice or books a slot can run twice for the same item: a webhook is retried, an execution is resumed after a crash, two triggers overlap, or someone re-runs a failed execution. The result is a duplicate email to a customer, a double booking or a second charge.

Retry settings do not solve this. Retrying is exactly what creates the duplicate when the first attempt did reach the other system but the reply was lost.

The pattern: reserve -> act -> confirm

Give every side effect an idempotency key and record it in a table before acting.

  1. Key. Build a deterministic key from what makes the action unique, for example channel | recipient | business id (email|ana@acme.com|invoice-1042). Hash it if it is long.
  2. Reserve atomically. Insert the key into a table with a UNIQUE constraint. Only the execution whose insert succeeds may act. Everyone else stops.
  3. Act. Send the email / call the API.
  4. Confirm. Mark the row sent with the provider's id (message id, booking id).
  5. Unknown outcome = do not retry blindly. If the execution dies between 3 and 4, the row stays reserved. After a timeout, treat it as uncertain: first check the other system (is the email in Sent? does the booking exist?), then either confirm it or mark it failed and allow a new attempt.

Postgres

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(), updated_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 UPDATE side_effects SET state = 'sent', proof = $2, updated_at = now() WHERE key = $1; -- Stale reservations become 'uncertain' (verify before any retry) UPDATE side_effects SET state = 'uncertain', updated_at = now() WHERE state = 'reserved' AND created_at < now() - interval '2 hours'; 

In n8n

  • Code / Crypto node: build the key ({{$json.channel}}|{{$json.to}}|{{$json.businessId}}), optionally SHA-256 it.
  • Postgres node (Execute Query): the INSERT ... ON CONFLICT DO NOTHING RETURNING key above.
  • IF node: continue only if the query returned a row. The other branch ends quietly (it is a duplicate).
  • Your action node (Gmail, HTTP Request, Calendly ...). Turn on "Continue on fail" so you can record the outcome.
  • Postgres node: confirm sent with the provider id, or failed only when the response proves nothing was sent (for example a 4xx validation error). A timeout is not proof of failure: leave it for the uncertain check.
  • A small scheduled workflow runs the stale -> uncertain update and, for each uncertain row, checks the other system before allowing a retry.

No Postgres? The same works with any store that has an atomic "insert if absent" (a unique index in MySQL/SQLite, a Redis SET key value NX, an Airtable/Sheets lookup is not atomic under parallel runs).

Why it holds under concurrency

The UNIQUE constraint is enforced by the database, not by the workflow, so two parallel executions cannot both win the insert. We tested the same reserve/confirm design with 12 separate processes racing for one recipient, five rounds: exactly one winner each round, and every later attempt was refused.

If a workflow of yours is sending duplicates or you are not sure what happens on a retry, we fix this at a fixed, written scope: ART OF INTELLIGENCE, https://art-of-intelligence.web.app/en/services/api-integration/?utm_source=devto&utm_medium=content&utm_campaign=zc-2026-12&utm_content=never-send-twice