Skip to main content

Trends, tech news, and tool comparisons.

How to add webhooks to a SaaS API

· 7 min read
Dealpuffin
Proof points and live coupons for early adopters

To add webhooks to a SaaS API, let customers register an HTTPS endpoint and pick event types, then POST a small signed JSON payload to that endpoint whenever an event happens. Sign each request with an HMAC over a timestamp and the body, retry failed deliveries with backoff for a few days, and give every event a unique ID so receivers can ignore duplicates. A delivery log and a "send test event" button finish the job.

The steps below follow the order you would build them in. Where it helps, they borrow conventions from Stripe's webhook docs and the open Standard Webhooks spec, which many API providers already use. Details were checked on 27 November 2026.

Step-by-step​

  1. Name your events. Use resource.action in the past tense: invoice.paid, project.created, member.removed. Start with the five or six events customers ask for; one event per database table is more than anyone will subscribe to. Adding an event later is easy; removing one breaks someone's integration.

  2. Choose the payload shape. A "fat" payload carries the full object; a "thin" one carries only the ID and type, and the receiver calls your API to fetch the current state. Thin payloads avoid sending stale data when events arrive out of order and keep sensitive fields out of logs. Fat payloads save the receiver a round trip. A practical default is the full object plus a type, an event id and a created timestamp, with a version field so you can change the shape later.

  3. Let customers register endpoints. Store the URL, the event types it subscribes to, a per-endpoint signing secret and an enabled flag. Accept only HTTPS. Reject URLs that resolve to private or internal addresses; the Standard Webhooks project names SSRF, spoofing and replay as the three attacks every implementation needs to handle.

  4. Sign every request. Compute HMAC-SHA256 over the event ID, a Unix timestamp and the raw body, using the endpoint's secret, and send the result in a header together with the ID and timestamp. The Standard Webhooks spec uses three headers (webhook-id, webhook-timestamp, webhook-signature). Stripe uses one Stripe-Signature header with t= and v1= entries and tells receivers to reject timestamps outside a tolerance; its libraries default to five minutes (Stripe webhook docs). Using an existing scheme means your customers can verify with libraries that already exist.

  5. Send from a queue, never inline. When the event happens, write it to an outbox table in the same database transaction, then let a worker deliver it. If you POST inside the request that changed the data, a slow customer endpoint slows down your API, and a crash between commit and send loses the event.

  6. Retry with backoff. Treat any non-2xx response or a timeout (5 to 10 seconds is common) as a failure. Retry on a growing schedule, for example after 1 minute, 5 minutes, 30 minutes, 2 hours, then every few hours. Stripe retries live-mode events for up to three days. After that, mark the delivery failed, and disable an endpoint that has failed for days, with an email to the account owner.

  7. Make duplicates harmless. Retries mean a receiver can see the same event twice. Keep the event id stable across retries and document that receivers should store processed IDs and skip repeats. Do not promise ordering; tell receivers to use the created timestamp or fetch the latest state.

  8. Show a delivery log. For each attempt store the endpoint, event ID, response status, a truncated response body and the time. Let customers resend a single event and send a test event from the dashboard. Most of your webhook support tickets get answered from this page.

  9. Document it. One page with the event list, a sample payload per event, the signature scheme with a verification snippet, the retry schedule and the IP ranges if you publish them. How to write docs for a SaaS API covers the rest of the reference.

A minimal sender in TypeScript​

import { createHmac, randomUUID } from "node:crypto";

export async function deliver(endpoint: { url: string; secret: string }, event: object) {
const id = `evt_${randomUUID()}`;
const ts = Math.floor(Date.now() / 1000).toString();
const body = JSON.stringify(event);
const sig = createHmac("sha256", Buffer.from(endpoint.secret, "base64"))
.update(`${id}.${ts}.${body}`)
.digest("base64");

const res = await fetch(endpoint.url, {
method: "POST",
headers: {
"content-type": "application/json",
"webhook-id": id,
"webhook-timestamp": ts,
"webhook-signature": `v1,${sig}`,
},
body,
signal: AbortSignal.timeout(10_000),
});
return res.ok; // false -> schedule a retry
}

In production the id comes from the outbox row so it stays the same across retries, and the worker records each attempt in the delivery log.

Build it or use a hosted service​

Build it yourselfHosted service (Svix as an example)
Upfront workOutbox, worker, retries, signing, log, dashboard UISDK call per event, embed their portal
Ongoing workDisabling dead endpoints, support for failed deliveriesMostly configuration
CostYour hosting and timeFree up to 50,000 messages a month; Basic from 20 USD a month
ControlFullTheir retry schedule and limits on lower plans

Svix's pricing page lists the free plan at 50,000 messages a month, 50 messages a second and 7-day payload retention. Basic starts at 20 USD a month with 30-day retention and 0.0001 USD per message beyond the included 50,000. Retries are not counted as messages.

Who should pick what: if you have a handful of event types and fewer than a few hundred customers, building it is a few days of work and keeps the stack simple. If customers ask for a self-serve endpoint portal, you send to many endpoints per account, or webhooks are a selling point of your API, a hosted service saves you from maintaining the parts customers notice when they break.

Test before customers do​

Point a test endpoint at a request inspector, fire every event type, and check the signature with a separate verifier so a bug in your signing code cannot hide itself. Then force failures: return 500, time out, return 410. Confirm that retries and disabling behave as documented. If you also receive webhooks from Stripe, the same habits apply on the receiving side; see how to test Stripe webhooks locally. Rate limits on the API that receivers call back into matter too; see how to add rate limiting to a SaaS API.

Frequently asked questions​

Should webhook payloads include the full object?​

Either works. Full objects save receivers an API call; thin payloads with just an ID avoid stale or out-of-order data. Many teams send the full object with a version field and tell receivers to fetch fresh state when order matters.

How long should I retry failed webhooks?​

A few days with exponential backoff is the common range. Stripe retries live-mode events for up to three days. After that, mark the delivery failed and let the customer resend it from the log.

How do receivers verify a webhook signature?​

They recompute the HMAC over the same signed content with their copy of the secret and compare it to the header using a constant-time comparison. They should also reject timestamps that are too old, which blocks replayed requests.

Do I need webhooks if I already have an API?​

Not on day one. Customers can poll. Add webhooks when integrations need to react within seconds, or when polling traffic starts to cost you more than sending events would.