What are webhooks and how they work?
What are webhooks?
Imagine having a mailbox at home. This mailbox is a place where one receive letters and packages, but it’s not known when something will arrive. So, one have to keep checking the mailbox periodically to see if there’s anything new. This is similar to how traditional web applications work; they have to keep asking other systems (like checking the mailbox) if there’s new data or updates.
Now, imagine instead of checking your mailbox all the time, the post office calls every time they deliver something to your mailbox. This call is an alert that there is something new. This is essentially what webhooks do.
In the digital world, a webhook is like getting a phone call from the post office. It’s a way for an app or a website to get real-time information. Instead of the app having to check repeatedly with the server if there’s new data (like checking the mailbox), the server will send a message to the app (like the post office calling you) as soon as there’s new data available. This makes the process more efficient and timely.
Coming to a more technical description, a webhook is a type of HTTP request that is automatically initiated by an event in a source system and directed towards a destination system, usually carrying a data payload. These webhooks operate autonomously, meaning they are sent automatically whenever their corresponding event is activated in the source system.
Essentially, this mechanism allows one system (the source) to communicate (through an HTTP request) with another system (the destination) as soon as an event takes place, and to convey details (via the request payload) about the event that transpired.
How webhooks work?
The receiver of information i.e. webhook consumer has to expose an API endpoint (or URL) to which the sender of information can send HTTP requests. The body of the request is usually in JSON format. The receiver is supposed to return a 2XX status code if the information was processed successfully or 5XX status code if the information wasn’t processed correctly.
While it’s preferable to send webhooks as POST HTTP requests, there have been instances of having other HTTP methods as well.
Where are webhooks used?
- Payment Gateways: They inform about transaction updates such as successful payments, failed transactions, or refunds. For instance, when a customer makes a payment, stripe uses webhooks to notify the merchant’s system about the successful transaction.
- Customer Relationship Management (CRM) Systems: To update customer data in real-time. If a customer updates their contact information, salesforce webhooks can ensure this change is reflected across all integrated platforms.
- CI/CD Pipelines: github webhooks are used to trigger builds, tests, or deployment processes in response to code commits or other changes in a version control system like.
- Healthcare Systems: For updating patient records, appointment schedules, or sending alerts for critical test results.
- Ecommerce platforms: shopify webhooks are used in e-commerce to update order status, notify about new orders, or synchronize inventory across platforms. For example, when a new order is placed on an online store, a webhook can automatically inform a warehouse management system to initiate the shipping process like.