top of page

Webhooks

Architectural Style & Patterns: Webhooks are a pattern for server-to-server callbacks over HTTP. In essence, a webhook occurs when one application sends an HTTP request to another application when a specific event happens. Unlike an API where a client polls for data, webhooks are event-driven push: the source system (publisher) pushes data to a URL (subscriber) provided by the target system. Webhooks typically use HTTP POST requests with a JSON (or XML or form-encoded) payload describing the event. They are not a formal protocol, but a convention that has become extremely popular for integrating web services. Webhooks support an event-driven architecture at the application integration level – they decouple the producer and consumer in time (the consumer just exposes an HTTP endpoint and waits). Many SaaS and cloud services provide webhooks so that external systems can get real-time notifications (e.g., GitHub sending a webhook when a repo is pushed, Stripe sending a webhook when a payment succeeds, Slack sending a webhook when a message is posted to a channel, etc.). In a micro-services context, webhooks can be used as well for internal events, but often message queues are preferred internally; webhooks shine for cross-organisational or cross-product integration using HTTP. They naturally fit a pub-sub model: the publisher service might allow registration of multiple webhook endpoints (subscribers) for certain events. Architecturally, webhooks are simple: any web server or serverless function can receive them; they rely on the ubiquity of HTTP. A 2023 survey found that about 36% of developers use webhooks to integrate systems, reflecting their importance in modern API ecosystems (likely even higher now, given their prevalence in SaaS configurations). Webhooks don’t require a persistent connection (each event is a separate HTTP call), which makes them cost-effective for the publisher (no need to maintain thousands of open sockets like with WebSockets). They enable event-driven integration without a full-blown message broker, leveraging the internet as the medium.



 Webhooks-based architecture showing a triggering system (e.g., payment gateway) sending an HTTP POST to a listener URL on another application. The image highlights event-driven communication with arrows representing real-time, one-way notifications between systems.

Strengths and Use Cases: Webhooks are popular because they offer a simple yet powerful way to glue systems together:


  • Near Real-Time Communication - Webhooks eliminate the need for polling. Instead of one system constantly asking another “Has X happened yet?”, the second system just tells the first when X happens. This leads to faster interactions and less wasted effort. For example, instead of a client polling a payment API every minute to see if a transaction went through, the payment API just sends a webhook the moment the transaction status is known – the client gets it within seconds. This is great for real-time integration of services (receiving instant notifications of events).


  • Efficiency and Simplicity - Webhooks use HTTP which almost every technology platform can send and receive. No specialised libraries or protocols are needed beyond the ability to make an HTTP request. Consuming a webhook is often as easy as creating an HTTP endpoint in your app that handles a POST. This means low barrier to entry – developers can set them up quickly. They also reduce load: instead of continuous polling calls that mostly return no new data, you make calls only when necessary. This efficiency is both on the provider (less traffic) and consumer side (less processing).


  • Decoupling and Event-Driven Style - A service that emits webhooks doesn’t need to know much about the receiver aside from the URL and maybe a token. This is a form of decoupling – the services are integrated by events, not by direct APIs or database sharing. If one service goes down, as long as it can catch up on missed webhooks (or the events weren’t critical), the systems remain decoupled. Webhooks help bring an event-driven approach to web services without needing message brokers: e.g., one SaaS can integrate with another by each offering webhook endpoints to catch events from the other.


  • Great for SaaS and Third-Party Integrations - Practically every major SaaS provides webhooks because it’s the easiest way for external developers to integrate. Use cases:

    • E-commerce - a store system sends a webhook to inventory and shipping services when an order is placed.

    • CI/CD - GitHub sends webhooks to Jenkins or other CI servers to trigger builds on code push.

    • Payments - Stripe or PayPal send webhooks to your app when a payment is completed, so you can update order status.

    • Messaging/Communication - Twilio sends webhooks for incoming SMS or call events to your app, Slack sends webhooks for new messages if you set up a Slack app, etc.

    • Essentially, any service that provides data that others might want to act on in real-time likely offers webhooks (if not more complex streaming APIs).


  • Flexible and Customisable - Typically, you can configure exactly which events you want webhooks for and where to send them. This selective subscription is useful to reduce noise. Also, you can often include custom payload data. Many webhook providers allow setting secret tokens so the receiver can verify the source (via signature or shared secret). Though not a protocol, common practices have evolved (like including an HMAC signature in headers) to enhance security.


  • Leverages Existing Security and Scale - Webhooks piggyback on HTTP, so you can use HTTPS for encryption and authentication (like basic auth, tokens in headers, etc.). Also, if you host your webhook endpoint on a scalable web service, you can leverage that platform’s scaling. For example, if you host on a cloud function or a load-balanced service, it can scale out to handle bursts of webhook traffic (say, if many events happen at once). This avoids needing persistent connections or specialised infra on the consumer side; just handle web requests which is a solved scaling problem.


  • Human-Visible Failures - If a webhook fails (server returns non-2xx), providers often log it or even show it in dashboards, and many will retry a few times. This makes debugging easier: you can often find webhook delivery logs in the provider’s admin interface. Developers appreciate this transparency when integrating because you can see if your endpoint is not working or responding slowly.



Weaknesses and Limitations: While useful, webhooks come with their own challenges:


  • Reliability and Delivery Guarantees - Webhooks are typically fire-and-forget from the sender’s perspective. They make an HTTP request; if it fails, they might retry a few times, but after some attempts they usually give up. If your endpoint was down for a period, you might miss events. It’s on the consumer to realize this gap and maybe manually recover if possible. Unlike a message queue which would hold messages until the consumer is up, webhooks don’t have a built-in persistence (unless the provider specifically stores and retries for an extended period, which some do but not indefinitely). This means critical events via webhook might need additional safety nets (some APIs allow querying missed events or you might periodically poll as backup). The consumer must implement robust handling – e.g., idempotency (so if a webhook is delivered twice due to retry, it doesn’t double-process) and a strategy if a notification is missed.


  • Security Concerns - By exposing a webhook endpoint, you are basically opening an API on your system that others (the provider) will call. This must be secured. Common practice is using secret tokens or signatures to ensure authenticity of the call. If not done, a malicious party could spoof events. Also, your endpoint becomes a potential target for abuse – if the secret leaks, someone could spam your system with fake events. Handling incoming requests safely (validate payloads, authentication, rate limiting) is crucial. Webhooks also traverse the open internet, so securing via HTTPS is a must to prevent snooping or tampering. There have been cases of misconfigured webhooks causing data leaks (e.g., sending sensitive data to the wrong URL).


  • Consumer Management Complexity - If you (as a provider) offer webhooks to many customers, managing those endpoints (subscriptions) can be complex. What if a customer’s endpoint is slow or always failing? You might need to disable it. Or if they change their URL, you need a mechanism to update. Some providers implement handshake protocols (like verifying the endpoint by a challenge request when setting up). There’s no universal standard, so each API has slightly different ways to subscribe/unsubscribe and verify. Monitoring the health of all outgoing webhook deliveries can become a task – e.g., you don’t want a buggy client to cause your system to hang (if you wait too long on their response).


  • Scalability on Receiver End - If you subscribe to a high-volume webhook (imagine receiving a webhook for every tweet containing your hashtag – that could be huge), your server must handle potentially bursty loads of HTTP calls. If an event producer has a surge of events, they may send a surge of webhooks. This can overwhelm poorly scaled endpoints. Contrast this with pulling from a queue, where you can control the rate. Receivers should ideally be stateless and scalable services to handle unpredictable event rates. Using cloud functions or auto-scaling can mitigate this, but it’s a consideration.


  • Lack of Standardisation - Webhooks as a concept are standard, but each implementation might differ (different payload structure, headers, retry policy, security scheme). Developers have to consult documentation for each service’s webhook format. There’s no single protocol like SOAP or something that standardizes it. This is a minor issue, but integration involves some custom code per provider. There are efforts like the W3C WebSub (formerly PubSubHubbub) that tried to standardize webhooks for content feeds, but not widely used beyond specific domains.


  • Visibility and Testing - When developing, testing webhooks is a bit tricky because your local dev environment needs to receive an external HTTP call. Developers often use tools like Ngrok to tunnel or have to deploy to a test server. It’s not insurmountable, but unlike calling an API (which you can do from Postman easily), simulating a webhook requires either waiting for the real system to call you or crafting a test request that mimics it. Debugging can thus be a bit more involved.


  • One-Way Notification - Webhooks typically do not expect a complex response. The receiver usually just responds with 200 OK to acknowledge. There isn’t a conversation; if the receiver needs data from the sender beyond what’s in the webhook, it has to make an API call back (like “you told me order ID 123 updated, let me call your API to get full details”). This is by design (webhooks keep it minimal), but means sometimes you get an event but still have to follow up with a fetch for the whole context.


Common scenarios for when not to use webhooks - If you need guaranteed processing of every event or the ability to replay events, a message queue or event log is better. If the receiving end is a client app (like a mobile app), webhooks won’t go directly (you’d need a server in between). Also, internal low-latency communication between micro-services might better use a dedicated queue or gRPC – webhooks have the overhead of full HTTP and Internet transit.


In conclusion, webhooks are best for integrating different systems or services in a decoupled, event-driven way using the simplicity of HTTP. They empower a lot of the modern SaaS “glue” – allowing services to talk to each other without tight coupling. A product manager or architect would see webhooks as a quick win to connect systems: e.g., “When our CRM records a new lead, post a webhook to our internal analytics app so it can update the lead score in real time.” Many enterprise workflows are implemented exactly with such webhooks connecting out-of-the-box cloud services with in-house apps. Their popularity (over a third of developers use them, and likely more in certain domains) shows that despite being simple, they fulfill a fundamental need for event notifications between disparate systems.


Main Blog:

Comments


bottom of page