Let’s talk about Webhooks (Part 1: The Theory).

Ishmeet Bindra
Oct 27, 2019 · 2 min read

Before we dive into it, let’s just imagine you just gave someone a cheque and you wanna be informed as soon as the money is deducted from your account. Now you can either

  1. Continuously call the bank’s teller, ask about your account balance or whether cheque came in or not.
  2. Wait for a simple message that would inform you about the transaction.

Keeping this in mind let’s discuss webhooks.

Webhooks are special HTTP Callbacks that inform us about any action that has taken place somewhere. These are incredibly useful when we want to get notified about an event, right when it occurs.

Webhooks are also known as Reverse APIs as rather than client applications sending some info to a server (like an API), the server notifies the client application about some action that took place. This greatly reduces the load on the server.

Without webhooks, we need to continuously ping a server to know the status of any transaction. This process is known as Polling.

Fig. 1 — Polling with APIs vs Webhooks

Polling is a resource hoarding process and as the number of devices increase, the server could get extremely cluttered with such requests. This could eventually lead to an increased cost of infrastructure and delays in the request.

Webhooks operate on the concept of ‘Event Reaction’. This means that the client is only informed when an action takes place.

For a webhook to work we need to provide an endpoint URL for Client-Side application to the Server-side application. An endpoint is a URL through which we can get access to the web application. The server consumes this endpoint URL when it needs to notify the client about some action.

While we can send some additional information/payload (eg, JSON data or XML) through webhooks, but its primary goal is to act as a notifier and it is a good practice to limit it to that only. Also, we should have a separate mechanism of receiving a webhook and processing it. For more information on this please refer to this article.


So coming to the scenario discussed above. It is always better to get notified about an event that has happened. You might think what’s the harm in continuously checking the status, but you need to realize that you are not the only device/resource an application is going to serve.

Webhooks allow us to implement better, efficient applications. From getting your Bank transaction’s information to, updating the WhatsApp's delivery status in real-time, every application uses Webhooks in one way or another.

This was Part 1 of the webhook tutorial. In Part 2 we are going to implement Github Webhook with Python. You can find the article here.

Resources:

  1. Webhook guide-https://codeburst.io/what-are-webhooks-b04ec2bf9ca2
  2. APIs vs Webhooks- https://hackernoon.com/webhook-vs-api-whats-the-difference-8d41e6661652
  3. Endpoint- https://study.com/academy/lesson/what-is-web-service-endpoint-definition-concept.html

More From Medium

Also tagged Implementation

Also tagged Implementation

Also tagged Programming

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade