Frontend Mayhem


April 16, 2018

I want this blog to be a reflection of things I am learning & working on. Recently, I had the opportunity to use webhooks for the first time to set up a “real-time integration” between two applications. This blog post provides a high-level overview of what webhooks are and how they work.

What is a webhook?

A webhook is just an HTTP callback that gets triggered when some event occurs. Webhooks provide a way for an application to send real-time information to other applications. A web app that supports webhooks will POST a message to a URL when something happens.

How do we use webhooks?

To use webhooks, you register a URL with the company providing the service. That URL is where you’ll receive updates in your app & do something with it. This is most often done through an API. It also means that the URL must be accessible from the public web. You could use a service like ngrok during development to expose your localhost to the public web.

In some cases, the service provider will allow you filter the events that you want to receive webhook updates for.

How is it different from polling?

Webhooks allow the consumer to receive information when it happens as opposed to continuously polling for the data & receiving nothing most of the time. They also have the potential to be faster as they eliminate the delay between each polling cycle.

Use cases

Webhooks are a very handy tool is many scenarios. Some of those include:

  • Notifications: Create notifications after you receive webhook updates from another application. Slack integrations anyone?
  • Real-time data syncing: Keep your application’s data in sync with another system by using webhooks.

Watch out!

Keep these few things in mind when creating a webhook consumer:

  • Webhooks have the potential to DDoS your app. If the service provider has a lot of events to notify you about, it will barrage your application with requests. Make sure your application can handle the scale of your webhooks.
  • Develop an understanding of how webhook provider handles errors. Some providers will re-send requests if your application errors out while processing a request, but others might not.

Be the provider

If you want to allow other applications to integrate with your application then webhooks might be the way to go. Implementing basic webhooks is as simple as letting users’ submit a URL & making a POST request to that URL whenever something relevant happens.

Watandeep Sekhon

Written by Watandeep Sekhon.
Website / Twitter / LinkedIn / Instagram