n8n guide

Why n8n runs the same webhook twice, and how to fix it

By Northkeel Labs. Updated 21 November 2026.

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.

WorkflowAI calls for 20 eventsDuplicate records
Look up the id, then insert (common pattern)106 to 10986 to 89
n8n's Remove Duplicates node29 to 509 to 30
Answer 202 first, then atomic claim (the fix)20 every run0 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.

  1. Answer right away. Set the Webhook node to respond immediately with status 202. The sender gets its answer in milliseconds and stops retrying.
  2. 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

Questions

Does this work in n8n queue mode?

The claim is a single statement on a primary key, so Postgres lets exactly one execution win no matter how many workers run it. We have tested it in regular mode only.

Can I use Redis instead of Postgres?

Yes. SET with NX and an expiry gives the same "only one caller wins" behaviour and a built-in stale timeout. You lose the attempts count and audit trail unless you add them, and keys are lost if Redis restarts without persistence. Postgres is the better default when your data is already there.

Which event id should I use?

The id your sender puts on each event, from a header or the body. Stripe, for example, puts it in the body as id. If your sender has no id, the claim falls back to a hash of the body.

Can you fix this in our workflow?

Yes. Send us the workflow that double-runs. Fixing one workflow is a Starter project, from USD 99, and we show you the before and after counts.

Is a workflow running twice?

Send us the workflow and what it triggers. We reply with the cause and a fixed price before any work starts.

Describe the problem

Or write to contact@northkeellabs.com