'Stripe webhook best practice
After we receive the webhook, we should return 2xx response, prior of doing some additional logic in our backend.
Your endpoint must quickly return a successful status code (2xx) prior to any complex logic that could cause a timeout. For example, you must return a 200 response before updating a customer’s invoice as paid in your accounting system.
They suggest here to first return successful 2xx response, and then to do additional things in our backend. They consider this as best practice so there won't be a request timeout.
I don't see how is this best practice, since there is an obvious possibility were our system fails in updating the database for example, and we already returned successful response. That means that Stripe will not try to re-send the webhook later, and we will lose this information since our system didn't save it.
Are there an existing solution for this sort of problem?
Solution 1:[1]
I contacted Stripe Support and they said that timeout for the webhook request is 20 seconds.
The default timeout is 20 seconds. To determine if it's a complex query you would want to evaluate how long would writing to your DB take.
I couldn't find this information in the docs, so it's really helpful. 20 seconds is more than enough to save something to the database and return 2xx response.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
