The right way to do webhooks

Let’s say you just did an integration with a payment provider like Stripe. Part of that flow involves Stripe calling back into your application to let you know that something happened.

This pattern is called a webhook. It allows you to let a 3rd party handle some part of your process and let you know that their part of your process is done.

Let’s say that you’re now providing the webhook as part of your offering. How do you do it?

The naive way is to have your call to your customers’ services contain the payload they need to know about. The thing that you track happens, and so you call them with the details of it.

Why is this naive? What happens if their server is not available? Do you retry? How often? How many times? Can your customers afford to miss your callback?

Moar better: your webhook simply tells them that you have new data available for them. They then call back into you to get that data.

What happens if they’re not available? That’s fine. They already understand that they call into you to get the data, so they’ve already built to be able to check with you for new data. Your outbound webhook is just a performance optimization at that point.

This is how event sourcing works, by the way. Consumers drive the consumption rather than having data pushed to them and for the same reasons.


Like this message? I send out a short email each day to help software development leaders build organizations the deliver value. Join us!


Get the book!

Ready to learn how to build an autonomous, event-sourced microservices-based system? Practical Microservices is the hands-on guidance you've been looking for.

Roll up your sleeves and get ready to build Video Tutorials, the next-gen web-based learning platform. You'll build it as a collection of loosely-coupled autonomous services, developing a message store interface along the way.

When you're done, you'll be ready to contribute to microservices-based projects.

In ebook or in print.