n8n runs a webhook workflow twice when the same event is delivered twice. That happens for two reasons: the sender retries because your workflow answered too slowly, and some senders deliver copies of an event at the same moment. A "have I seen this id?" lookup does not stop the second kind. What works is to answer 202 right away, then claim each event with one atomic database insert before any costly step.
This guide explains both causes, shows what three common setups did under the same duplicate load, and gives the fix as SQL you can paste into your own workflow. The numbers come from a public, reproducible test: n8n-webhook-dedupe-demo on GitHub.
Cause 1: the sender retries because your workflow answers too late
By default the Webhook node answers when the last node finishes. If the workflow calls an AI model, a CRM or anything else slow, the answer can arrive after the sender has given up waiting. Most webhook senders treat a timeout as a failure and send the event again, often for days. The first run is still going, so now two runs process the same event.
In our test the sender waited 1 second and the AI step took 1.5 seconds. Every delivery timed out, so the sender retried, and the number of HTTP deliveries roughly tripled.
Cause 2: copies of the same event arrive at the same moment
Some senders deliver the same event more than once at nearly the same instant. The usual guard, "look up the event id, and skip it if it is there", is a read followed by a write. Every copy does the read before any copy has done the write, so they all pass. This is a race, and it gets worse the slower the steps between the read and the write are.
What we measured
Same load for every workflow: 20 unique events, each delivered 5 times at once, a 1 second sender timeout with up to 2 retries, and an AI step that takes 1.5 seconds. Three runs each, on n8n 2.47.5 with Postgres 16 in Docker, on 12 November 2026. The AI call is a local mock that counts calls; n8n, Postgres, the webhooks, the retries and the races are real.
| Workflow | AI calls for 20 events | Duplicate records |
|---|---|---|
| Look up the id, then insert (common pattern) | 106 to 109 | 86 to 89 |
| n8n's Remove Duplicates node | 29 to 50 | 9 to 30 |
| Answer 202 first, then atomic claim (the fix) | 20 every run | 0 every run |
No workflow lost an event. The common pattern paid for the AI step more than five times over. Numbers vary by machine and load; the full tables are in the repository.
Why the Remove Duplicates node is not enough under load
The node stopped most copies but not all, and the leak changed from run to run. In n8n 2.47.5 it reads the stored history, checks and appends in memory, and writes the history back without a lock, so two executions running at the same time can both pass. In one run 20 new events were recorded but the stored history grew by only 19. With no overlapping executions it removed every duplicate. It also still answers at the end of the workflow, so timeout retries continue.
The fix
Two changes, one for each cause.
- Answer right away. Set the Webhook node to respond immediately with status 202. The sender gets its answer in milliseconds and stops retrying.
- Claim each event with one atomic statement. Before any slow or costly step, insert the event key into a table whose primary key is that key. Only one copy can win the insert; the others get nothing back and stop.
The table:
CREATE TABLE IF NOT EXISTS processed_events (
event_key TEXT PRIMARY KEY,
status TEXT NOT NULL CHECK (status IN ('processing', 'done', 'failed')),
attempts INTEGER NOT NULL DEFAULT 1,
claimed_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
The claim, run in a Postgres node. The first parameter is the sender's event id; when it is empty, the key is a hash of the request body. It returns a row only for the one execution that should continue. A failed event, or a claim stuck for more than 5 minutes, can be claimed again by a later delivery.
WITH k AS (
SELECT COALESCE(
NULLIF($1, ''),
encode(sha256(convert_to(($2::jsonb)::text, 'UTF8')), 'hex')
) AS event_key
)
INSERT INTO processed_events (event_key, status, attempts, claimed_at, updated_at)
SELECT event_key, 'processing', 1, now(), now() FROM k
ON CONFLICT (event_key) DO UPDATE
SET status = 'processing',
attempts = processed_events.attempts + 1,
claimed_at = now(),
updated_at = now()
WHERE processed_events.status = 'failed'
OR (processed_events.status = 'processing'
AND processed_events.claimed_at < now() - interval '5 minutes')
RETURNING event_key;
Then put an If node after the claim: continue only when a row came back. Put your AI call, CRM insert or email on that branch, mark the event done at the end, and route errors to a step that marks it failed so a redelivery can retry it. The repository has the full workflow as JSON, ready to paste into the n8n canvas.
Limits worth knowing
- Keep event keys at least as long as your sender keeps retrying. A nightly delete of finished keys older than 7 days is enough for most senders.
- Answering 202 first means the sender will not retry your internal failures. Failed events are retried only when the event is delivered again, so add a scheduled sweep for events that must not be lost.
- Also put a unique index on the destination table's event key as a second guard.
- Emails, payments and other outside systems are only protected if you pass the same key to their idempotency key option.
- The claim is one statement on a primary key, so it holds with several n8n workers in queue mode. We did not measure queue mode; this test ran n8n in regular mode.