Describe short polling and its drawbacks. Question For - Junior Level Developer
Question
Describe short polling and its drawbacks. Question For – Junior Level Developer
Brief Answer
What is Short Polling?
Short polling is a client-server communication method where the client repeatedly sends requests to the server at fixed intervals to check for new data. While it can simulate real-time updates, it is generally inefficient.
Key Drawbacks:
- Latency: Data isn’t delivered instantly, leading to noticeable delays in updates (e.g., in chat or live dashboards), making it unsuitable for true real-time applications.
- High Overhead: Every poll creates a new HTTP connection, consuming significant server resources and increasing server load, which limits scalability.
- Wasted Resources: Most requests return empty responses, leading to inefficient use of bandwidth and processing power.
- Battery Drain: Frequent network activity keeps mobile device radios active, rapidly depleting battery life.
Interview Edge:
Always emphasize its inefficiency compared to persistent connections like WebSockets, which are far superior for real-time needs. Highlight its unsuitability for immediate data updates and its negative impact on mobile devices. If you have relevant experience, briefly mention how migrating from short polling to WebSockets improved performance, ideally with quantifiable benefits.
Super Brief Answer
Short polling is a client-server technique where the client repeatedly sends requests to the server to check for new data.
Its main drawbacks are significant latency, high connection overhead (new connection per poll), wasted bandwidth from frequent empty responses, and severe battery drain on mobile devices.
It’s highly inefficient and unsuitable for true real-time applications, where alternatives like WebSockets are vastly preferred.
Detailed Answer
What is Short Polling?
Short polling is a client-server communication technique where the client repeatedly sends requests to the server at fixed intervals to check for new data. While it can simulate real-time updates, it is largely inefficient and problematic due to inherent high latency, significant connection overhead, wasted bandwidth from empty responses, and considerable battery drain on mobile devices. For truly real-time applications, more efficient alternatives like WebSockets are preferred.
Key Drawbacks of Short Polling
Short polling, despite its simplicity, presents several significant disadvantages that make it unsuitable for modern, real-time applications:
1. Latency
Short polling introduces inherent latency, which significantly impacts the user experience, particularly in real-time applications. Imagine a chat application relying on short polling: a user sends a message, but the recipient does not see it until their client polls the server again, perhaps several seconds later. This lag disrupts the flow of conversation and creates a frustrating experience. Compare this to the near-instantaneous delivery provided by WebSockets. The delay caused by latency is the primary reason why short polling is not suitable for applications requiring immediate feedback, such as online gaming or collaborative editing.
2. Overhead
Every poll request creates new HTTP connections, dramatically increasing server load and resource consumption. Each new HTTP connection requires the server to allocate resources for handling the request, including opening and closing TCP connections. With frequent polling from multiple clients, the server can become overwhelmed, leading to performance degradation and limiting the number of clients it can support. This constant overhead makes short polling far less scalable than WebSockets, which maintain a single, persistent connection.
3. Inefficiency (Wasted Resources)
Most short poll requests return empty responses, leading to a substantial waste of bandwidth and processing power. This inefficiency is particularly evident in scenarios where updates are rare. Consider a stock ticker application: stock prices might only change every few seconds or even minutes. With short polling, the client continuously sends requests, and the server repeatedly responds with the same price information most of the time. This unnecessary data transmission wastes valuable bandwidth and server processing power, especially if many users are tracking the same stock.
4. Battery Drain
Frequent polling can significantly drain battery life on mobile devices. Mobile users are highly sensitive to battery consumption, and short polling’s constant network activity keeps the device’s radio active, rapidly depleting power. This can lead to negative user reviews and even app abandonment. WebSockets, with their persistent connection and less frequent data transmissions, offer a much more battery-friendly solution for real-time updates on mobile platforms.
Interview Preparation Hints
When discussing short polling in an interview, consider the following points to demonstrate a comprehensive understanding:
1. Emphasize Inefficiency Compared to WebSockets
Clearly explain the stark contrast in efficiency between short polling and WebSockets. Use an analogy, like a revolving door (short polling) versus a single open door (WebSockets). With short polling, every request is like someone entering and exiting through a revolving door—it takes more effort and slows things down. WebSockets, conversely, are like a single open door—communication flows smoothly and efficiently without constant re-establishment.
2. Highlight Unsuitability for Real-time Applications
Stress how short polling’s inherent latency makes it unsuitable for applications demanding immediate data updates. Provide specific examples of how latency negatively impacts user experience:
- In a live dashboard displaying stock prices, short polling could result in outdated information, potentially leading to poor trading decisions.
- In a fast-paced online game, delayed updates could mean the difference between winning and losing.
3. Address Battery Drain and Mobile Constraints
Demonstrate awareness of mobile development constraints by bringing up the battery drain issue. Mention alternative solutions for mobile environments, such as push notifications. While not as real-time as WebSockets, push notifications can be a more battery-efficient way to deliver updates in certain mobile applications.
4. Share Relevant Project Experience (If Applicable)
If you have practical experience where you replaced short polling with WebSockets, briefly mention the performance improvements. Prepare a concise story about such a project, quantifying the benefits whenever possible. For instance:
“In a previous project involving a real-time chat application, we initially implemented short polling. We quickly realized the limitations as the server struggled to handle the increasing number of users and message frequency. Latency was also a major issue, with messages often delayed by several seconds. We then migrated to WebSockets. This resulted in a dramatic 60% reduction in server CPU usage and a tenfold improvement in message delivery speed. User feedback was overwhelmingly positive, highlighting the much smoother and more responsive chat experience.”

