Webhook Best Practices

Respond quickly

After receiving a webhook using an HTTPS endpoint, it's important to respond to the request with a 200 OK as quickly as possible.

Often times a message queue is used for storing messages as they are received so they can be processed by a background process. This decreases the likelihood that a call will time out and be considered a failure that should be retried later.

👍

Coding with a ASP.NET Core Web Application?

Read Microsoft's Article: Background tasks with hosted services in ASP.NET Core. This explains .NET technologies that could be used to implement a background process.

Ignore duplicates

It is possible that the same event may be sent more than once. For example, an event will be resent if a prior call timed out(60 seconds) before receiving a 200 Ok status. Webhook endpoints should be implemented with idempotent operations. If an endpoint receives a duplicate event then it should have no effect. The "X-Directscale-Message-Id" header can be used to filter duplicate messages.

Manage delays

In certain circumstances, there are delays in sending webhooks. If receiving webhooks a day or more late will cause issues to your implementation then it is recommended to use the "EventDateUtc" timestamp from the JSON body to compare to the current time.


Did this page help you?