Webhooks are messages one system sends to another the moment something happens, so the receiver never has to keep asking whether anything has changed.
Payment providers and Git hosts use them to tell your code about events as they happen.
Polling: asking again and again
Without webhooks, the usual way to find out about a change in another system is polling: your code asks that system on a timer whether anything is different yet.
import time
while True:
order = shop_api.get_order(42)
if order["status"] == "paid":
break
time.sleep(60)This works, and it is simple. The trouble is that most of those requests come back with 'no'. Every one costs you a network round trip and costs the other side some work, and many APIs limit how many requests you can make, so a busy poller can hit those limits on nothing but empty answers.
Polling also forces a trade-off you can't win. Check every minute and you learn about a payment up to a minute late. Check every second and you find out sooner, but you send sixty times as many wasted requests. Multiply that by every order you are waiting on and the cost adds up quickly.
How a webhook flips it round
Wondering how this was made? How we make these