Webhook is server saviour

Knock Knock Hey !!!! server is there any update ? No.

Knock Knock Hey !!! server is there any update ? No.

and this goes on….

Cron behaves exactly like this when it tries to get data from any 3rd party server to be updated. Which wastes a lot of resouces to both server and client side.

Client trying to get any update

Possible cases :

  • Single client on a server.
  • Multiple clients on a server.
  • Server callback updates to its client’s address.

Now think about case 1, client will keep ping server for data again and again and server will return null until it has data. Result — waste of time for the client and the server both.

Case 2 : Huge load on server and all will get null :) until server dies or data is found. It’s like all students asking for his/her result from a single person.

Case 3 : Just think as provider stores subscriber’s id and notify them as there data is found. Cool !!!.

Webhook is similar to case 3. Here server returns callback when conditions are satisfied, without knocking each others and both are free to do their work or rest.

Client has to provide these parameters (depends upon server):

1 : Webhook API end point.

2 : HTTP method.

3 : Secret key.

Here server has no data for id p21
Client has request for data, but not found, with a update later message

Here client has no data in its database so, it checked in third party server and server also doesn’t have data. So, it has created a subscription to update when it gets data and the client has created an empty data.

Empty data in client database.

Here client didn’t request third party server as it knows server also doesn’t have it and it will call me once it gets.

Data of id p21 is inserted in server.

Here comes Webhook, as soon as server gets the data it checks all subscribers and updates them. If client is down then it will retry.

Also, as client API endpoint is public, there is chance of getting incorrect data, so secret key is passed from client-server-client to make sure data is coming from genuine location. Now client can modify data and notify its user.

Data in client side for id p21

Webhook POC

Client side logic
Server side logic

Many services like payment gateways, Git, Slack use webhook to keep their clients updated. For example one product price gets updated and is hosted on multiple platforms. In that case, will you go on each platform and update or write a webhook for it !!!!!.

No more knock knock, keep calm you will be updated.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store