~/t/g/self-hosting $

n8n webhook runs twice? Claim each event before acting

gist Compare incoming event IDs, claim each event atomically, and make retries safe before sending messages or changing records.

contents
  1. Step 1: Check the webhook URL and sender
  2. Step 2: Compare the incoming executions
  3. Step 3: Claim the event before side effects
  4. Step 4: Make unfinished work recoverable
  5. Step 5: Choose when to acknowledge the request
  6. Compare the approaches
  7. Common questions

If an n8n webhook repeats an action, use a stable event key and claim it atomically in persistent storage before acting. Keep enough state to recover unfinished work.

I run n8n in Docker on my Unraid box. For this pattern, you need access to saved execution data, the sender’s event ID rules, and a persistent store with an atomic uniqueness check.

Step 1: Check the webhook URL and sender

Open the Webhook node and compare the URL with the endpoint registered at the sender.

n8n provides separate Test URL and Production URL values. The test endpoint listens temporarily during testing. Publishing the workflow registers its production endpoint. Production data is available through the workflow’s Executions tab. Webhook documentation.

Check sender delivery records for:

  • A retry after a timeout or rejected response.
  • Two subscriptions pointing at the same workflow.
  • Separate events about the same record.
  • An intentional replay.

An order ID alone may be too broad. An order can have several valid events. Use the provider’s documented event identifier and confirm that it stays the same across retries.

Step 2: Compare the incoming executions

Open Executions, select each relevant run, and inspect the Webhook node’s input. Compare the event ID, timestamps, payload, and execution mode. n8n distinguishes manual and production executions. Execution documentation.

If the input is missing, check your execution saving and retention settings before repeating the test.

The screenshots come from a throwaway test install, not my live one.

Two successful execution rows do not explain why a request arrived twice. Matching event IDs within the same provider scope show repeated delivery of the same event. Then check the sender’s records to separate retries from duplicate subscriptions.

If there is only one execution, follow its branches. Check whether separate paths reach the same action. Also check whether someone manually reran saved input.

A Webhook-only workflow helps compare incoming requests. Check the downstream action’s own records to determine whether an email, write, or API call happened twice.

n8n Executions tab for a webhook workflow: two runs at the same second, both Succeeded, with the Webhook node open on the canvas
Two green runs in the same second look harmless here. Open each one and compare the Webhook input: the same event ID twice means the sender delivered it twice.

Step 3: Claim the event before side effects

Build the key from a trusted provider scope and a stable event ID. Include the account or subscription scope when the provider’s IDs are unique only within that scope. If one event drives several separate actions, give each action its own key scope.

Only the first execution to claim a key runs the action. A unique event key separates duplicate delivery from a new event. Failures and retries need explicit handling.

Avoid a separate “read key, then write key” sequence. Two executions can both read “missing” before either writes. A database uniqueness constraint makes the claim compete at one boundary.

For PostgreSQL, design an application-owned event table with:

  • Non-null provider_scope and event_id columns.
  • A composite primary key on those columns.
  • A status such as pending, succeeded, or failed.
  • Timestamps and enough stored input to recover the work.

A composite primary key enforces uniqueness across both columns. Back this table up with the rest of the database; see how to back up Postgres. PostgreSQL constraints.

For a table with those columns and that primary key, use this parameterized claim pattern:

WITH claim AS (
  INSERT INTO webhook_events (
    provider_scope,
    event_id,
    status
  )
  VALUES ($1, $2, 'pending')
  ON CONFLICT (provider_scope, event_id) DO NOTHING
  RETURNING event_id
)
SELECT EXISTS (
  SELECT 1 FROM claim
) AS claimed;

After running the query, inspect claimed: true indicates an inserted row; false indicates that no new claim was inserted. PostgreSQL’s ON CONFLICT DO NOTHING skips the conflicting insert, and RETURNING includes only inserted rows. PostgreSQL INSERT documentation.

Use the n8n Postgres node’s Execute Query operation. Supply the scope and event ID through Query Parameters, mapped to $1 and $2. Keep incoming values out of the SQL text. Postgres node documentation.

Route true toward processing. Route false toward checking the existing status. A stored claim does not mean the action finished.

Diagram: a unique event key separates duplicate delivery from a new event; handle failures and retries explicitly.
The claim is the gate: a new event ID gets in and runs the action, a repeat of the same ID is turned away before anything is sent.

Step 4: Make unfinished work recoverable

Handle crashes between claiming the event and finishing the action:

Stored state What to do
succeeded Skip the completed action.
pending with an active worker Let that worker continue.
Stale pending Check the execution and destination records before retrying.
failed with a known unsuccessful action Retry under a single-worker claim.
Unknown outcome after a timeout Check the destination or retry with its supported idempotency key.

Make recovery ownership atomic too. Before retrying unfinished work, check the original execution’s status and reconcile the destination’s result.

For an external API, reuse the same action key across attempts when the API supports idempotency. Check its key scope, retention period, and rules for changed request data.

For changes contained in one database, put the claim, change, and completion state in one transaction. For work sent elsewhere, a transactional outbox can record the work in the same transaction as the claim. A separate worker delivers committed work. Delivery can still repeat, so the destination needs safe repeat handling. Transactional outbox documentation.

Keep completed keys long enough to cover the sender’s retry and replay windows. Deleting a key allows that event to be accepted again.

Step 5: Choose when to acknowledge the request

n8n can respond immediately, after the last node, or through Respond to Webhook. Webhook response options.

A prompt response can reduce timeout retries. It cannot guarantee that an action happens exactly once.

For reliable background processing, acknowledge only after the event and required input are durably accepted. Then recover unfinished work independently of the sender. If storage fails, follow the sender’s documented retry rules rather than returning a success response.

Compare the approaches

Approach Useful when What it still needs
Persistent event keys You need duplicate detection across restarts. Atomic claims, retention, and recovery state.
Database uniqueness constraints Concurrent executions may receive the same event. Safe handling after the claim succeeds.
Caller-provided idempotency keys You control the sender’s request contract. The caller must reuse the key on retries; the receiver must enforce it.
Destination API idempotency An external action may succeed before a timeout. Documented support and the same key on every attempt.

Common questions

Why does my n8n webhook run twice?

Check for repeated requests, duplicate subscriptions, and manual reruns. Compare event IDs and sender delivery records. Two successful runs alone do not identify the cause.

Does responding immediately stop duplicate webhooks?

It can reduce retries caused by slow responses. Other repeated deliveries can still arrive. Use a persistent event claim to protect the action.

Can I use workflow static data for deduplication?

Use a persistent store with a documented atomic claim for concurrent requests. A read followed by a write leaves a race, regardless of where those values are stored.

Should I generate a new idempotency key on every retry?

No. Reuse the key for the same logical action. A new key makes the retry look like new work.

What if the action succeeds but n8n records a failure?

Check the destination before repeating it. Reuse a supported destination idempotency key, or reconcile the result before retrying an action with an uncertain outcome.

How do I check whether duplicate protection works?

In an isolated workflow, check sequential duplicates, simultaneous duplicates, a new event ID, a restart, and failures around the action. Compare destination records as well as execution history. The expected result is one completed action per key, with unfinished work recoverable.

Related: self-hosting guides · guide index.

../self-hosting/ every Self-hosting guide