Webhooks: At-Least-Once Delivery

Why Webhooks Exist At All

The events that matter most in a payment's life don't happen inside any HTTP request you made. A 3DS challenge the cardholder completes twenty minutes after leaving your checkout. An ACH debit that settles — or fails — three business days later. A dispute opened ninety days after the sale (see Card network). None of these have a request to return a response on; the client that initiated the original call is long gone. A webhook is Stripe reaching back into your system on its own initiative, the only channel that exists for "something changed and you weren't watching."

Stripe's own fulfilment guidance states the failure mode of not having this directly: "You can't rely on triggering fulfilment only from your Checkout landing page, because your customers aren't guaranteed to visit that page. For example, someone can pay successfully in Checkout and then lose their connection to the internet before your landing page loads." The redirect is something that happens to a browser that may never load; the webhook is something Stripe keeps trying to deliver regardless of whether anyone's browser is even open.

At-Least-Once, Explicitly

Stripe retries a failed delivery — any non-2xx response, a timeout, a connection failure, even a 3xx redirect (treated as a failure, not followed) — with exponential backoff:

Live mode retry windowUp to 3 days, exponential backoff
Sandbox retry window3 retries over a few hours
Manual resend — DashboardUp to 15 days after event creation
Manual resend — Stripe CLIstripe events resend, up to 30 days after event creation

A manual resend that succeeds doesn't cancel Stripe's own automatic retry schedule for that event — the two tracks are independent, which is itself a source of extra duplicate deliveries beyond ordinary retries and worth accounting for explicitly rather than assuming "I resent it, so the old retries are dead."

An endpoint's status field on the WebhookEndpoint object is either enabled or disabled; a disabled destination stops receiving new deliveries and Stripe stops retrying events already in flight to it. Community and support reporting consistently describes Stripe emailing the account when an endpoint starts failing and again if it ends up disabled — but the exact automatic-disable trigger (whether it's tied strictly to the 3-day retry window expiring with zero successes, or some other threshold) isn't spelled out as a fixed number on the current docs page, so verify the live behavior against your own endpoint's dashboard rather than treating "3 days then disabled" as a hard-coded rule.

What Counts as Success

A 2xx status code, returned quickly. Stripe's docs are explicit that you must return it "before any complex logic that might cause a timeout" — they deliberately don't publish an exact number of seconds for the handler timeout.

The critical, and most common, real-world webhook bug is doing fulfilment work synchronously inside the handler:

✗ Synchronous — the common bug

def webhook(request):
    event = verify(request)          # ok so far
    if event.type == "payment_intent.succeeded":
        pi = event.data.object
        ship_order(pi.metadata.order_id)   # slow
        charge_ledger(pi.amount)           # slow
        send_receipt_email(pi)             # slow
    return 200                        # Stripe may have
                                       # already timed out

✓ Verify, persist, ack, process async

def webhook(request):
    event = verify(request)
    db.insert_event(event.id, event.type,
                     event.raw_body)   # unique on event.id
    enqueue(event.id)                 # hand off, don't block
    return 200                        # fast, every time

# separate worker, reading the queue:
def process(event_id):
    event = db.load_event(event_id)
    handle(event)                     # slow work happens here,
                                       # off Stripe's clock

No Ordering Guarantee

Stripe's docs state it plainly: "Stripe doesn't guarantee the delivery of events in the order that they're generated." Their own example: creating a subscription can generate customer.subscription.created, invoice.created, invoice.paid, and charge.created — four events from one API call, with no guarantee your endpoint sees them in that sequence. The same applies across a PaymentIntent's lifecycle: nothing prevents a later-stage event for an object from arriving before an earlier one. Snapshot events record created in whole seconds, so two genuinely distinct events can even share a timestamp — the docs explicitly warn not to use created to infer order or to decide whether you've already processed something.

The correct defense is a pattern worth naming: treat every event as a trigger to re-read, not a state delta to apply. Don't mutate your local record based on fields inside the event payload; use the event only to know which object changed, then either fetch that object's current state from the API or compare a version/sequence field before writing anything. Your own state machine (see PaymentIntent state machine) should independently reject any transition that would move a PaymentIntent backwards — if a stale, out-of-order event describes a status your local record has already moved past, the state machine's own guard rejects the write, no matter what order the events arrived in.

Consumer Idempotency

This is the mirror image of the server-side idempotency machinery in the Idempotency: the contract part/Idempotency: the machinery: the same event.id can be delivered more than once, and "check if I've processed this, then process it" is the identical check-then-act race the Idempotency: the machinery part describes for a client's own retries — a second delivery can arrive while the first is still mid-processing, see "not yet processed," and run concurrently with it.

The fix is the same shape as the Idempotency: the machinery part's: make the check and the effect atomic, in one transaction, using a unique constraint rather than a read-then-write.

Insert the event ID under a unique constraint, in the same transaction as the effect

BEGIN;
  INSERT INTO processed_events (event_id, event_type, processed_at)
  VALUES ($1, $2, now());          -- unique constraint on event_id

  -- if the INSERT above raises a unique_violation, catch it,
  -- roll back, and return 200 immediately: this delivery is a
  -- duplicate, already handled, nothing left to do.

  UPDATE orders SET status = 'fulfilled' WHERE id = $3;
COMMIT;

One nuance the docs call out that's easy to miss: "In some cases, two separate Event objects are generated and sent" for what is conceptually the same underlying change — meaning a unique constraint on event.id catches literal redelivery of the same event, but not every logical duplicate. Stripe's own recommendation for that case is to also key on the ID of the object in data.object together with event.type, not event.id alone, when the operation you're guarding is "has this object already reached this state" rather than "have I seen this exact event."

Signature Verification

Every webhook request carries a Stripe-Signature header:

Stripe-Signature: t=1492774577,v1=5257a869e7ece...,v0=6ffbb59b2300a...

Verification: build signed_payload as {timestamp}.{raw request body}, compute HMAC-SHA256 over it using the endpoint's whsec_... signing secret, and compare against the v1 value using a constant-time comparison (to prevent a timing attack from leaking the correct signature byte by byte). The v0 value is a fixed test-mode scheme and should be ignored in live verification; only v1 is currently valid.

The t= timestamp is what stops replay: an attacker who captures a valid payload and signature can't reuse it indefinitely, because your verification also checks the gap between that timestamp and the current time. Stripe's official libraries default to a 5-minute tolerance. The docs are blunt about the failure mode of disabling this: "Don't use a tolerance value of 0. Using a tolerance value of 0 disables the recency check entirely."

Two failure modes account for nearly all real signature-verification bugs:

Failure modeWhy it happens
Wrong signing secretEvery endpoint has its own whsec_... secret. Add a second endpoint (or mix a CLI-forwarded secret with a Dashboard-registered one) and verifying with the first endpoint's secret against the second endpoint's traffic fails every time — not intermittently, which is usually the tell.
Verifying a re-serialized body, not the raw bytesThe HMAC is computed over the exact byte sequence Stripe sent. Any framework middleware that parses the JSON body before your handler sees it — and reserializes it, reorders keys, changes whitespace, or changes encoding — silently breaks every signature, because the bytes you verify no longer match the bytes that were signed.

Thin vs. Fat (Snapshot) Events

Stripe currently runs two event formats side by side, and the docs distinguish which is current and which is preview carefully:

Snapshot events (fat)Thin events (v2)
PayloadLarge — the full API object as of when the event firedSmall — just the event/object IDs; fetch the rest
StalenessCan be stale by the time you process it; Stripe's own docs recommend re-fetching anywayForces the re-fetch pattern by construction — there's no stale embedded object to be tempted to trust
VersioningVersioned by API version — you manage versions on both sidesUnversioned — upgrade your integration without touching the webhook config
Generated byBoth API v1 and v2 resource changesAPI v2 resource changes; API v1 resources via thin events are in private preview as of the current docs

The architectural case for thin events is exactly the "fetch, don't trust" discipline the ordering section above argues for by hand: a thin event can't tempt you into reading a stale embedded object, because it doesn't carry one. Smaller payload, no staleness footgun, and the re-read pattern is the only pattern available — it's the same correctness property snapshot events require you to opt into by discipline, made structural instead. As of the current docs, thin events for the v1 resources most payment integrations are actually built on (PaymentIntents, Charges) are not yet generally available — plan around snapshot events for that surface today, and treat thin events for v1 as a preview capability to evaluate, not the default.

Webhooks vs. Polling vs. the return_url

WebhookPollingreturn_url / redirect
DirectionPush, Stripe-initiatedPull, you-initiatedBrowser-initiated, client-side
ReliabilityAt-least-once, retried for daysAs reliable as your polling loop; you own the retry logicNot guaranteed at all — the customer may never load it
Good forThe source of truth for every state change you must act onA one-off status check right after an action, or reconciliation sweepsImmediate UX only — "thanks for your order," not confirmation logic
Never use it for—Your only mechanism — you'll miss delayed/async transitionsDeciding whether the payment actually succeeded

This is the direct callback to the PaymentIntent state machine part: the redirect is a UX affordance, never a source of truth. Stripe's own words on the point: webhooks are "the most reliable way to confirm when you get paid." A landing page that fires fulfilment logic is a latency optimization for the customer who's still there watching — it is never a substitute for the webhook-driven path that fires regardless of whether they are.

The Webhook-Before-Database Race

Your server calls the PaymentIntents API, gets back an ID, and is about to commit a local row that maps your order to that ID — but hasn't yet. Meanwhile Stripe has already generated (and can already be delivering) payment_intent.created, and for a fast-authorizing payment method, payment_intent.succeeded can follow within the same round trip. The webhook can reach your endpoint before your own transaction commits.

The race between your own write and Stripe's webhook delivery
The race between your own write and Stripe's webhook delivery

Failure chain: the handler looks up an order keyed by pi_123, finds nothing because your own write hasn't landed yet → the naive handler either 404s and drops the event on the floor, or — worse — decides "no order exists yet, create one," producing a duplicate order that your original request's own commit will collide with moments later.

Two standard fixes, both already implied by earlier sections of this guide:

  1. Return a retryable status. If the lookup finds nothing, respond with a 4xx/5xx that signals "not ready, try again" rather than "permanently invalid" — Stripe's automatic retry schedule (this part, above) means the event comes back with exponential backoff, and by the second or third attempt your own commit has almost certainly landed.
  2. Make the lookup key something you wrote before calling the API. Generate your own order ID first, pass it as metadata on the PaymentIntent create call, and key your local table on that ID rather than on the Stripe-assigned pi_... ID that only exists after the round trip completes. This is exactly the PaymentIntent state machine part's write-ID-first discipline, applied to the consumer side of the same request instead of the producer side.

The Invariants

  • Guarantees: Delivered at least once, with automatic retries for up to 3 days in live mode; every request is signed and verifiable; the event body is a faithful snapshot (or a faithful pointer, for thin events) of the object as of when the event was emitted.
  • Does not guarantee: Not at most once — build for duplicates. Not in order — build for out-of-order arrival. Not delivered within any bounded time — a slow endpoint can still receive a Day 3 retry for a Day 0 event. And the event body is a snapshot at emit time, not the object's current state — by the time you read it, it may already be stale.