DEV Community

delay.run
delay.run

Posted on Edited on

Adding a second webhook provider (payments, email, or billing)? A 12-point checklist so events don't get mixed, missed or double-handled

Reliable HTTP cron and delayed-job scheduling with automatic retries and full run logs — delay.run

The first webhook integration is usually "Stripe posts here and we update the invoice". The second one — another payment processor, a billing tool, an email provider, a fraud vendor — looks like a copy of the first. It isn't. You now have two signatures, two ID spaces, two retry behaviours, and sometimes two notifications for a single payment. The failures are "we missed it" and "we handled it twice", often in the same week.

This is the checklist I want before the second endpoint goes live.

Before you write the endpoint

1. Write down the business events, not the vendor events. "A payment succeeded", "a payment failed", "a refund closed", "an email bounced". Then map each provider's event names onto that list. If both providers can tell you a payment succeeded, you need one place in your model that becomes true once, not two handlers that both increment a counter.

2. Give each provider its own endpoint and its own secret. /webhooks/stripe and /webhooks/adyen (or /webhooks/mailgun), not one URL that tries to guess. Secrets go in a secret manager, per environment. Never reuse a signing secret across providers or across test and live.

3. Put both into the same inbox shape, keyed on (provider, event_id). Event IDs are not globally unique across vendors. A unique index on event_id alone will eventually collide, or will stop you from storing a legitimate event.

4. Decide the source of truth when they overlap. If a customer can pay with either provider, or you are mid-migration, a single payment might produce two webhooks. Your ledger should be unique on something you own (order_id, invoice_id) so the second event is a no-op, not a second fulfilment.

5. Use test-mode endpoints and test-mode keys until you can complete a full loop. For payments: succeed, fail, refund, dispute if you have it, and a replay from the dashboard. For email: delivered, bounced, complained. Do this against staging, with the staging secret. A live secret in a staging URL is a common incident.

Building the handler

6. Verify the signature of that provider, on the raw body, before you parse. A shared "webhook middleware" that slightly re-serializes JSON will break one of the two, usually the one you added second and tested less.

7. Acknowledge fast, process later, on a queue you already trust. Two providers means twice the chance of a slow downstream. If either endpoint is slow, that vendor will retry, and you will see duplicates even with a perfect inbox.

8. Log provider, event ID, event type, and your internal ID on every delivery. When a customer asks "why was I charged twice?", you want to see two event IDs, two providers, or two deliveries of one event, without guessing.

Two providers means two retry policies, and the only safe common ground is an idempotent handler with a visible log. delay.run can take the processing step as a delayed HTTP job per inbox row, retry it with backoff, and keep a run log, while each provider gets a fast 200 on its own endpoint.

9. Don't let a test event reach a live handler, or a live event a test one. Separate URLs, separate secrets, and a check that the payload's livemode (or equivalent) matches the environment. A test invoice.paid applied to production is a support week.

Going live

10. Enable the new endpoint in the vendor dashboard only after the URL is serving a verifier that returns 2xx on a real signed ping. Many providers disable the endpoint after a streak of 4xx/5xx. Start with a handler that can at least verify and store, even if processing is still feature-flagged.

11. Run both providers in parallel, with a comparison, if you are migrating. For a period, treat one as primary and log disagreements from the second (status, amount, customer). Do not cut the old endpoint off on the same day you enable the new one.

12. Add alerts on: signature failures, a rising duplicate rate, inbox rows stuck unprocessed, and a drop to zero events from a provider that usually talks. "Zero events" is the quiet failure — a disabled endpoint, a rotated secret, a typo in the new URL — and it looks like a peaceful dashboard.

Things that show up in week two

  • Event order differs by vendor. One sends payment_succeeded then invoice_updated; the other reverses them. Handlers that assume order will flake on the second provider only.
  • Time zones and amount formats. Cents vs major units, timestamps without a zone. Do not reuse the first provider's parser verbatim.
  • Dashboard replays by a teammate who is "just testing in production". The inbox should make that safe; the runbook should make it rare.

A second provider is a second integration, plus a consistency problem with the first. The checklist is there so you don't only solve the integration.

One more: who owns the endpoint after launch

The first provider often has a de facto owner, the person who built it. The second has a ticket and a dashboard nobody bookmarked. Write down who gets paged when events stop, where the secrets live, and how to rotate a signing secret without downtime (usually: support a second secret for a day, switch the vendor, remove the old one). A second provider you cannot rotate or debug is a time bomb, even if the code is fine.

Related reading

When you added a second webhook source, what broke first — signatures, double fulfilment, or a silent week of zero events?

Top comments (0)