Group
  • Testing

    Test that my webhook handlers survive duplicate delivery

    Prove webhooks processed twice (which providers do on purpose) don't double-charge, double-grant, or double-email.

    • Improve quality
    • Debug & fix
    • Intermediate
    • General

Free Prompt

Webhook providers retry deliveries, sometimes several times, and my handlers need to survive receiving the same event twice. For every webhook handler in my app (payment events, email events, third-party integrations), write tests that deliver the same event twice and assert: 1. The side effects happen once: one entitlement granted, one order created, one receipt email sent, one credit applied. 2. The second delivery returns a successful response (so the provider stops retrying) without repeating the side effects. 3. Out-of-order delivery is handled where it matters: a 'subscription canceled' event arriving before 'subscription created' doesn't crash the handler or corrupt the account state. If my handlers have no idempotency mechanism (no event ID tracking, no upsert logic, no state checks), the tests will fail. That's the point. Show me the failures and implement the fix: track processed event IDs, or make handlers naturally idempotent by checking current state before acting. Also verify signature verification is tested: an event with a bad signature must be rejected before any processing happens. When finished, run the suite and report per handler: idempotent or not, and what mechanism makes it so.

What This Does / How This Helps

This tests your webhook handlers against duplicate and out-of-order delivery, the two behaviors every webhook provider exhibits, and drives fixes like event ID tracking where handlers aren't idempotent. Stripe's docs say plainly that events can arrive more than once and occasionally out of order. A handler that grants access or sends a receipt on every delivery will double-email customers and double-grant entitlements within the first week of real traffic. Idempotency is boring infrastructure that prevents a class of bugs that looks, to a customer, like you don't know what you're doing.

Want to skip doing this by hand?

Fortivibe audits your app for all of the areas these prompts cover (and more).

See What We Check

Related Prompts