Try it on your own data
Every report in this article is in the free plan. One snippet for web and apps, up to 10 sites.
Start freeA webhook is a push: another system calls your URL when something happens. Polling an API is a pull: you ask on a timer. For rare events a webhook saves almost all requests and arrives sooner; for very high volumes, batched polling can send fewer. Either way, plan for retries, signatures and duplicates.
What you will learn
- For 120 orders a day, polling every minute makes 1,440 requests, at least 91.7% of them empty; webhooks make 120 plus retries
- Once events per day exceed polls per day, batched polling sends fewer requests than one webhook per event
- Verify the signature over raw bytes, use the event ID as an idempotency key and keep it longer than the retry period
Webhook vs API: what is the difference?
An API call is a pull: your program sends a request when it wants data and gets the answer back. A webhook is a push: another system sends an HTTP request to a URL you registered when something happens on its side. Both usually travel over HTTP and often carry the same JSON. What differs is who starts the conversation, and therefore who has to worry about timing, delivery and trust.
Strictly speaking, a webhook is one part of an API: the part where the provider calls you. So "webhook vs API" really means push vs polling. Polling asks "anything new?" on a timer. A webhook waits and is told.
| Question | Polling an API | Receiving a webhook |
|---|---|---|
| Who starts the request | You | The other system |
| When data arrives | On your next poll | Shortly after the event |
| Requests when nothing happens | One per interval | None |
| What you must run | A scheduler and a cursor | A public HTTPS endpoint |
| If your side is down | You poll again later and catch up | The sender must retry, or the event is lost |
| What you must verify | The server's TLS certificate | The sender's signature |
| Can you ask for history | Yes, if the API supports it | No, you only get what is sent |
The rest of this guide puts numbers on the first three rows, then covers the three things that make webhooks reliable: retries, signatures and idempotency.
How a poll and a webhook work
Take a shop that wants its fulfilment system to hear about paid orders.
With polling, the fulfilment system runs every minute:
- It sends
GET /orders?status=paid&updated_after=<last cursor>. - The shop returns the new orders, often an empty list.
- The client saves the newest cursor and sleeps until the next run.
With a webhook, the shop does the work when the order is paid:
- The fulfilment system registers
https://fulfil.example.com/hooks/ordersonce. - The shop sends a
POSTwith the order event to that URL. - The receiver replies with a
2xxstatus to say it has the message. - Anything else, including a timeout, counts as a failure and the shop tries again later.
The idea has a formal web standard in one area. WebSub, a W3C Recommendation, defines how a subscriber registers a callback URL with a hub, how the hub first verifies that the subscriber really asked for it, and how new content is then pushed as HTTP requests, optionally signed with a shared secret. Most business webhooks follow the same shape without implementing WebSub itself.
Push vs polling: the request count
Sample data: a shop with 120 paid orders a day, and one consumer that wants to know about them. A poll every interval costs 86,400 ÷ interval seconds requests per day. If orders arrive at random moments, the average wait until the next poll is half the interval and the longest wait is the whole interval.
| Method | Requests per day | Polls that return nothing (at least) | Average delay | Longest delay |
|---|---|---|---|---|
| Poll every 10 s | 8,640 | 8,520 (98.6%) | 5 s | 10 s |
| Poll every 60 s | 1,440 | 1,320 (91.7%) | 30 s | 60 s |
| Poll every 5 min | 288 | 168 (58.3%) | 2.5 min | 5 min |
| Poll every 15 min | 96 | 0 or more | 7.5 min | 15 min |
| Webhook, one per order | 120 plus retries | 0 | delivery time | longer only on failure |
"At least" assumes each order lands in a different poll; if several share one, even more polls come back empty. The trade-off in polling is unavoidable: each time you cut the delay by a factor of six, from 60 seconds to 10, you multiply the requests by six.
Multiply by consumers. If the shop is a platform with 200 customers each polling every 60 seconds, it serves 200 × 1,440 = 288,000 requests a day. Sending webhooks for 120 orders per customer is 200 × 120 = 24,000, a twelfth as many, and fresher.
Those empty requests are not free for either side. They use connection capacity, appear in logs and count against quotas. An API under pressure answers 429 Too Many Requests, defined in RFC 6585, which may include a Retry-After header; how to design around such limits is covered in rate limiting.
Requests per day to learn about 120 orders
requestsWhen polling still wins
Push is not always cheaper. Change one number in the sample: 50,000 events a day instead of 120. One webhook per event is 50,000 requests. A poll every minute is still 1,440 requests, each returning about 50,000 ÷ 1,440 ≈ 35 events in one page.
The rule of thumb that falls out: polling sends fewer requests than one-per-event webhooks once events per day exceed polls per day, provided the API returns batches. You pay for it with delay.
| If this describes you | Better fit | Why |
|---|---|---|
| Rare events, fast reaction needed | Webhook | No wasted requests, short delay |
| Very high event volume, a minute of delay is fine | Polling with pages, or a queue | Batches beat one request per event |
| You cannot expose a public endpoint | Polling | Outbound calls only |
| You need history or a full resync | API | Webhooks only deliver from now on |
| The provider offers no webhook | Polling | No choice; use a cursor, not "fetch everything" |
| Losing a single event is unacceptable | Webhook plus periodic API sweep | Each covers the other's gap |
If you poll, ask only for changes (a cursor or updated_after), spread clients out so they do not all fire on the minute, back off when told to, and handle pagination so a busy interval is not truncated. The choice between calling an endpoint directly and using a vendor library is a separate one, covered in SDK vs API.
| Point | API polling | Webhook |
|---|---|---|
| Direction | You pull | They push |
| Delay | Up to one interval | Delivery time, longer on failure |
| Cost when idle | One request per interval | Nothing |
| Recovery after downtime | Read from your cursor | Depends on sender retries |
| Security work | Protect your credential | Verify signature and block replays |
| History and resync | Available if the API offers it | Not available |
Many integrations use a webhook for speed and a scheduled API sweep for completeness.
Retries: what happens when your receiver is down
A poller that was offline for an hour simply reads from its cursor. A webhook depends on the sender trying again. How long and how often is the sender's choice, so read its documentation.
Standard Webhooks, an open specification for sending webhooks, recommends exponential backoff with some random jitter over several days, and gives this example schedule:
| Attempt | Wait before it | Time since the first attempt |
|---|---|---|
| 1 | none | 00:00:00 |
| 2 | 5 seconds | 00:00:05 |
| 3 | 5 minutes | 00:05:05 |
| 4 | 30 minutes | 00:35:05 |
| 5 | 2 hours | 02:35:05 |
| 6 | 5 hours | 07:35:05 |
| 7 | 10 hours | 17:35:05 |
| 8 | 14 hours | 31:35:05 |
| 9 | 20 hours | 51:35:05 |
| 10 | 24 hours | 75:35:05 |
Now apply it to an outage. Your receiver is down for 4 hours.
| Event created | Outage time left | Delivered on attempt | Arrives at (hours since outage began) |
|---|---|---|---|
| At the start | 4 h 00 min | 6 | 07:35:05 |
| 3 h in | 1 h 00 min | 5 | 05:35:05 |
| 3 h 50 min in | 10 min | 4 | 04:25:05 |
The first order of the outage arrives about 7.6 hours after it happened, although you were back after 4. And the order created at the start arrives after the two created later. Two conclusions:
- Do not assume order. Compare the event's own timestamp or version before overwriting newer state with older.
- Do not assume backoff will catch you up. After an outage, read the gap from the API instead of waiting.
The same specification says how senders should read your answer: any 2xx is success and anything else is failure; 410 Gone means stop sending; 429, 502 and 504 suggest throttling; and it recommends a sender timeout of 15 to 30 seconds. So acknowledge quickly and do the slow work afterwards from your own queue.
Signatures: prove who sent the webhook
Your webhook URL is reachable from the internet, so anyone who learns it can post to it. HTTPS protects the data in transit but does not tell you who is calling. A signature does.
In the Standard Webhooks scheme, the sender includes three headers (webhook-id, webhook-timestamp, webhook-signature) and signs the string id.timestamp.body. With a shared secret, the signature is the Base64 of HMAC-SHA256 over that string, prefixed v1,. A sample you can recompute:
secret: whsec_c2FtcGxlLXdlYmhvb2stc2VjcmV0LTMyLWJ5dGVzISE=
id: msg_sample_001
timestamp: 1796256000
body: {"type":"order.paid","data":{"order_id":"ord_1001","total":50}}
signature: v1,zww9KFdlHpLsEn7fKlkA/kOGtcdzL5740ZkRLXTQa/Y=
Verification in Python:
import base64, hashlib, hmac, time
def verify(secret, headers, raw_body, tolerance=300):
msg_id = headers["webhook-id"]
ts = headers["webhook-timestamp"]
if abs(time.time() - int(ts)) > tolerance:
return False
key = base64.b64decode(secret.removeprefix("whsec_"))
content = f"{msg_id}.{ts}.".encode() + raw_body
digest = hmac.new(key, content, hashlib.sha256).digest()
expected = "v1," + base64.b64encode(digest).decode()
return any(hmac.compare_digest(expected, s)
for s in headers["webhook-signature"].split())
Four details cause most failures or holes:
- Verify the raw bytes. In the sample, adding a space after each colon in the body makes verification fail. Parsing JSON and serializing it again before checking is a common mistake that the specification calls out.
- Check the timestamp. It limits how long a captured request can be replayed. The 300 seconds above is a sample tolerance.
- Compare in constant time, as
compare_digestdoes. - Allow several signatures. The header can list more than one so that a secret can be rotated without downtime.
Not every provider follows this specification. Header names, encodings and signed strings differ, so implement what your sender documents. The specification also describes asymmetric signatures, which spare the receiver from holding a secret that could forge messages.
Idempotency: process each event once
Retries guarantee that you will sometimes receive the same event twice: your handler did the work but the 2xx was lost, or answered after the sender's timeout. HTTP treats POST as not idempotent (RFC 9110 lists PUT, DELETE and safe methods as idempotent), so the receiver has to provide that property.
In Standard Webhooks, webhook-id identifies the event and stays the same across retries, while webhook-timestamp changes with each attempt. Use the ID as your key:
- Verify the signature.
- Insert the ID into a table with a unique constraint.
- If the insert fails, you have seen it: return
2xxand stop. - Otherwise put the work on a queue, then return
2xx. - Keep IDs longer than the sender's whole retry period.
On point 5, note the numbers: the specification mentions storing IDs for 5 minutes as an example against replays, but its example retry schedule runs for more than 75 hours. To stop retries from being processed twice, keep IDs for at least as long as retries can arrive, for example 7 days.
Use both: webhooks for speed, the API for completeness
Reliable integrations usually combine them:
- The webhook says something changed, within seconds.
- The handler optionally calls the API to read the current state, which sidesteps stale or out-of-order payloads. Standard Webhooks discusses both "thin" payloads that carry little more than identifiers and "full" payloads that carry the data.
- A scheduled sweep lists everything changed since the last cursor and repairs whatever was missed.
Sample cost of the safety net for the 120-order shop: 120 webhooks plus one sweep every hour (24 requests) is 144 requests a day. That is a tenth of polling every minute, with delivery in seconds and a missed order repaired within about an hour.
How this looks with TapCub
Take the same paid order, and say you want it counted in analytics. TapCub does not receive your payment provider's webhooks for you; your handler receives them and calls TapCub's server events API.
- Receive and verify the
order.paidwebhook as above. - Forward one event to the server events API with
insert_idset to the order ID andtimeset to when the order was paid. Create the key under Configuration › Settings › API keys and tick the Server track scope, which a new key does not have by default; the request is in send events with the HTTP API. - Let retries be harmless. TapCub drops an event whose
insert_idis already stored with an event time within one day. Atimemore than 72 hours from the server clock is replaced with the current time, so a delivery that arrives days late deserves a check of your own ID table first. What to report from the server is covered in server-side tracking. - Get pushed to, too. TapCub can send monitor alerts to a Webhook notification channel (monitors need Pro or above), and a segment with a webhook configured reports membership changes after a refresh.
- Verify audit pushes with their own rule. The real-time audit log push signs the body with HMAC-SHA256 in an
X-Webhook-Signatureheader. It is not the three-header scheme above, so do not reuse that code unchanged.
FAQ
Is a webhook an API?
It is a way of using one. A webhook is an HTTP request that a provider sends to an endpoint you expose, with a payload format and rules the provider documents. People contrast it with "the API" to mean the request-response calls you make yourself. Most integrations use both.
Are webhooks better than APIs?
Neither is better in general. Webhooks suit infrequent events that need a fast reaction. API calls suit reading history, resyncing, high volumes fetched in batches and environments that cannot accept inbound traffic. Compare events per day with the polls per day your delay target requires.
What happens if a webhook fails?
That depends on the sender. Many retry with increasing delays for hours or days and may disable an endpoint that keeps failing. Some give up quickly. Check the schedule, whether you can replay deliveries by hand and whether the API lets you list events you missed.
How do I secure a webhook endpoint?
Use HTTPS, verify the signature over the raw body with a constant-time comparison, reject old timestamps, record event IDs to block repeats and limit request size. Source IP allow lists can add a layer where the sender publishes fixed addresses, but do not replace signature checks.
Are webhooks real time?
They are near real time when everything is healthy, since the sender posts soon after the event. They can be minutes or hours late during failures because of retry backoff, and they can arrive out of order. Store the event's own timestamp and do not treat arrival time as event time.
Sources
Was this article helpful?
We use your answers to fix and expand this page.
Couldn’t send. Please try again in a minute.
Thanks for the feedback. We’ll use it to improve this page.You’ve already sent feedback on this page. Thanks.

Product Experience Specialist
Explores usability, user journeys, and feature adoption through practical examples of onboarding and everyday product use.



