Data Fetching Patterns
Learn about the different techniques used to fetch data from servers.
We'll cover the following
Introduction
Servers can send a large amount of data to connected clients daily in real-world applications. HTTP is predominantly used on the Internet to send and fetch content from servers. On top of that, data fetching requests are millions per second in read-heavy applications such as Twitter, Quora, and so on. Different applications require a varied communication structure depending on their use cases, for example, a few applications are tolerant to some delays, while others might need near real-time updates. We need a mechanism to deliver real-time data updates between the client and server. For example, real-time communication is needed with a navigation system, where the server tells the directions, and the client must repeatedly send its location.
This lesson will discuss data polling techniques to send and fetch data to and from the server. The main polling methods are given below:
Short polling
Long polling
Additionally, this lesson also discusses WebSocket, a full-duplex protocol used to address the limitations of polling techniques and provide real-time communication between the client and server. It also enables clients and servers to avoid polling of data. Let’s discuss the mentioned approaches one by one
Short polling
With short polling, the client initiates a request to the server for a particular kind of data at regular intervals (usually < 1 minute). When the server gets the request, it must respond with either the updated data or an empty message. Even though the small polling interval is nearly real-time, deciding the polling frequency is crucial. Short polling is viable if we know the exact time frame when the information will be available on the server. The illustration below represents the short polling procedure between the client and server:
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.