Skip to main content
How can one application learn about events that happen inside another application as soon as they occur? A common scenario is handling a payment: you pay via a payment provider (for example Stripe) and your application needs to know the moment that payment is confirmed. There are two main approaches to solve this: polling and webhooks.
The image illustrates a concept of communication between two applications: "Your App" and a "Payment Co." app, questioning how one app finds out about actions in the other.

Polling: the obvious but inefficient approach

With polling, your app repeatedly asks the other service, “Has the payment completed yet?” at a fixed interval (every few seconds or minutes). This works, but it wastes bandwidth and server resources and introduces latency between the actual event and when your app learns about it.
The image illustrates a polling process between "Your App" and a "Payment Co." system, questioning whether a payment is completed.

Webhooks: flip the direction of communication

A webhook reverses the flow: instead of your app asking, the other service calls your application when the event happens. You give the external service a publicly reachable callback URL on your server (for example https://xyz.com/payment-done). When the payment settles, the payment provider sends an HTTP request to that URL.
The image illustrates a webhook connection between "Your App" and "Payment Co," with the text, "They call you the moment it happens."
A webhook is a standard HTTP request. Typical payload example:
Your endpoint should acknowledge the delivery quickly by returning an HTTP 200 OK (or another success status depending on the provider):
Most webhook providers implement retry policies: if your server is down or returns an error, they will retry delivery a number of times. Retry specifics vary by provider, so review the provider documentation.
Your webhook endpoint must be reachable from the public internet. During development you can expose a local server using a tunneling tool (for example, ngrok) so the provider can reach your callback URL.

Securing webhooks

Because the endpoint is public, anyone can try to send forged requests. Providers mitigate this by signing webhook requests using a shared secret. Your server should verify the signature before processing the payload. A common pattern is an HMAC signature included in a header (for example X-Webhook-Signature), computed over the raw request body using a shared secret and a secure hash function (such as SHA-256). Example verification in Python:
Additional security best practices:
  • Only accept requests over HTTPS.
  • Validate the payload schema and required fields before processing.
  • Log received events and verification outcomes for auditing and debugging.
  • Optionally implement IP allowlisting if the provider publishes their sending IP ranges.

Polling vs Webhooks — quick comparison

Examples and references

Popular services that use webhooks: When designing integrations, choose webhooks for near-instant notifications and efficiency, and reserve polling only for simple or constrained scenarios.

Watch Video