You order a parcel online. You could check the tracking page every ten minutes, all day, to see if it has arrived. Or you could just get a notification on your phone the moment it’s delivered. The second is obviously better: less effort for you, and you find out right away.
Software has the same choice. Checking again and again is called polling. Being notified when something happens is a webhook. This guide explains how webhooks work, why they’re so common, and how to handle them safely.
What is a webhook?
A webhook is an HTTP request that one system sends to another automatically when an event happens. You give the other system a URL of yours, and it calls that URL whenever the event occurs.
It’s often called a reverse API. With a normal API, you call them to ask for something. With a webhook, they call you to tell you something.
Everyday examples:
- A payment provider calls your server when a payment succeeds or fails.
- GitHub calls your build server when someone pushes code, so tests start automatically.
- A chat app posts a message to a channel when your deployment finishes.
- An e-commerce platform tells your warehouse system when a new order is placed.
Webhooks vs polling
Polling means asking on a timer: “Any new payments? … Any now? … Any now?” It’s simple, but:
- Most calls are wasted. If you poll every 10 seconds and a payment arrives once an hour, around 359 of every 360 calls return nothing.
- You find out late. On average, you learn about an event half a polling interval after it happened.
- It doesn’t scale. Thousands of customers polling a provider every few seconds create huge load on both sides.
Webhooks flip it: the provider calls you once, right when the event happens. Fewer calls, faster news.
| Polling | Webhook | |
|---|---|---|
| Who starts the call | You, on a timer | The other system, on an event |
| Wasted calls | Many | Almost none |
| How fast you learn | Up to one polling interval late | Almost immediately |
| What you need | Nothing special | A public URL that can receive requests |
| If you’re down | You simply poll later | You may miss it, unless the sender retries |
How a webhook works, step by step
- Register. In the provider’s dashboard or API, you give a URL like
https://api.example.com/webhooks/paymentsand choose which events you want. - An event happens. A customer’s payment succeeds.
- The provider sends a POST to your URL, with a JSON body describing the event, for example its type (
payment.succeeded), an event ID, and the payment details. - You reply quickly with a
2xxstatus code to say “got it”. - If you don’t reply (or reply with an error), the provider usually retries later, often several times over hours or days, waiting longer between tries.
Receiving webhooks safely
Your webhook URL is open to the internet, so anyone could send fake requests to it. And because of retries, real events can arrive more than once. A solid webhook handler does five things:
- Verify the signature. Providers sign each webhook with a shared secret, usually in a header. Recompute the signature on your side and reject anything that doesn’t match. This proves the request really came from them and wasn’t changed.
- Check the timestamp. Reject events that are too old, so an attacker can’t replay a captured request later.
- Reply fast, work later. Save the event, put it on a message queue, and return
200immediately. Do the slow work (emails, updating orders) in the background. Slow replies cause timeouts and unnecessary retries. - Handle duplicates. Retries mean the same event can arrive twice. Store the event ID and skip ones you’ve already processed. This is idempotency.
- Don’t trust the order. Events can arrive out of order (“refunded” before “succeeded”). Check timestamps or fetch the latest state from the provider’s API before acting.
Sending webhooks from your own system
If your product sends webhooks to customers, you’re the provider. Plan for:
- Retries with backoff when customers’ servers are down, and a way for them to see and replay failed deliveries.
- Signing every request and documenting how to verify it.
- Timeouts, so one slow customer doesn’t tie up your senders.
- A queue of outgoing events, so a burst of events doesn’t overwhelm your system or theirs.
Common misconceptions
“Webhooks are a different technology from APIs.” A webhook is just an ordinary HTTP POST. The difference is who calls whom, and when.
“If I set up a webhook, I’ll never miss an event.” Your server might be down longer than the retry window, or have a bug. Many teams also run a slower reconciliation job that polls occasionally to catch anything missed.
“Webhooks are only for big integrations.” They’re one of the simplest ways to connect two systems, and many no-code tools are built on them.
Key takeaways
- A webhook is an HTTP request another system sends you when an event happens.
- It’s the opposite of polling: fewer wasted calls and faster updates.
- You register a URL; the provider POSTs events to it and retries on failure.
- Always verify signatures, reply fast and queue the work, and handle duplicates and out-of-order events.
- Treat important webhooks as a nudge to re-read the real state.
Frequently asked questions
What is a webhook in simple words?
A webhook is a way for one app to notify another app automatically when something happens, by sending a message to a web address that the second app provides.
What is the difference between a webhook and an API?
With an API, your system makes a request to get or change data when it wants to. With a webhook, the other system sends a request to you when an event happens. A webhook is sometimes called a reverse API.
Why are webhooks better than polling?
Polling sends many requests that usually find nothing new, and still learns about events late. Webhooks send one request right when the event happens, so they’re faster and use far less traffic.
How do I secure a webhook?
Use HTTPS, verify the provider’s signature on every request, reject old timestamps to stop replays, and treat the content as a hint by confirming important details through the provider’s API.
What happens if my webhook endpoint is down?
Most providers retry failed deliveries several times, waiting longer between attempts. If your endpoint stays down past the retry window, the event may be dropped, so it’s wise to also reconcile with the provider’s API from time to time.
Comments