In this guide
Stop duplicate Stripe webhook side effects with signature verification, durable event storage, transaction boundaries, and replay tests.
Duplicate Stripe webhooks should produce one business action even when an event is delivered more than once. Verify the signature, persist the event in a durable inbox with a unique event ID, and make downstream operations idempotent. An in-memory flag or a disabled checkout button cannot protect a webhook handler.
Why does a completed payment create two orders?
In an illustrative shop, Stripe sends a payment event, the server creates an order, and the HTTP connection times out before acknowledgement. The event is delivered again. If the handler blindly creates another order, one successful payment becomes two fulfillment tasks. A server restart can make a memory-only duplicate check disappear.
Begin by comparing provider event IDs with your order references and request logs. Two deliveries of one event ID differ from two distinct payment objects. That distinction matters: suppressing every later event for a customer can incorrectly discard a legitimate renewal or a second purchase.
Step 1: authenticate the delivery before reading its meaning
Use Stripe's supported signature-verification library with the endpoint's signing secret and the original request bytes. In Express, mount raw-body handling for this route before a generic JSON parser transforms the payload. Select the secret for the actual endpoint and environment, including local CLI forwarding when applicable.
Treat invalid signatures as rejected requests, not as a reason to disable verification. After verification, validate the event type and the fields required by your workflow. A valid Stripe event does not automatically mean that every object inside it matches an order your application is authorized to fulfill.
Step 2: store a durable event inbox with uniqueness
This illustrative PostgreSQL inbox records receipt, not completion. Insert only after signature verification. The unique key makes simultaneous deliveries compete at the database boundary instead of relying on application timing. A duplicate insert can be acknowledged because the original durable inbox record remains available for processing.
CREATE TABLE payment_event_inbox (
event_id text PRIMARY KEY,
event_type text NOT NULL,
payload jsonb NOT NULL,
received_at timestamptz NOT NULL DEFAULT now(),
processed_at timestamptz
);
-- Bound parameters from an authenticated event:
INSERT INTO payment_event_inbox (event_id, event_type, payload)
VALUES ($1, $2, $3::jsonb)
ON CONFLICT (event_id) DO NOTHING
RETURNING event_id;If insertion fails because the database is unavailable, return an appropriate failure instead of claiming acceptance. If persistence succeeds but queue notification fails, an inbox scanner must still find the unprocessed record. This is why storing a durable inbox before acknowledging is stronger than starting a background promise in the HTTP process.
Step 3: make order fulfillment safe to repeat
A worker should lock or claim an inbox record, inspect the current order state, apply the relevant transition, and mark the event processed with a well-defined transaction boundary. Give order creation a unique business reference too, such as the payment or checkout object appropriate to your payment flow.
Different event types can refer to the same purchase. For example, two independently valid notifications must not each create a shipment. Choose one documented fulfillment transition and enforce it in the database. Do not assume that event delivery order proves the current payment state; retrieve authoritative state where your workflow requires it.
External effects need their own retry protection. A database transaction cannot roll back an email already sent or a shipment already requested. Use an outbox with unique action keys, and use the downstream provider's idempotency support where available. Record action status so an operator can distinguish pending work from a completed action.
Step 4: test retries, crashes, and event order
- Deliver one signed test event twice. Confirm that one inbox entry and one order transition exist.
- Deliver the same event concurrently. Verify that database uniqueness prevents duplicate work under a race.
- Stop the worker after inbox persistence. Restart it and confirm that the event is eventually processed.
- Simulate a downstream timeout after the provider accepts an action. Confirm that retry uses the same action identity.
- Deliver related event types out of order. Confirm that the order state remains consistent with your chosen fulfillment rules.
Use Stripe test mode or an isolated sandbox for these checks. Keep test customers, orders, and fulfillment destinations separate from live data. A passing happy-path checkout test does not prove retry safety; the valuable tests interrupt work at the boundaries where an acknowledgement or state change can be lost.
Which records should operations be able to inspect?
Is storing the event ID enough?
An event ID prevents one narrow duplication case: replaying that same event. It does not by itself prevent two different event types from triggering the same order action, or a worker from repeating an external call after a crash. Define uniqueness at the business-action level as well as the delivery level.
For example, an order can have a unique fulfillment transition and a separately recorded shipment request. A retry finds the existing state and resumes unfinished work instead of creating another shipment. Write down these invariants before implementation. A reviewer should be able to point to the database constraint or provider idempotency rule that enforces each one.
Keep the provider event ID, object reference, internal order ID, processing status, attempt count, and last actionable error together. Avoid storing unnecessary payment or customer data in diagnostic logs. Define retention and access appropriate to the payload rather than treating an event inbox as an unlimited archive.
Monitor the age of unprocessed events and failed actions. A handler returning HTTP 200 can still be broken if the inbox grows forever. If queues are stalled, follow the Laravel queue recovery guide. For a reviewed integration, explore backend engineering and share your event-to-order workflow.
Official references and further reading
Stripe: duplicate events and event ordering
Relevant Scaleup Infotech Services
Keep Reading
Fix API 429 Errors With Safe Retry and Backoff
Handle API 429 Too Many Requests with Retry-After, bounded backoff, jitter, and shared request limits. Includes a read-only JavaScript example.
5 min readFix Laravel Queue Jobs Not Processing After Deployment
Recover Laravel queue jobs after deployment by checking the connection, queue name, workers, cached configuration, failed jobs, and restart behavior.
5 min readFix a Slow PostgreSQL Dashboard Query Step by Step
Trace a slow PostgreSQL dashboard query, inspect its execution plan, choose a focused index, and verify results with realistic filters and data.
5 min read