We integrate external systems using different APIs in Salesforce. REST and Bulk API are quite popular to integrate two or more systems. Sometimes we need to update the target system after a few intervals or after some action is performed on the source system. In that kind of situation, we use Pooling or Webhook. This post will explain about the difference between WebHook and API Polling
API polling is a mechanism for an API client to repeatedly call the server to check for changes in data. This will consume so many resources to repeatedly call the server.
A webhook is a reverse API or server-to-client push notification. The server sends a notification that data is updated/added to the server.
Difference between WebHook and API Polling
|Communication Model||Polling is Pull model of communication where a system pulls information from another system.||Webhooks use the push model by pushing information from a source application to a destination application|
|Request Origin||Polling requests are made by a client. Polling is set up to run at fixed intervals and runs whether there is a new event or not.||Webhook requests are made by a server. Webhooks are also automatically triggered when an event occurs.|
|Resource Efficiency||Polling can be resource-intensive and we need to make calls on whether the efforts will be fruitful or not.||Webhook requests are only made when there is new information.|
|Real-Time Updates||With polling, there will always be an interval between requests that creates a delay in receiving an update||Webhook is made by the server on a real-time basis. No delay in notification.|
When to use polling
We should only use polling when updates are very frequent and no real-time updates are required. This could be a good fit in a situation where you need to pull information from social media activities. As these activities are very frequent, polling will be a good fit in this use case.
When to use webhooks
If we need updated data in real time and updates are not very frequent, webhooks are the perfect solution.