WebHooks
Webhooks are a powerful way to enable real-time communication between systems.
They allow one system to send automated notifications or data updates to another system when certain events occur, without the need for the receiving system to continually check (constant polling) for updates.
Also known as reverse APIs or push APIs because the server sends HTTP requests to the client
- Custom HTTP Callbacks triggered by specific events
- eliminated the need of polling
Pay attention to 3 things when using a webhook:
- design a proper API for the external service to call.
- set up proper rules in the API gateway for security reasons.
- register the correct URL at the external service.
https://github.com/ByteByteGoHq/system-design-101?tab=readme-ov-file#what-is-a-webhook
WebHooks in payment Services
The payment service -> external payment service provider (PSP)
- Short polling
- keeps asking the PSP about the payment status.
Drawbacks
- Constant polling requires resources from the payment service.
- The External service communicates directly with the payment service, creating security vulnerabilities.
- Webhook
Register a webhook with the external service.
- calls back at a certain URL when there is an updates on the request.
- the PSP invoke the HTTP request to update the payment status (upon successful completion).
- if the PSP never calls back, then a fallback polling mechanism can be used