Skip to content

Instantly share code, notes, and snippets.

@Luke-SNAW
Created December 14, 2021 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Luke-SNAW/20c8b1fea783680df0c70ec1e4637600 to your computer and use it in GitHub Desktop.
Save Luke-SNAW/20c8b1fea783680df0c70ec1e4637600 to your computer and use it in GitHub Desktop.
[Give me /events, not webhooks](https://blog.syncinc.so/events-not-webhooks) #API

bkrausz

I was responsible for Stripe's API abstractions, including webhooks and /events, for a number of years. Some interesting tidbits:

Many large customers eventually had some issue with webhooks that required intervention. Stripe retries webhooks that fail for up to 3 days: I remember $large_customer coming back from a 3 day weekend and discovering that they had pushed bad code and failed to process some webhooks. We'd often get requests to retry all failed webhooks in a time period. The best customers would have infrastructure to do this themselves off of /v1/events, though this was unfortunately rare.

The biggest challenges with webhooks:

  • Delivery: some customer timing out connections for 30s causing the queues to get backed up (Stripe was much smaller back then).

  • Versioning: synchronous API requests can use a version specified in the request, but webhooks, by virtue of rendering the object and showing its changed values (there was a previous_attributes hash), need to be rendered to a specific version. This made upgrading API versions hard for customers.

There was constant discussion about building some non-webhook pathway for events, but they all have challenges and webhooks + /v1/events were both simple enough for smaller customers and workable for larger customers.

throwaway290232

I always laugh when people end up with designs like this. They could have just used SMTP! It's designed to reliably deliver messages to distributed queues using a loosely-coupled interface while still being extensible. It scales to massive amounts of traffic. It's highly failure-resistant and will retry operations in various scenarios. And it's bi-directional. But it's not "cool" technology or "web-based" so developers won't consider it.

Watch me get downvoted like crazy by all Nodejs developers. Even though they could accomplish exactly what they want with much less code and far less complex systems to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment