Search⌘ K
AI Features

Important Concepts in Product Architecture - II

Explore critical concepts in product architecture focusing on data-fetching methods such as short polling, long polling, and WebSockets. Understand event-driven protocols like webhooks, SSE, and WebSub for efficient server push communication. Learn how cookies and sessions maintain user state and the importance of idempotency in API design to ensure reliable and consistent server behavior under repeated requests.

Data-fetching patterns

Real-world applications serve millions of data-fetching requests per second, especially in read-heavy systems like Twitter and Quora. Different use cases demand different communication structures: some tolerate delay, while others require near-real-time updates (for example, navigation systems where the server provides directions and the client continuously reports its location). The foundational polling methods for client-server data exchange are short polling and long polling. Beyond these, WebSocket provides a full-duplex protocol that addresses polling limitations for true real-time communication.

Short polling approach making needless requests to a particular server
Short polling approach making needless requests to a particular server

Short polling has the client request data at regular intervals (typically less than one minute). The server responds with updated data or an empty message. While it can feel near-real-time at short intervals, choosing the right polling frequency is critical. Short polling works best when the server's update schedule is predictable. Its core problems:

  • Needless requests when the server has no updates, yielding mostly empty responses.

  • The server cannot push an update until the client's next scheduled request arrives.

Delay problem in short polling
Delay problem in short polling

If the server has new data immediately after a response, the client must still wait for the predetermined interval before making its next request. Long polling (also called hanging GET) addresses this by keeping the connection open until the server has new data or an acceptable timeout expires. The server never sends an empty response. This reduces latency for real-time data, but it does not deliver significant performance gains because the client may need to reconnect repeatedly after timeouts.

An idle issue in long polling
An idle issue in long polling

Problems with long polling include:

  • Delays while waiting for updates or timeouts.

  • The server must manage unresolved states for many connections and their timeout details.

  • The client needs multiple concurrent connections to send new information while an existing connection awaits a response or times out.

Note: The TCP connection used by both polling approaches can be persistent (opened once) or nonpersistent (a new TCP/IP connection initiated per request).

Technical Quiz
1.

(Select all that apply.) Identify the advantage(s) of using persistent TCP connections from the given options. Multi-select

A.

Reduced network traffic

B.

Increase connection management cost

C.

Decreased latency

D.

Increase memory consumption


1 / 1

WebSocket

To overcome the limitations of both polling approaches, WebSocket provides a persistent full-duplex communicationThe client and server can communicate concurrently. protocol over a single TCP connection. The client initiates an HTTP connection and requests an upgrade to WebSocket, enabling both parties to send data at any time with low latency and efficient resource use. This eliminates the half-duplex constraint of polling, where only one side communicates at a time.

Communication between the client and the server using WebSocket
Communication between the client and the server using WebSocket

WebSockets’ stateful nature allows reuse of the same open TCP connection, making them ideal for multimedia chat, multiplayer games, and notification systems. A WebSocket connection upgrades from a standard HTTP connection. More detail is available in this course’s lesson on WebSockets.

Technical Quiz
1.

Consider creating a real-time messaging application for an organization’s communication between multiple international offices. Which approach will be appropriate for this case?

A.

Short polling

B.

Long polling

C.

WebSockets

D.

None of the above


1 / 1

Comparison of data polling approaches

The table below compares short polling, long polling, and WebSockets based on the primary factors for selecting the right approach in a given scenario.

Data Polling Approaches

Low Latency


Efficient Bandwidth Usage

Full Duplex

Browser's Compatibility

Short polling

No

(can lower by it using 0 timeout, but at the expense of poor network use)

No

(can be better by increasing timeout but at the expense of higher delay)

No

Yes

Long polling

Yes

(better than short polling)

Yes

(better than short polling)

No

Yes

WebSocket

Yes

Yes

Yes

Yes

Now that you’ve learned how each data-polling technique works, evaluate your understanding with a series of questions using the AI mentor.

AI Powered
Saved
12 Attempts Remaining
Reset

Short polling introduces substantial delay through fixed wait intervals. Long polling reduces this by holding the connection open, but the server and client can still communicate only in half-duplex mode. WebSockets resolve both issues with full-duplex, persistent communication.

Of short polling, long polling, and WebSockets, which data-fetching pattern would be most effective for developing a real-time messaging application that supports communication between multiple international offices within an organization? Discuss the approach you chose and its benefits for efficient data retrieval and real-time communication across distributed locations.

Data fetching pattern for real-time communication

Event-driven architecture protocols

While polling techniques give the client control over when to fetch data, they remain fundamentally request-driven. HTTP-based approaches have inherent limitations for real-time communication: short polling generates excessive, unnecessary requests; long polling requires two separate connections for bidirectional data flow; and HTTP streaming supports only half-duplex communication. Event-driven architecture (EDA) ...