TapCub is live — analytics, insights and live chat, free on one platform
Analytics

Webhook vs API: push or polling with the request math

A webhook pushes when something happens; an API is polled. Request counts for 120 and 50,000 events a day, what a four-hour outage does to retries, signature checks and idempotency.

Oliver Reed Published Dec 3, 2026 14 min read Analytics
Sample data: one consumer, 120 paid orders a day. The hourly sweep adds 24 requests as a safety net for missed deliveries.Sample data

A 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.

QuestionPolling an APIReceiving a webhook
Who starts the requestYouThe other system
When data arrivesOn your next pollShortly after the event
Requests when nothing happensOne per intervalNone
What you must runA scheduler and a cursorA public HTTPS endpoint
If your side is downYou poll again later and catch upThe sender must retry, or the event is lost
What you must verifyThe server's TLS certificateThe sender's signature
Can you ask for historyYes, if the API supports itNo, 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:

  1. It sends GET /orders?status=paid&updated_after=<last cursor>.
  2. The shop returns the new orders, often an empty list.
  3. 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:

  1. The fulfilment system registers https://fulfil.example.com/hooks/orders once.
  2. The shop sends a POST with the order event to that URL.
  3. The receiver replies with a 2xx status to say it has the message.
  4. 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.

MethodRequests per dayPolls that return nothing (at least)Average delayLongest delay
Poll every 10 s8,6408,520 (98.6%)5 s10 s
Poll every 60 s1,4401,320 (91.7%)30 s60 s
Poll every 5 min288168 (58.3%)2.5 min5 min
Poll every 15 min960 or more7.5 min15 min
Webhook, one per order120 plus retries0delivery timelonger 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.

app.tapcub.com

Requests per day to learn about 120 orders

requests
Poll every 10 seconds8,640
Poll every 60 seconds1,440
Poll every 5 minutes288
Webhook plus hourly sweep144
Webhook only (before retries)120
Sample data
Sample data: one consumer, 120 paid orders a day. The hourly sweep adds 24 requests as a safety net for missed deliveries.

When 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 youBetter fitWhy
Rare events, fast reaction neededWebhookNo wasted requests, short delay
Very high event volume, a minute of delay is finePolling with pages, or a queueBatches beat one request per event
You cannot expose a public endpointPollingOutbound calls only
You need history or a full resyncAPIWebhooks only deliver from now on
The provider offers no webhookPollingNo choice; use a cursor, not "fetch everything"
Losing a single event is unacceptableWebhook plus periodic API sweepEach 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.

PointAPI pollingWebhook
DirectionYou pullThey push
DelayUp to one intervalDelivery time, longer on failure
Cost when idleOne request per intervalNothing
Recovery after downtimeRead from your cursorDepends on sender retries
Security workProtect your credentialVerify signature and block replays
History and resyncAvailable if the API offers itNot 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:

AttemptWait before itTime since the first attempt
1none00:00:00
25 seconds00:00:05
35 minutes00:05:05
430 minutes00:35:05
52 hours02:35:05
65 hours07:35:05
710 hours17:35:05
814 hours31:35:05
920 hours51:35:05
1024 hours75:35:05

Now apply it to an outage. Your receiver is down for 4 hours.

Event createdOutage time leftDelivered on attemptArrives at (hours since outage began)
At the start4 h 00 min607:35:05
3 h in1 h 00 min505:35:05
3 h 50 min in10 min404: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:

  1. 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.
  2. Check the timestamp. It limits how long a captured request can be replayed. The 300 seconds above is a sample tolerance.
  3. Compare in constant time, as compare_digest does.
  4. 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:

  1. Verify the signature.
  2. Insert the ID into a table with a unique constraint.
  3. If the insert fails, you have seen it: return 2xx and stop.
  4. Otherwise put the work on a queue, then return 2xx.
  5. 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.

  1. Receive and verify the order.paid webhook as above.
  2. Forward one event to the server events API with insert_id set to the order ID and time set 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.
  3. Let retries be harmless. TapCub drops an event whose insert_id is already stored with an event time within one day. A time more 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.
  4. 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.
  5. Verify audit pushes with their own rule. The real-time audit log push signs the body with HMAC-SHA256 in an X-Webhook-Signature header. 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

Filed underAnalytics

Was this article helpful?

We use your answers to fix and expand this page.

Oliver Reed

Product Experience Specialist

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

Count server events once, even when deliveries repeat

Send orders and sign-ups from your server with a stable insert_id and see them next to your website data.

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics