How Webhooks Work: How Apps Tell Each Other the News

Diagram of a webhook: a service sends an HTTP POST with JSON event details to an app's endpoint URL when an event happens

A webhook is an automatic message that one app sends to another the moment something happens. Understanding how webhooks work explains a lot of everyday software, like how a shop knows a payment went through without anyone refreshing a page.

This guide walks through the idea from the ground up. You'll see why webhooks exist, what happens inside each delivery, where they show up in tools you already use, and the three mistakes that catch most beginners when they build a receiver.

In short
  • A webhook is an automatic, event-driven message from one app to another.
  • It replaces polling, where your app keeps asking whether anything has changed.
  • You register a URL once; after that, each event arrives as an HTTP POST with JSON details.
  • A good receiver verifies the signature, replies fast, then does the slower work.
  • Senders retry when they don't hear back, so your handler must be safe to run twice.
  1. 0:00Intro
  2. 0:37Checking the mailbox every minute
  3. 1:31So what is a webhook?
  4. 2:28Polling versus webhooks
  5. 3:20Polling wastes time and resources
  6. 4:05Give the service your URL
  7. 4:58An event happens
  8. 5:50The service sends an HTTP POST
  9. 6:48The full journey of a webhook
  10. 7:41Walking through an online order
  11. 8:41Webhooks are everywhere
  12. 9:46What a good receiver does
  13. 10:49Three mistakes beginners make
  14. 11:54Why the same event arrives twice
  15. 12:48Webhooks in five points
  16. 13:21Apps should tell, not keep asking

Why constantly checking for updates is a problem

Imagine you're waiting for an important letter, and the only way to know whether it arrived is to walk outside and check the mailbox. Now imagine doing that every minute, all day. Almost every trip ends with an empty box, but you keep going in case this is the time it's there.

This mailbox habit has two problems. First, nearly all of the effort is wasted, because most checks find nothing new. Second, it isn't even fast: if the letter lands just after you look, you won't find out until your next trip outside.

Now picture the mail carrier ringing your doorbell when the letter arrives. You get on with your day and hear the news the instant it happens. That doorbell is the idea behind webhooks, and it's worth keeping in mind for the rest of this article.

  • The mailbox way: you keep checking, and almost every check finds nothing.
  • The doorbell way: you're told the moment something arrives.

What is a webhook?

A webhook is an automatic message that one app sends to another when something happens. Two words in that definition matter. "Automatic" means no person has to click anything. "When something happens" means the message is driven by events, not by a timer that fires on a schedule.

Every webhook involves two roles. The sender is the service where the event actually takes place and the one that has the news first. A payment provider is a sender when a customer pays, and GitHub is a sender when someone pushes code.

The receiver is your app, sitting at a web address and waiting. It doesn't go looking for news. It simply listens, and when a message lands, it reacts. So a webhook is the sender ringing the receiver's doorbell.

  • Sender: the service where the event happens, such as a payment provider or GitHub.
  • Receiver: your app, waiting at a web address to be told the news.

Polling vs webhooks: what's the difference?

Before webhooks, the usual approach was polling, which is the mailbox habit done by software. Your app repeatedly asks another service whether anything has changed. Webhooks flip that around: the service tells your app only when something really did change.

The cost of polling adds up quickly. Say your app asks a payment service once a minute whether a customer has paid. There are 1,440 minutes in a day, so that's 1,440 requests a day, from one app, about one thing. If the customer pays once, nearly all of those requests were wasted.

Polling is also slow. If the payment lands a second after a check, you wait almost a full minute to notice. Polling more often shortens the delay but multiplies the waste. That trade-off is exactly the trap webhooks were designed to escape.

  • Who starts: with polling your app keeps asking; with webhooks the service tells you.
  • Timing: polled news is only as fresh as your last check; webhooks arrive right away.
  • Wasted work: most polls find nothing; webhooks are only sent when needed.
  • Your setup: instead of a loop calling out, you need a URL that listens.

Step 1: Register your webhook URL (the endpoint)

Webhooks work in three steps, and the first happens only once, at setup. You tell the service where to send its news. It's like giving the mail carrier your address and saying, ring this doorbell. In webhook terms, that address is a URL on your own server.

For example, you might create a URL such as myshop.com/webhooks/payments and paste it into the service's settings page. Usually you also choose which events you care about, like "payment completed", so you only hear about things that matter to you.

This URL is called an endpoint: a specific door on your server set aside for incoming messages, so they don't get mixed up with normal page visits. Once it's registered, you don't need to touch it again. Messages start arriving on their own.

# A URL on your server, e.g.
https://myshop.com/webhooks/payments
# Pasted into the service's settings
# Events: payment completed

Steps 2 and 3: An event triggers an HTTP POST

Step two is the trigger: an event happens inside the service. An event is a record that something changed, such as a customer finishing checkout or a developer pushing code to a GitHub repository. The service watches for the events you chose and ignores everything else. If nothing happens all day, your server hears nothing, and that's fine. Silence simply means no news.

Step three is where the doorbell rings. The service packs up the event details and sends them to your URL as an HTTP POST request. HTTP is the same language your browser uses to load pages, and POST is the kind of request used to deliver data, much like submitting a form.

The body of that request is usually JSON: plain text made of labels and values. In a simplified example, it says which event happened, which order it's about, and the order's new status. JSON is easy for people to read and for almost every programming language to parse.

  • Why POST: the service isn't asking your server for anything; it's handing data over.
  • Why JSON: simple, readable text that nearly every language understands.
POST /webhooks/payments HTTP/1.1
Content-Type: application/json
{ "event": "payment.completed",
  "order": "A102", "status": "paid" }

A webhook example: following one online order

Put the steps together and you get one smooth journey. Setup happens once. After that, every matching event follows the same path: the event happens, the service builds a JSON message, the message travels as an HTTP POST to your URL, and your server reads it and does something useful.

Imagine a small online shop that uses a payment service for card payments. A customer pays for order A102. That creates a "payment completed" event. The service sends a POST to your /webhooks/payments URL, your server sees that order A102 is paid, and the shop sends a confirmation email and passes the order on for shipping.

Without a webhook, the shop would have to keep polling, and the customer might stare at a loading screen wondering whether the money went through. With a webhook, the confirmation arrives moments after paying, and your server only does work when real news arrives. That speed is what makes apps feel live.

  • Event: payment.completed
  • POST sent to: /webhooks/payments
  • Server reads: order A102 = paid
  • Shop reacts: confirmation email and shipping

Where are webhooks used?

Once you know the pattern, you'll notice it everywhere: an event in one app, a message to another app, and an automatic reaction. Only the event changes from one case to the next.

Payment alerts are the classic case. Payment services use webhooks to tell your app when a charge succeeds, fails or gets refunded, so your records match what really happened. GitHub deployments are another: pushing code can send a webhook to a build system that tests your code and deploys it automatically.

Team chat tools use them too. A message popping into a channel to say a new order arrived or a build failed is usually a webhook delivering the news. And form submissions can instantly add a row, send an email or alert a team the moment someone fills them in.

  • Payment alerts
  • GitHub builds and deployments
  • Chat notifications
  • Form submissions

How should a webhook receiver handle messages?

So far the focus has been on the sender, but your server has a job too. Think of each incoming webhook as a parcel arriving at your door. Handling it in a sensible order prevents most problems before they start, and there are four stages.

First, receive it: accept the POST at your endpoint and read the JSON body plus the headers, small labels that travel with the message. Second, verify it. Many services attach a signature made with a secret only you and the service share. Checking it proves the message really came from them, not an impostor.

Third, reply quickly with a success response, usually HTTP status 200, which basically means "got it, thanks". The sender is waiting for that answer. Fourth, do the slower work, such as sending emails and updating records, after you've replied.

  • Receive the POST at your endpoint.
  • Verify the signature.
  • Reply quickly, usually with HTTP 200.
  • Process the slower work afterwards.

Common webhook mistakes (and why events arrive twice)

Mistake one is skipping signature checks. Your endpoint is just a web address, so someone who finds it could send fake payment events. Always verify the signature before trusting anything. Mistake two is responding slowly: if your server does heavy work before replying, the sender may give up and treat the delivery as failed. Reply first, process afterwards.

Mistake three is ignoring duplicates, and it surprises people most. If a sender doesn't get a clear success reply, perhaps because your server was slow or briefly down, it assumes the message was lost and retries later, until it finally hears "got it". Retries are a helpful safety net, but they mean the same event can arrive more than once.

The fix is to make your handler idempotent, a fancy word for safe to repeat. Most events carry a unique ID. When one arrives, check whether you've already handled that ID. If you have, reply with success and skip it. That way an order never ships twice because of a retry.

  • Skipping signature checks lets fake events in.
  • Slow replies can time out and trigger retries.
  • Ignoring duplicates can process the same event twice.
  • Track event IDs so repeats change nothing.

Key takeaways

  • A webhook is an automatic message one app sends another when something happens.
  • Webhooks replace polling, the wasteful habit of asking again and again.
  • You register an endpoint URL once, then events arrive as HTTP POST requests with JSON.
  • On your side: verify signatures, reply fast and process the work afterwards.
  • Expect retries and use event IDs so handling an event twice is safe.

Frequently asked questions

What is the difference between a webhook and polling?

With polling, your app keeps asking another service whether anything has changed, and most of those checks find nothing. With a webhook, the service tells your app only when an event actually happens, so the news arrives right away and no work is wasted.

Why do webhooks use HTTP POST?

The sending service isn't requesting anything from your server; it's delivering event details. POST is the standard web method for handing data over, much like submitting a form.

What is a webhook endpoint?

An endpoint is the URL on your server that you register with a service to receive webhooks. It's a dedicated door for incoming messages, kept separate from normal page visits.

Why did I receive the same webhook twice?

Senders retry when they don't get a clear success reply, for example if your server was slow or briefly down. Track each event's unique ID and skip ones you've already handled so repeats change nothing.

How do I know a webhook really came from the service?

Many services attach a signature created with a secret that only you and the service share. Verifying that signature before trusting the message proves it wasn't sent by an impostor.

Watch the full video on YouTube →

Souy Soeng

Souy Soeng

Hi there 👋, I’m Soeng Souy (StarCode Kh)
-------------------------------------------
🌱 I’m currently creating a sample Laravel and React Vue Livewire
👯 I’m looking to collaborate on open-source PHP & JavaScript projects
💬 Ask me about Laravel, MySQL, or Flutter
⚡ Fun fact: I love turning ☕️ into code!

Post a Comment

CAN FEEDBACK
Ad