Best Practices
When using webhooks, hold to these best practices to increase security and performance.
Avoid oversubscribing to events
You should only sign up for the webhook events that are necessary for you. Your server will have less work to complete as a result of this.
Handle events asynchronously
Unify recommends that you handle events asynchronously. This means that you should acknowledge the webhook request as soon as possible and then process the event in the background. This will help to ensure that your webhook endpoint is responsive and can handle a high volume of requests.
This can be done by returning a 2XX response code to the webhook request as soon as possible, and then using a background job or queue to process the event.
Handling duplicate webhooks
Unify guarantees at least once delivery of webhooks. This means that in some cases, you may receive the same webhook event multiple times. This can happen if your server is slow to respond, or if there are network issues that cause the webhook to be retried.
Unify implments idempotency by including a unique identifier for each event in the X-Unify-Event-Id header. You should use this identifier to ensure that you only process each event once. This can be done by storing the event ID in your database and checking it before processing the event.
Ordering event data
As other webhook systems and due to retry policies, Unify can't ensure ordering inside a topic or between topics for the same resource.
For instance, a webhook for an order update could arrive before one for a creation.
This means that you should not rely on the order of events being delivered to your webhook endpoint. Instead, you should design your webhook handler to be able to handle events in any order.
To organize webhooks, we advise using the timestamps that are included in the header X-Unify-Triggered-At.
Updated 9 months ago