Webhooks Explained: How Real-Time Automation Works
What webhooks are, how they differ from polling and APIs, and how to receive them securely and reliably, with signature checks, retries and duplicate handling.
· updated · 7 min read
In this article7 sections
A webhook is an HTTP request that one system sends to a URL you control when something happens, such as a payment succeeding or a form being submitted. Instead of your code asking the other system for news every few minutes, the other system tells you the moment it happens.
That makes webhooks the backbone of most real-time automation. They are simple to start with and easy to get wrong in production, because you are running a public URL that anyone on the internet can call. This guide covers both halves: how webhooks work, and what it takes to receive them safely and reliably.
How a webhook works
- You create an endpoint, a URL on your server or in an automation tool, that accepts HTTP POST requests.
- You register that URL with the sending service and choose which events you want, for example "payment succeeded" or "new lead".
- When the event happens, the service sends a POST request to your URL with the details in the body, usually as JSON.
- Your endpoint checks that the request is genuine, replies quickly with a 2xx status code and processes the data.
- If your endpoint does not reply with a 2xx in time, most services retry later, often several times over hours or days.
A typical payload looks something like this:
{
"id": "evt_1Q2w3E4r5T6y",
"type": "order.created",
"created": 1793001600,
"data": {
"order_id": "10234",
"email": "customer@example.com",
"total": 1490,
"currency": "SEK"
}
}
The id and type fields matter more than they look. The type tells you what happened, and the ID lets you recognise the same event if it arrives twice.
Webhooks vs polling vs APIs
An API is something you call when you want data. A webhook is the other system calling you. Most integrations use both: the webhook says "order 10234 was created", and your code then calls the API to fetch the full, current order.
Polling means calling the API on a schedule and asking what changed. It is less elegant but has real advantages. It works when the source has no webhooks. It does not lose events while your server is down, because the next run simply catches up. And it is easier to test. Many automation tool triggers poll under the hood, checking the source for new items on a schedule.
Use webhooks when speed matters or volumes are high. Use polling when the source has no webhooks, when a delay of a few minutes is acceptable, or as a nightly safety net that catches anything the webhooks missed.
Receiving your first webhook
The fastest way to see webhooks in action is an automation tool. In n8n, add a Webhook node and you get two URLs: a test URL that only listens while you click to listen for a test event in the editor, and a production URL that works once the workflow is live (activated or published, depending on your n8n version). Mixing them up is a common beginner problem. Everything works in testing, then the sender gets 404 errors in production. The n8n Webhook node docs describe the options, including whether to respond immediately or when the workflow finishes.
Zapier and Make have equivalent triggers (Webhooks by Zapier and Make's custom webhook module), and the n8n vs Zapier vs Make comparison covers how the tools differ more broadly. Many apps also offer native triggers that are webhooks underneath. Facebook Lead Ads is a common one, and a flow that sends a follow-up email the moment a lead comes in is a good first project.
If you write your own endpoint, three practical points:
- Use HTTPS. Many senders refuse plain HTTP, and payloads often contain personal data.
- Expose your local machine during development with a tunnelling tool, or use the sender's CLI if it has one. Stripe's CLI, for example, can forward test events to
localhost. - Log the raw request (headers and body) while you develop, so you can see exactly what arrives.
Security: verify every request
Your webhook URL is public. Anyone who finds it can send fake events, like a fake "payment succeeded". Serious senders therefore sign each request, typically with an HMAC of the raw request body using a secret that only you and the sender know. Always verify it.
import crypto from "node:crypto";
function isValidSignature(rawBody, signatureHeader, secret) {
const expected = crypto
.createHmac("sha256", secret)
.update(rawBody)
.digest("hex");
const a = Buffer.from(expected);
const b = Buffer.from(signatureHeader || "");
return a.length === b.length && crypto.timingSafeEqual(a, b);
}
The details vary per provider (header name, encoding, whether a timestamp is part of the signature), so follow their docs exactly. Stripe's webhook documentation is a good reference for how a mature provider does it. The general rules:
- Verify against the raw body. If your framework parses the JSON first and you serialise it again, the signature will not match. This is the classic cause of "invalid signature" errors.
- Use a constant-time comparison like
timingSafeEqual, not a plain string comparison. - Reject old timestamps if the provider signs one, to block replayed requests.
- Keep the secret in an environment variable or secret store, never in code. See environment variables for how to handle that.
- Do not trust the payload blindly. For anything important, fetch the object from the sender's API with your own credentials before acting on it.
If a sender offers no signatures at all, use a long random path segment or a secret header as a minimum, and restrict by IP address if the provider publishes its ranges.
Reliability: fast replies, retries and duplicates
Most webhooks are delivered "at least once". That one phrase explains many production problems.
Reply fast, process later. Senders have short timeouts. If your endpoint does slow work before replying, the sender times out and retries while the first run is still going. Validate, store the event, return 200, then do the heavy work in a background job or a separate workflow.
Expect duplicates. Retries, network glitches and your own redeploys all lead to the same event arriving twice. Store each event ID and skip IDs you have already processed. That makes the handler idempotent: running it twice has the same effect as running it once.
Do not rely on order. An "updated" event can arrive before "created". Where order matters, fetch the current state from the API instead of applying events in sequence.
Understand what an event represents. One action in the source system can mean many events, or an event can mean something other than you assume.
Protect the endpoint. A misbehaving sender or an attacker can flood your URL. Rate limits and payload size limits keep one bad source from taking down everything else. The guide on rate limiting covers the techniques.
Have a safety net. If your endpoint is down for longer than the sender keeps retrying, events are lost. A scheduled job that compares recent records in the source system with what you have processed catches the gaps.
Debugging webhooks
When a webhook does not work, check in this order:
- The sender's delivery log. Most services show each attempt with the status code and response body. This tells you whether the request reached you at all.
- The URL. Production or test URL, a trailing slash, HTTP instead of HTTPS, an inactive workflow.
- The status code you return. 401 or 403 usually points to a signature or auth problem, 404 to a wrong URL, 413 to a payload that is too large, and 5xx or a timeout means your handler crashed or took too long.
- Your raw request log. Compare what arrived with what your code expected. Field names and nesting often differ between event types.
- Replay. Most senders let you resend an event. Fix the problem, replay, verify.
Frequently asked questions
What is the difference between a webhook and an API?
With an API, your system requests data when it wants it. With a webhook, the other system sends data to you when an event happens. Most integrations use both, the webhook to get notified and the API to fetch details.
Are webhooks secure?
They are as secure as your endpoint. Use HTTPS, verify the sender's signature against the raw request body, keep secrets out of your code and validate important data against the sender's API.
What happens if my webhook endpoint is down?
Most senders retry failed deliveries for a period, so short outages usually recover on their own. For longer outages, use the sender's replay feature or a scheduled job that reconciles missed records.
Why am I receiving the same webhook twice?
Webhooks are usually delivered at least once, so retries and timeouts produce duplicates. Store each event ID and skip events you have already processed.
Can I use webhooks without writing code?
Yes. n8n, Zapier and Make all provide webhook triggers that give you a URL and turn incoming requests into workflow data, and many apps offer native triggers built on webhooks.
- Webhooks
- API
- Automation
- n8n

Written by Pontus Henriksson
Co-founder and CEO of Walldy in Sundsvall. I have built for the web since I was fourteen, tested games for studios like Netflix and Bungie since 2021, and write about what I use in real projects.
Liked this? Get the next one.
New Claude skills, kits and what I learn building AI for small businesses. Not often, only when it is worth sending. Unsubscribe with one click.