Sunday, February 27, 2022

HTTP Push Vs Pull

HTTP is the most common methods of data transfer in client server-based architecture. 

But there are two ways to data transfer: HTTP Push and HTTP Pull.

Pull API

In the HTTP pull method, the client sends a request to the server and the server responds to that request (and the connection is closed). The client pulls the data from the server whenever it requires (by creating a new connection). And it keeps doing it over and over to fetch the updated data

The disadvantage of the HTTP pull method is that if clients keep on periodically makes the pull request for updated data, but there are no updates at the server hence, every time the client will get the same result, bandwidth will be wasted and the server will be busy too.

Also, excessive pulls by the clients have the potential to bring down the server.

This is also called "Polling" and it's basically the same as refreshing your inbox every 5 minutes to check for new mail.

As a developer, if you want to find out whether an API has anything new for the user, you just need to call and ask.

Generally you can poll the API anytime, and as often as you like, but some larger applications typically have limits on how often they allow you to call their API.







Push API
To overcome the problem with HTTP pull, an HTTP push was introduced. In the HTTP push method, the client opens a connection to the server by requesting a server only the first time and after that server keeps on pushing back updated content to the client, whenever there’s any.

In this method, the client receives the updated content instantly.

The HTTP push mechanism, leverage the persistent connection i.e. the connection remains constantly active for further communications instead of being closed after a single request and response, just like in HTTP pull.

A much faster way to monitor for updates is to reverse the roles: have the source application send out an update when it has something new. This is called a Push API, and is generally referred to as a HTTP request or a webhook.

A webhook is a specific URL your application gives to another application with the instructions to send the update this way whenever something new has happened. Then all your application has to do, is monitor it's own URL which is much less resource-intensive and nearly instantaneous.








Sources:
https://medium.com


1 comment: