Data Retrieval in Frontend System Design
Understand and compare polling, WebSockets, and server-sent events (SSE) to choose the most efficient data-fetching strategy for real-time and dynamic frontend applications.
Imagine a user visiting a page to check their notifications, but nothing loads until they manually refresh. Now, picture an online stock trading app that updates so slowly that users miss critical price changes. These scenarios highlight inefficient data fetching patterns or techniques.
Problem: Modern web applications rely on dynamic, data-driven interfaces, but loading too much data or fetching it inefficiently leads to sluggish performance, delayed responses, and frustrated users.
Solution: To keep web apps fast and responsive, selecting the right data fetching strategy is crucial. Fetch data only when necessary, such as after a user action or in real-time if the application demands it. This approach minimizes delays and prevents unnecessary system load.
Let’s explore the key data fetching patterns and how they optimize performance.
Introduction
Servers can send a large amount of data to connected clients daily in real-world applications. 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. 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 different data fetching patterns and techniques to optimize applications’ performance while fetching larger server data. We’ll explore the following:
Polling
WebSockets
Server-sent events
Let’s discuss the mentioned approaches one by one.
Polling
Polling involves periodically sending requests to check for new data. It can be divided into the following two categories:
Short polling to fetch data
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, ...