The blog post "You might not need WebSockets" argues that developers often prematurely choose WebSockets for real-time features when simpler, more efficient solutions exist. It highlights server-sent events (SSE) as a robust alternative for unidirectional communication from server to client, offering benefits like automatic reconnection and built-in event handling. While acknowledging WebSockets' bi-directional capabilities, the post emphasizes that many use cases only require server-to-client updates, making SSE a lighter and potentially better-performing choice. It encourages developers to carefully analyze their needs before defaulting to WebSockets and consider the reduced complexity and improved resource utilization that SSE can provide.
Without TCP or UDP, internet communication as we know it would cease to function. Applications wouldn't have standardized ways to send and receive data over IP. We'd lose reliability (guaranteed delivery, in-order packets) provided by TCP, and the speed and simplicity offered by UDP. Developers would have to implement custom protocols for each application, leading to immense complexity, incompatibility, and a much less efficient and robust internet. Essentially, we'd regress to a pre-internet state for networked applications, with ad-hoc solutions and significantly reduced interoperability.
Hacker News users discussed alternatives to TCP/UDP and the implications of not using them. Some highlighted the potential of QUIC and HTTP/3 as successors, emphasizing their improved performance and reliability features. Others explored lower-level protocols like SCTP as a possible replacement, noting its multi-streaming capabilities and potential for specific applications. A few commenters pointed out that TCP/UDP abstraction is already somewhat eroded in certain contexts like RDMA, where applications can interact more directly with the network hardware. The practicality of replacing such fundamental protocols was questioned, with some suggesting it would be a massive undertaking with limited benefits for most use cases. The discussion also touched upon the roles of the network layer and the possibility of protocols built directly on IP, acknowledging potential issues with fragmentation and reliability.
Summary of Comments ( 228 )
https://news.ycombinator.com/item?id=43659370
HN commenters largely agree with the author's premise that WebSockets are often overused for real-time updates when simpler solutions like HTTP long-polling or Server-Sent Events (SSE) would suffice. Several pointed out the added complexity of WebSockets, both in implementation and infrastructure, with one commenter noting the difficulty in scaling WebSocket connections. The benefits of SSE, particularly its simplicity and native browser support, were highlighted. Some suggested that the choice depends heavily on the specific use case, with WebSockets being more suitable for highly interactive applications like online games, while others argued that even these could be served efficiently with alternatives. A few commenters mentioned the advantages of WebSockets in terms of lower latency and bi-directional communication, but these were generally seen as niche benefits that don't justify the added complexity for most applications. The general consensus seemed to be: consider simpler options first, and only reach for WebSockets when absolutely necessary.
The Hacker News post "You might not need WebSockets" (https://news.ycombinator.com/item?id=43659370) sparked a discussion with several insightful comments. Many commenters agreed with the author's premise that WebSockets are often overused for real-time updates when simpler solutions like HTTP long-polling or Server-Sent Events (SSE) would suffice.
One compelling argument highlighted the added complexity introduced by WebSockets, including connection management, reconnection logic, and handling various edge cases. Commenters pointed out that this complexity can lead to increased development time and potentially more bugs, especially for smaller projects or less experienced developers. They argued that unless bidirectional communication is absolutely necessary, the simpler alternatives are preferable.
Several users shared their personal experiences where they successfully replaced WebSockets with SSE or long-polling, resulting in improved performance and simplified codebases. They emphasized the importance of evaluating the actual requirements before opting for WebSockets.
The discussion also touched upon the performance aspects of each approach. While some argued that WebSockets offer lower latency, others contended that the difference is negligible for many applications, and the overhead introduced by WebSockets can sometimes negate its theoretical advantages. The point was made that the latency introduced by network conditions often dwarfs the differences between these technologies.
Another key takeaway from the comments is the importance of considering the specific use case. For chat applications or highly interactive games, WebSockets might be the best choice. However, for applications that primarily involve server-pushed updates, like stock tickers or notification systems, SSE or long-polling are often more suitable.
A few commenters mentioned the better browser compatibility of SSE and long-polling compared to WebSockets, although this is less of a concern in modern web development.
Overall, the comments on the Hacker News post generally supported the article's claim that WebSockets are often unnecessarily complex and that simpler alternatives should be considered first. The discussion provided practical advice and real-world examples to help developers make informed decisions about the best technology for their real-time applications.