How to send webhooks to your customers: retries, signatures and SSRF protection

By David Garcia Berenguer · Published 2026-10-30 · Updated 2026-10-30 · Markdown version

Short answer: write each event to your database in the same transaction as the change that caused it, fan it out to one delivery per subscribed endpoint, and deliver from a worker with a lease. Sign with Standard Webhooks, retry on a schedule that spans about three days with jitter, block private addresses at connect time (not just when the URL is saved), never follow redirects, disable endpoints that keep failing, and keep a delivery log your customers can see.

A one-line feature request, a small distributed system

"Can you send us a webhook when an invoice is paid?" means a queue, a retry policy, signatures customers can verify, secret rotation, a settings page, a delivery log for support tickets, and an HTTP client that strangers can point at any address they like. Hosted services sell exactly this. Here is what to get right if you build it.

Data model

endpoints   (tenant, url, event filter, encrypted secret[s], status, failing_since)
messages    (tenant, id, type, payload)            one per event; (tenant, id) makes send() idempotent
deliveries  (message × endpoint, status, attempts, next_attempt_at, locked_until)
attempts    (delivery, status code, duration, error, first bytes of body)   the customer-facing log

Fan out at send time: one delivery per subscribed endpoint, each retrying on its own schedule, so one slow customer never delays another.

Durable first: the transactional outbox

"Order saved, webhook lost" and "webhook sent, order rolled back" are the same bug. Insert the message and its deliveries in the same transaction as the business change, and let a worker deliver them. The event exists if and only if the change committed.

Signatures your customers can verify

Use the Standard Webhooks format rather than inventing one:

  • Headers webhook-id (stable across retries, so receivers deduplicate on it), webhook-timestamp and webhook-signature.
  • HMAC-SHA256 over <id>.<timestamp>.<body>, whsec_-prefixed secrets, signatures as v1,<base64>, several space-separated.
  • Customers verify with an existing library in their language.

Rotation without downtime: for a window after a rotation (24 hours is a good default), sign with both secrets. The receiver accepts either; the customer deploys the new secret whenever they like.

Secrets at rest: you must be able to show the secret to the customer, so you can't hash it. Encrypt it (AES-256-GCM with a random IV) so a database dump alone doesn't reveal it.

Retries: a schedule, not a loop

The Standard Webhooks recommendation: immediately, then 5 s, 5 min, 30 min, 2 h, 5 h, 10 h, 14 h, 20 h and 24 h, about three days. Add jitter (±20 %) so a recovering customer isn't hit by every retry in the same second. Honour Retry-After up to a cap, so a hostile endpoint can't park deliveries for a year.

  • 2xx: delivered, reset the endpoint's failure streak.
  • 410 Gone: disable the endpoint at once.
  • 3xx: a failure. Don't follow redirects (see SSRF below).
  • Anything else, timeouts, network errors: schedule the next attempt.
  • An endpoint failing continuously for days: disable it and tell the customer. After they fix it, re-enable and replay what failed.

Workers claim due deliveries with FOR UPDATE SKIP LOCKED, a lease and a claim token, so a worker killed mid-request is replaced when the lease expires and its late write is discarded.

SSRF: the part most implementations miss

Your worker makes requests from inside your network to URLs chosen by customers. Two layers:

  1. Validate the URL on create, on update and before every attempt: https only, no credentials, no private or reserved IP literals (10.0.0.0/8, 127.0.0.0/8, 169.254.169.254, ::1…), no internal-looking hostnames.
  2. Check the resolved address at connect time. A hostname that was public when saved can later resolve to a private address (DNS rebinding). Run the check inside DNS resolution, on the addresses you actually connect to.

Never follow redirects: a redirect is a second destination that skipped both checks. See the OWASP SSRF prevention cheat sheet.

What not to promise

  • No ordering guarantee. Deliveries retry independently; receivers should use the payload's timestamp or fetch current state. Strict ordering would let one failing event block all others for days.
  • At least once. A request that succeeded but whose response was lost is retried; receivers deduplicate on webhook-id.
  • Small payloads. Cap them (64 KiB is plenty) and send ids receivers can fetch.

Implementing it in TypeScript

Outbound Webhooks is this design in about 1,450 lines of strict TypeScript with zero runtime dependencies, a PostgreSQL store, and a JSON management API for your customers' settings page:

import { aesGcmCipher, createManagementApi, createWebhookSender, PostgresStore } from "@softreuse/webhook-sender";

const store = new PostgresStore(pool);
export const webhooks = createWebhookSender({
  store,
  secretCipher: aesGcmCipher(process.env.WEBHOOK_SECRETS_KEY!),
  onEndpointDisabled: async (endpoint, reason) => notifyCustomer(endpoint.tenantId, reason),
});
export const webhooksApi = createManagementApi(webhooks, { basePath: "/api/webhooks" });

// inside your transaction: sent if and only if it commits
await webhooks.send(
  { tenantId: orgId, type: "invoice.paid", data: { id: invoiceId }, id: `invoice.paid:${invoiceId}` },
  { store: store.using(tx) },
);

// cron, every minute: deliver and retry
await webhooks.processDue({ limit: 50 });

Its tests include the Standard Webhooks published test vector, and DNS rebinding against a real HTTP server.

Checklist

  • Events written in the business transaction; one delivery per endpoint.
  • Standard Webhooks signatures; dual-signing during rotation; secrets encrypted at rest.
  • Retry schedule over ~3 days with jitter; 410 disables; dead endpoints disabled and reported.
  • URL validated on save and before every attempt; resolved address checked at connect time; no redirects.
  • A delivery log and replay, exposed to customers through your own UI.

Sources

Frequently asked questions

How should I sign webhooks I send to customers?

Follow the Standard Webhooks spec: HMAC-SHA256 over id.timestamp.body with a per-endpoint secret, sent in webhook-id, webhook-timestamp and webhook-signature headers. Customers can then verify with an existing Standard Webhooks library in their language.

How often should failed webhooks be retried?

On a growing schedule with jitter, not every minute forever. Standard Webhooks suggests immediately, then 5 seconds, 5 minutes, 30 minutes, 2, 5, 10, 14, 20 and 24 hours, about three days in total. After that, mark the delivery failed and let the customer replay it.

Why is sending webhooks an SSRF risk?

Customers choose the URL and your server makes the request from inside your network. Without checks, a customer can point an endpoint at your cloud metadata service (169.254.169.254) or an internal admin service. Validate the URL and also the resolved IP address at connect time, and never follow redirects.

What is DNS rebinding in webhook delivery?

A hostname that resolves to a public address when the customer saves the endpoint and to a private one later. Checking the URL only on save misses it; the address must be checked when the connection is made.

How do I rotate a webhook signing secret without downtime?

Sign with both the old and the new secret for an overlap window (for example 24 hours). Standard Webhooks allows several space-separated signatures, so receivers accept either while the customer deploys the new secret.

Should webhooks be sent inside the database transaction?

Write the event in the same transaction as the business change (the transactional outbox pattern) and deliver it afterwards from a worker. The event then exists if and only if the change committed.

See the module that implements this