How does Pusher webhook work? Is HTTP POST request sended from client or Pusher server?

1.4k Views Asked by At

From Pusher documentation

A webhook is sent as a HTTP POST request to the url which you specify.

The question is - does the first POST request is sended from client or Pusher server?

I want to instantly notify users when new product is added to site. So I need to run script that checks which users should be notified and also send notification email to them. As there could be a lot of users that will be interested in product the script can take a lot of time. So I have to do it asynchronously. Otherwise user that wanted to add the product would have to wait for a lond time just to see success message.

One way would be to triger ajax call to server with the success message. However there is danger that user leaves the page (thus closes the connenction) and me not knowing whether all email have been sent.

What I am looking for is a webworker. However as I already use Pusher for real-time chat and notifications I thought that I could use Pusher-s webhook for this purpose.

I want to send "product-added" event that contains product id in data instead of success message. On event I would display success message from browser using JS and use Pusher-s webhook to notify others.

Your server should respond to the POST request with a 2XX status code to indicate that the webhook has been successfully received. If a non 2XX status code is returned, Pusher will retry sending the webhook, with exponential backoff, for 5 minutes. This ensures that temporary failure should not affect your ability to receive all webhooks.

My consern is that if HTTP POST request is first sent from client browser and client closes the connection before script ends I could sent some email twice. If Pusher sends all (including first) HTTP POST requests from their server I have no problems.

1

There are 1 best solutions below

1
On BEST ANSWER

Pusher's webhooks are sent from Pusher's servers. Client disconnects will not affect them - if the event makes it to Pusher, they'll send out the webhook POST.