Why should I use Webhooks instead of Polling?

An API integration aims to efficiently share data between apps to provide greater value to your users. To do that, the integration should offer a way to detect changes in information (any events occurring at the API endpoint). Today the two main event management tools are polling and webhooks, but what are they exactly, and which one of them is better?

Two different concepts.
To know if a friend is sick, you can call him every morning and ask him (polling). Otherwise, you can call his doctor once and ask him to call you back as soon as your friend is sick (webhooks).

Polling
Sending http request at a predetermined frequency to detect changes in data.

Webhooks (also called a web callback or HTTP push API)

Whenever a new event occurs within the endpoint app, it posts the event data to your already specified URL, updating your application in real-time.

Polling vs Webhooks

The main advantage of polling is that you are completely in control of the amount of data you get. But what if you are asking every 10s what the status of your delivery is?

In addition to potentially quickly reach the API rate limit you will most of the time get no changes at all. Multiply this by all the endpoints you need to poll and all the deliveries… you can easily picture the big waste of communication. To better measure the efficiency of the polling method, Zapier conducted an interesting analysis and found that over 98.5% of polls are wasted. In contrast, webhooks only transfer data when there is new data to send, making them 100% efficient. That means that polling creates, on average, 66x more server load than webhooks. That’s a lot of wasted time, and if you’re paying per API call, a whole lot of wasted money.

only about 1,5% of all poll requests are useful

Polling data is always old, it is actually the data that was correct at the time of your last poll. This means that every time an event occurs in the endpoint, your app will be out-of-date until the next poll. If multiple events occur between two of your polls you will miss the data.

With webhooks, events are posted in real-time to your url, your app can then use them to update itself with the new data instantly and you have no risk of missing an event.

Don’t call us, we’ll call you!

Webhooks are developer-friendly. When a group of 150 developers was surveyed, 80% preferred to consume a third-party REST API by being notified of changes via webhooks instead of polling. Polling requires developers to maintain state and infrastructure. Webhooks are much easier to implement and maintain.

However, one of the dangers of using a Webhook is that you may never learn about any changes if the other system that sends updates to your url goes offline at the wrong time for some reason.

Conclusion

  • Webhooks are far more efficient than polling, from a resource and communication standpoint.
  • Polling data is always old whereas webhooks are (almost) real-time data.
  • Webhooks lower the infrastructure costs and are developer-friendly.
1 Like