How to prevent duplicate webhook events on retry

TL;DR – Executive summary

Webhooks are often retransmitted (retry), which causes double orders and invoices. Solution: idempotency key or dedup board. Check the webhook-ID before processing.

Why Tulips Are Born

Webhook integrations work on a "push" basis: the sender calls your endpoint. The problem arises when:

  • Network Outage: The sender does not receive a reply → Retransmit
  • Timeout: Processing takes too long → The sender assumes failure
  • Error in reading: Sender will resend until successful
  • User activity: User click "Submit" twice

The sender does the right thing – Make sure the message gets through. Your job is to deal with duplicates.

Retry strategies

On the sender's side (not under your control)

  • Immediate retry: Immediately again (1-3 times)
  • Exponential backoff: 1s, 2s, 4s, 8s. growing delay
  • Dead letter queue: Failed will be moved to queue for later processing

On the Recipient's Side (you)

  • Reply 200 immediately: Acknowledge reception before processing (asynchronous)
  • Fast processing: Less than 5 seconds or move to background job
  • Idempotency: Handle the same message only once

Idempotency in practice

Idempotency = the same operation produces the same result, even if performed many times.

Idempotency key

The sender provides a unique ID (e.g. X-Idempotency-Key header or event_id body).

1. Receive webhook
2. Check: has event_id already been processed?
3. If yes → return 200, do nothing
4. If not → process and save event_id

Dedup Table

Save processed webhook-IDs to the database:

CREATE TABLE processed_webhooks (
  event_id VARCHAR(255) PRIMARY KEY,
  process_at TIMESTAMP DEFAULT NOW()
);

Case: order → landing → warehouse

An order is generated in the online store → You have to create an invoice and subtract from the stock.

Where is the dedup done?

  • Option 1: In the first phase (recommendation)
  • Option 2: Each stage individually (safer but more complex)

Recommendation: Check the subscription ID immediately in the webhook endpoint. If already treated → 200 OK, no action.

Do you have double-bills/double-bills?

Send a chain of events → We will provide a repair model.

Ask for a correction

Checklist: how to recognize and prevent doubles

  • ☐ Check webhook documentation: Is there a retry logic? What is a unique ID?
  • ☐ Save processed IDs: Dedup board or cache (Redis)
  • ☐ Check before processing: Is the ID already processed?
  • ☐ Respond quickly: 200 OK immediately, processing in the background
  • ☐ Monitor: Alarm if the same ID comes multiple times
  • ☐ Test: Simulate retry situations

Read also

Who is this service for?

  • Developers who build webhook integrations
  • Companies with double order or double invoice problems
  • IT equivalents debugging integration problems

Typical delivery with Datastorm

  1. Analysis: Where do doubles come from
  2. Correction: Idempotency logic, dedup table
  3. Testing: Retry simulation, monitoring
Request an estimate

What would you like to improve in your business?

Datastorm Oy's ERP delivery is a written agreement, ready-to-use system from design to commissioning. The initial discussion and the offer are free of charge; any separate specification work will be agreed in advance. Maintenance and subsequent further development will be agreed separately. Explore our ERP service.

Learn about the content of the related service and Tell us about your business need.

Tell us about your project

Tell us what you want to achieve. We’ll discuss your options and agree on the next step in a free introductory call.