Introduction
As always, I love Blog-Driven Development.
At work, we're implementing webhooks. I asked right away what they were.
Surprisingly to me, it was the first time that I heard it. I decided to write this post to deepen my understanding.
Pre-requisite
I assume you know what APIs are.
Background
Our customers are using our API.
Whenever statuses of data transfers change, they want to be notified.
There are several ways they can go about it.
Polling
One approach our customers could take is to poll.
This means sending a request every X seconds or minutes to our API to receive information on whether a data transfer has been e.g. successfully transferred.
Let's take a look at some pros and cons.
Pros
Simple to implement.
You control when to make requests.
No need to expose any endpoints.
Cons
Not real-time, data could be stale.
Inefficient.
Resource consumption.
Webhooks
The other approach we can take is for our API to inform the customer whenever the status has changed.
This is the webhook approach.
The customer would give us an endpoint we send POST requests to every time the value they're tracking changes. In this case, it would be the data transfer's status.
Let's take a look at some pros and cons.
Pros
Allows for real-time updates.
Data is only sent when there is a change.
Customers don't have to poll.
Cons
Customers rely on us to send the right data.
More complex to implement.
Customers need to provide an endpoint where we send the POST request.
We need to implement the mechanisms.
Conclusion
Well, this was a good example of Blog-Driven Development.
Just write, write and write.
You excel faster than 99% of developers.
Awesome post, BDD strikes again!
Really clearly explained! Here’s a question: Why are they called webhooks? Wouldn’t it be easier to “get” if it was called a “notify endpoint” or “callback endpoint” or some such.