← Back to the blog

AWS & n8n • 2026-07-30 • 3 min read

Idempotent Webhooks in n8n: Exactly-Once Without a Queue You Maintain

Every webhook sender retries, which means every workflow runs twice eventually. The claim table and key design that make the second run a no-op instead of a second invoice.

Idempotent Webhooks in n8n: Exactly-Once Without a Queue You Maintain — AWS & n8n

Webhook delivery is at-least-once. The sender has no way to know whether a timeout meant you did not receive it or that your response was lost, so it sends again. If your workflow creates an invoice, you now have two.

The idempotency key

The key identifies *the event*, not the delivery. Good sources, in order of preference:

  1. An event id from the sender, if it provides one — Stripe, GitHub and most mature APIs do
  2. A hash of the stable fields of the payload, excluding anything that changes per delivery, such as a timestamp or a delivery id
  3. A business key that is naturally unique: order-1234-paid

Hashing the whole body usually fails, because senders include a delivery id that differs between retries of the same event. Choose the fields deliberately.

Claim before you work

A row is inserted before the workflow does anything, with a unique constraint on the key. If the insert fails, this event is already being handled or has been handled, and the workflow returns the stored result.

// sql
INSERT INTO webhook_claims (idempotency_key, source, status, claimed_at)
VALUES ($1, $2, 'processing', now())
ON CONFLICT (idempotency_key) DO NOTHING
RETURNING id;

No row returned means somebody else claimed it. That is the whole mechanism, and the database's unique constraint is what makes it correct under concurrency — two simultaneous deliveries cannot both win.

Finishing the claim

On success, update the row to done and store the result, so a later retry can be answered with the original outcome rather than re-running anything.

On failure, the interesting choice. Delete the claim and the sender's next retry re-attempts the work. Keep it as failed and retries are suppressed until someone intervenes. We delete for transient failures and keep for permanent ones — a 500 from a downstream service is worth retrying, a malformed payload is not.

A claim stuck in processing because the worker died needs a timeout: a claim older than the workflow's maximum runtime is reclaimable. Without that, one crash blocks that event forever.

Respond fast, work later

Acknowledge with a 200 as soon as the claim is written, then do the work asynchronously. Senders have short timeouts — often five or ten seconds — and a workflow that calls three APIs will exceed that, producing retries caused entirely by your own latency.

In n8n this is the webhook node responding immediately, with the real work behind the queue described in the ECS hardening notes.

Test the duplicate path

The test that matters is sending the same event twice and asserting that exactly one invoice exists. Then send it twice concurrently, which is the case that finds the race your single-threaded test did not. This is the same reasoning as the outbox in our offline sync: the client retries, so the server defines what a repeat means.

Read next

COOKIES // MEASUREMENT

We count page views through Google Tag Manager. Say yes and it may store a cookie in your browser; say no and it still counts the visit, without storing anything and without an identifier. Nothing here is used for advertising.

Cookie Policy — you can change this at any time from the footer of any page.