Skip to content
Back to blog

Engineering

Webhooks vs Polling for Reliable Integrations

Reading time
14 min read
Published
Last updated
Webhooks vs Polling for Reliable Integrations

When to use webhooks, polling or both, and how to poll without skipping records. Includes receiver code we wrote for ClinicTek and barmajtek.com that survives duplicates, retries and forged requests.

Use webhooks when you need to know about a change within seconds and the provider sends signed events. Use polling when the provider has no events, or when hearing about a change a few minutes later is fine. When one missed event costs money or a booking, use both. The webhook tells you quickly, and a scheduled poll or reconciliation (a periodic comparison of your records with the provider's) checks that nothing slipped through.

A webhook is an HTTP request the provider sends to your system when something happens. Polling means your system asks the provider, on a schedule, what changed since it last asked.

Webhooks, polling and the hybrid compared

Article data table: Webhooks, polling and the hybrid compared (1)
WebhooksPollingHybrid
How soon you knowUsually secondsAfter the polling intervalSeconds, confirmed later
If your system is down for an hourThe provider retries for as long as it chooses, then gives upYou resume from your saved cursorThe poll recovers what the webhook missed
DuplicatesExpected; processing an event twice must change nothing (idempotent)Expected where windows overlapOne inbox table deduplicates both paths
OrderingUsually not guaranteedYou control read orderDecide from the record's current state
Load on the providerOne request per eventRequests even when nothing changedMore than webhooks alone
What the provider must offerSigned events with stable IDsAn API that can list changesBoth
Best fitFast notice where a rare miss can be caught laterNo events, or periodic freshness is enoughPayments, bookings, anything costly to miss

What providers actually promise

Read each provider's delivery terms before you design anything. Stripe's documentation (checked 4 November 2026) says it retries delivery in live mode for up to three days with exponential backoff. It also says an endpoint might receive the same event more than once, and that events may not arrive in the order they were generated.

Meta retries Graph API webhooks over 36 hours and then drops them. It retries WhatsApp notifications for up to 7 days, and its documentation says duplicates can occur, so deduplication is your job. If your receiver is down longer than the retry window, treat those events as lost. Only a fetch from the provider's API brings the data back. Stripe suggests the same fetch for events that arrive before the objects they depend on.

Ask every provider six questions before you build:

  1. How often does it retry, over what period, and which response counts as success?
  2. How does it sign requests, and is the timestamp part of the signature?
  3. Does every event carry an ID that stays the same across retries?
  4. Is ordering guaranteed, and for which event types?
  5. Can its API list changes since a given time, and what are the rate limits?
  6. Can it resend an old event on request, and how long does it keep events?

When polling is the better primary mechanism

Polling fits providers that do not offer events, sources where periodic freshness is sufficient, or resources that expose a reliable incremental cursor. It can also simplify low-volume integrations where a scheduled fetch has an acceptable cost and clear rate limits. A product catalog imported once an hour is a typical case.

How to poll without skipping or repeating records

A cursor is the value you store to know where the next read starts. It can be the last modified time you processed or the next-page token the provider returns.

  1. Ask only for changes since the saved cursor, and read the results page by page.
  2. Process the whole page, then save the new cursor. Save it first and a crashed worker skips that page for good.
  3. If the cursor is a timestamp, start each read a little before it, because two records can share a timestamp or be written late. Then drop records you've already seen by their IDs.
  4. Use conditional requests where the provider supports them, so it can answer "nothing changed" without sending the data again (RFC 9110).
  5. Respect rate limits. When the provider answers 429 or sends Retry-After, wait as long as it asks.
  6. Run one poller at a time so two workers never read the same cursor. Laravel's scheduler offers withoutOverlapping() and onOneServer() for this.
  7. If the API can't tell you about deletions, add a full comparison on a longer cycle, such as nightly.

Use the hybrid pattern for resilience

Receive webhooks for low-latency change notification, then run a scheduled incremental poll or reconciliation to find missing events and verify final state. The webhook can carry just the record ID, and your system fetches the record itself.

We built ClinicTek's payment-confirmation code this way. ClinicTek is the clinic management system we build and run. This is code in ClinicTek's repository, and we don't say here that any provider connection is switched on for a clinic. A confirmation can arrive by two paths, and both write to the same inbox table, where a unique key on provider and event ID stops any event being stored twice:

  • Webhook: the receiver verifies the signature, stores the event and confirms the payment.
  • Poll: a scheduled command, set to run every minute. For clinics whose payment settings select polling, it asks the provider about payments created in the last 24 hours that are still pending or were cancelled. withoutOverlapping() and onOneServer() keep it to one run at a time.

Each answer goes through the same confirmation code the webhook uses, so a payment is applied once however many times it is reported. The command also checks cancelled payments because money can land after the system has cancelled an expired payment request. It asks only about those recent payments, so its request volume falls when there are few of them.

Build a receiver that survives duplicates and retries

Reliable webhooks require a receiver that verifies the sender, accepts duplicate delivery, tolerates out-of-order events, acknowledges quickly, and then processes, observes, and repairs work. No network offers practical exactly-once delivery across two systems, so the design makes at-least-once delivery safe through durable identity and reconciliation.

Verify the raw bytes, in constant time

Many providers sign with an HMAC, a code computed from the request body and a secret both sides share (RFC 2104). Compute it over the raw body before any JSON parsing, because re-encoding can change spacing or key order. Stripe warns that any change to the raw body makes verification fail. Compare with a constant-time function such as PHP's hash_equals, so response timing can't leak the right value.

Meta's webhook documentation says it signs payloads in the X-Hub-Signature-256 header, with a value that starts with sha256=. ClinicTek checks WhatsApp notifications this way.

In Laravel, getContent() returns the body exactly as it arrived. Nothing reads the payload until this check passes.

Reject old requests

A signed request stays valid if someone captures it and sends it again later. Many providers stop that by signing a timestamp too, and your receiver rejects anything older than a set window. Stripe's libraries default to five minutes, and Stripe recommends keeping your server clock in sync with NTP.

We wrote a receiver for barmajtek.com's email-delivery events from Resend. Resend uses the Svix scheme (its headers are svix-id, svix-timestamp and svix-signature), an HMAC over the message ID, timestamp and raw body joined with dots. The header can carry several signatures, and the code accepts the request if any of them matches.

Several signatures matter during a key rotation. Stripe, for example, lets you keep the old secret active for up to 24 hours after you roll it. In that window it sends one signature per active secret, so events signed with either secret verify.

Some providers don't sign at all. The same code checks a fixed bearer token for Brevo, and HTTP basic-auth credentials plus a secret path token for Mailjet, each with hash_equals. That proves the sender knows the secret but can't detect a changed body. Accept HTTPS only, keep the URL private, and allow only the provider's published IP ranges if it has them.

Store every event in an inbox with a unique key

An inbox is a table that records every event before processing, with a database constraint that refuses the same event twice. ClinicTek's payment inbox works this way.

The key pairs provider and event ID because two providers can issue the same ID. A PostgreSQL check limits the status to four values:

Article data table: Store every event in an inbox with a unique key (2)
StatusMeaning
receivedStored, not yet processed
processedEffect applied; any later copy gets a success response and no new effect
ignoredSignature valid but no payment matches; waits for manual reconciliation
failedSignature or processing failed; the reason is in error

Keep that constraint in the database.

When a provider sends no event ID, derive one from stable fields. Brevo events carry none, so our email receiver builds the key from the message ID, event type, event time and a SHA-256 hash of the body. A random ID would be new on every retry and walk straight past the unique key.

Don't let a forged request claim a real event ID

ClinicTek stores an event before checking its signature, so every failed attempt leaves a trace. That order opens a gap. An attacker could send a badly signed request carrying a real event ID and a different amount before the genuine one arrives. Three rules close it:

  1. A request with a bad signature is stored as failed with signature_valid false, and no payment changes.
  2. When the genuine request arrives with the same ID and a valid signature, the code replaces the stored payload with the verified one, then processes it.
  3. Manual replay accepts only events whose stored signature is valid.

A test sends the event ID with an amount of 999 and a wrong signature, then the real event for 25, correctly signed. It checks that the payment is confirmed at 25 and that the inbox holds one row for the event.

Make the business effect idempotent

Inbox deduplication alone isn't enough. A worker can apply the effect and crash before marking the event processed, so the provider sends it again. A provider can also send two events with different IDs for the same transfer, and both pass the unique key. ClinicTek locks the payment row and stops if it's already confirmed.

Two race tests cover this. In one, two event IDs for the same transfer record the money once. In the other, a burst of webhooks with 20% duplicates still confirms each payment once.

When an effect leaves your system, such as a message or a refund request, pass an idempotency key if the other side supports one. Its server then returns the first result instead of repeating the effect. If it doesn't, write the request to an outbox table in the same transaction that changed your data. A separate worker then sends it and marks it sent.

Acknowledge fast, queue slow work

Stripe recommends returning a 2xx before any complex logic that could time out, and processing events from a queue so a burst can't overwhelm you. ClinicTek's code follows that for WhatsApp and makes one exception for payments:

  • An inbound WhatsApp message may trigger an automated reply and other services, so the receiver stores it and dispatches a queued job with afterCommit. The job never starts before the record is saved.
  • Confirming a payment is one short database transaction, so it runs inside the request. If it fails, the receiver returns 500 and marks the event failed, and the provider retries.

If the work calls another service or could outlast the provider's timeout, queue it. Never return success before the event is stored, because the provider stops retrying once you do.

Resolve the tenant from verified data

If your system serves several customers (tenants), never take the tenant from a field any sender can write. ClinicTek finds the clinic for a WhatsApp notification from Meta's phone-number ID, after the signature check.

For a payment, it uses the provider's payment reference when that matches exactly one payment. If no payment matches the reference, it uses the invoice token the notification carries. If the reference matches several payments, nothing is matched and the event waits for manual reconciliation. The clinic ID then travels explicitly into processing. Our multi-tenant authorization test guide shows how to test that boundary.

Handle events that arrive out of order

A later event can arrive before an earlier one. Stripe's documentation says that if invoice.paid arrives first, you should fetch the invoice, charge and subscription from the API. A failure can also arrive after a success. Decide from the record's current state, because arrival time says nothing about when an event happened, and fetch anything missing from the provider's API.

In ClinicTek a failure notice changes only a payment that is still pending. When a success arrives after the invoice was settled another way, the code records an exception for review and leaves the invoice unchanged. In our email receiver, a hard bounce stays final even when earlier-stage events such as "delivered" arrive after it.

Choose each response code on purpose

The provider retries whenever it doesn't get a success response, so your status code is your retry decision. ClinicTek's payment receiver answers like this:

Article data table: Choose each response code on purpose (3)
CaseResponseInbox statusWhat happens next
Unknown provider404Not storedNothing
Bad signature400failedLogged for suspicious-traffic monitoring
Already processed200stays processedNo new effect
Valid signature, no matching payment200ignoredWaits for manual reconciliation
Error while processing500failedProvider retries; can also be replayed by hand

Inside your own system, cap retries and space them out with exponential backoff plus a little random jitter, so failed jobs don't all retry at the same instant. Laravel's queue documentation covers retry counts and backoff. Move anything that exhausts its retries to a visible review list.

Replay from a controlled screen

Never fix a failed event by editing the database or pasting its payload into the endpoint. ClinicTek's super-admin panel lists inbound payment events with their time, type, clinic and signature result. Its Reprocess action works like this:

  1. It appears only for events with a valid stored signature and status failed or ignored.
  2. Only super-admins can run it, and it asks for confirmation.
  3. The code locks the event row, checks both conditions again, then sends the event through the same confirmation path a webhook uses.
  4. If processing fails, every payment change rolls back and the failure is recorded. A processed event is never downgraded to failed.

We hardened this path on 17 August 2026 with a row lock, super-admin-only access, a check of the stored signature and a rollback on failure. We also added a test that runs two replays of the same event at once and checks that only one applies.

Test the sequences that break receivers

Sign test requests yourself and send the exact raw body you signed. Helpers that turn an array into JSON can produce different bytes from the ones you signed.

Then cover these cases. ClinicTek has tests for the first seven:

  1. The same event twice: one effect, and the second response says it was already processed.
  2. Two event IDs for the same transfer: one effect.
  3. A bad signature: 400, and the payment is unchanged.
  4. A forged request that beats the genuine one with the same ID: the genuine amount is applied.
  5. A burst of webhooks with some duplicates: every effect happens once.
  6. A success after the invoice was paid another way: an exception for review, and the invoice is unchanged.
  7. Two simultaneous manual replays of one event: one runs.
  8. A request older than the tolerance window: rejected with 401.
  9. A key rotation: requests are accepted under either signature during the overlap.

For polling, add a restart from a saved cursor, two records sharing a timestamp, a failure halfway through a page, a deleted record and a 429 response.

Monitor what each event changed

A dashboard can show nothing but 200 responses while no payment gets confirmed. Track events by status, the age of the oldest received event, ignored events waiting for reconciliation, and signature failures per provider. ClinicTek records the outcome of each notification it can tie to a clinic, and super-admins see it on an integration health page. Our guide to automated customer notifications shows how internal events feed outgoing messages without tying business logic to one channel.

Planning an integration with an outside provider?

Send us the provider's documentation and what must happen in your system when an event is late or repeated, and we'll propose the right approach for each integration. Start with a project brief, read about our integration engineering service, or message us with the WhatsApp button on this page.

Frequently asked questions

Do not depend on it. Accept duplicates through stable event identity, a unique inbox, and idempotent business processing.

Sources

#Architecture

Read our editorial policy

Building a custom system for your business?

After “Webhooks vs Polling for Reliable Integrations”: tell us scope, users, and integrations — we reply with a practical plan after reviewing your request.