
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.
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 examplehttps://xyz.com/payment-done). When the payment settles, the payment provider sends an HTTP request to that URL.

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 exampleX-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:
- 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:- GitHub triggers CI/CD with webhooks: https://docs.github.com/en/developers/webhooks-and-events/webhooks
- Slack uses webhooks to post messages into channels: https://api.slack.com/messaging/webhooks