What is the best practice for processing webhooks? What if a webhook fails?
Webhooks are used to immediately notify your integration of events that take place in the Lean ecosystem. They are especially useful for events that take place on your front end through the Lean SDK or events that take place asynchronously, for example updating you about the status of a payment.
Webhooks can be handled by your integration in 2 ways:
Asynchronously (strongly recommended):
Your backend receives Lean webhook call
Acknowledges it by returning 200 OK to the Lean platform
Then executes code that deals with the webhook content
And finally marks the webhook ID as “executed” so they don’t execute the code twice.
Synchronously:
Your backend receives Lean webhook call
Processes the request on their side
Marks the webhook ID as “executed” so you don’t execute the code twice
And finally returns the response with a 200 OK back to the Lean platform.
To make sure that Lean webhooks are captured successfully by your backend, if the Lean platform doesn’t receive a 200 OK response within 10 seconds, we will try to resend the webhook in increasing intervals. See here for the detailed mechanism.
Therefore, we strongly advise you to implement all webhooks “ASYNCHRONOUSLY”, to avoid processing the same request several times due to delay issues in returning the 200 OK in the right time.