Web Protocols Cheat Sheet – Frontend System Design

HTTP/1.x and HTTP/2 represent two major versions of the Hypertext Transfer Protocol used for the World Wide Web. HTTP/1.x, with its final iteration being HTTP/1.1, has been the backbone of the web for decades. Its simplicity and text-based nature characterize it, making it easy to use and understand. HTTP/1.1 can reuse a TCP connection with keep-alive, but it still processes one request at a time on that connection (head-of-line blocking), which gets inefficient when a page has many assets.
HTTP/2, on the other hand, introduced several key improvements to enhance web performance and efficiency. One of the most significant changes is the introduction of multiplexing, allowing multiple requests and responses to be sent asynchronously over a single TCP connection, reducing latency and improving page load times. HTTP/2 also incorporates header compression to reduce overhead. It once included server push (sending resources before the client asked), but browsers later dropped server push, so don’t rely on it. Despite these advancements, HTTP/2 maintains high-level compatibility with HTTP/1.x, ensuring that applications built on the older versions can be upgraded without drastic changes.
| Feature | HTTP/1.x Pros | HTTP/2 Pros |
|---|---|---|
| Connection Management | Simple; HTTP/1.1 can reuse a connection (keep-alive), but still handles one request at a time per connection. | Multiple requests and responses can be multiplexed over a single TCP connection, reducing overhead. |
| Performance | Well-understood behavior and widespread support across web infrastructure. | Significantly improved performance through header compression, request prioritization, and multiplexing. |
| Resource Loading | Sequential loading can be simpler for developers to manage and predict. | Concurrent loading of resources reduces page load times and improves user experience. |
| Protocol Overhead | HTTP/1.x’s textual nature can be more readable and easier to debug manually. | Binary framing layer reduces overhead and improves parsing efficiency. |
| Scalability | More straightforward to implement on small-scale or less complex websites. | Better suited for complex applications and high-traffic websites due to efficient use of resources. |
| Compatibility and Adoption | Universal support across all web browsers and servers. | It requires modern web infrastructure and browsers but is widely supported in current environments. |
Polling

Polling, a technique used in computer networks to periodically check the state or presence of new data by making repeated requests to a server, is revered for its implementation simplicity. It’s straightforward to set up, making it a go-to choice for many developers when real-time data updates are not critical. Polling facilitates easy load balancing, distributing requests across multiple servers to enhance scalability. Additionally, it’s compatible with modern protocols like HTTP/2, which can optimize its performance through features like multiplexing.
However, polling is not without its drawbacks. It can lead to inefficient use of resources, particularly if new data is infrequent, as servers must process requests even when there’s nothing new to return. This can also result in increased server load, affecting overall performance, and generate significant network traffic, leading to bandwidth overuse. Moreover, the inherent nature of polling means data is not updated in real time, which can result in noticeable delays in data freshness, potentially impacting user experience in applications where timely data is crucial.
| Feature | Pros | Cons |
|---|---|---|
| Implementation Simplicity | Polling is straightforward to implement, involving periodic requests to the server. | Can lead to inefficient resource use if new data is infrequent. |
| Load Balancing | Distributing requests across multiple servers is relatively simple, enhancing scalability. | Server resources may be underutilized during off-peak times. |
| Protocol Compatibility | Works well with HTTP/2, leveraging its performance optimizations and multiplexing capabilities. | Without careful implementation, can negate HTTP/2 benefits due to frequent connections. |
| Data Freshness | Periodic updates ensure data is regularly refreshed. | May experience delays in receiving real-time data due to fixed interval polling. |
| Server Load | Server load can be predicted and managed based on known polling intervals. | Constant polling can lead to unnecessary server load, impacting performance. |
| Network Traffic | Simple to monitor and predict network traffic patterns. | Generates significant overhead, especially when there’s no new data to retrieve. |
Long Polling
While inheriting many advantages of traditional polling, such as ease of implementation and compatibility with existing web infrastructures, this approach offers a more efficient data retrieval method. Adopting a model that allows the server to hold a request open until new data is available can reduce the overall number of requests, potentially decreasing unnecessary network traffic and improving the freshness of the data presented to the user.
However, this method is not without its drawbacks. Similar to traditional polling, it can still suffer from issues like long latency in data updates, which may not be ideal for applications requiring real-time responsiveness. Connection timeouts and the risk of increased traffic overhead during peak times or in scenarios with numerous concurrent connections also pose significant challenges. Thus, while this method can offer improvements in certain areas over traditional polling, careful consideration and management are required to mitigate its limitations, especially in high-demand environments.
| Aspect | Pros | Cons |
|---|---|---|
| Implementation Ease | Shares the simplicity of setup and debugging with traditional polling. | Additional logic may be required to handle long polling connections and responses. |
| Infrastructure Compatibility | Utilizes existing infrastructure without needing significant changes. | Limited by the capabilities and scalability of the current infrastructure. |
| Data Freshness | Improves over traditional polling by reducing the wait time for new data. | Still subject to delays, not suitable for real-time applications needing instant updates. |
| Resource Efficiency | Can be optimized to reduce unnecessary network load compared to constant polling. | Potential for increased server and network load during peak usage or with many clients. |
| User Experience | Can improve user experience by providing more timely updates. | Long wait times for updates can still negatively impact user engagement. |
| Scalability | More scalable than traditional polling in moderate use cases. | Scalability challenges can arise with a high number of concurrent long polling requests. |
WebSockets

| Aspect | Pros | Cons |
|---|---|---|
| Communication Type | Duplex communication allows for real-time, bidirectional data exchange between client and server. | |
| Performance | High-speed communication channel, ideal for low-latency applications. | Continuous connections can increase resource consumption on both the client and server sides. |
| Connection Efficiency | Utilizes a single TCP connection, reducing the overhead of multiple HTTP connections. | Managing a single, persistent connection can be complex, especially in distributed systems. |
| Scalability | Challenges in efficiently load-balancing WebSocket connections can affect scalability. | |
| Compatibility | Supported by most modern web browsers, facilitating widespread use. | Some firewalls, proxies, and older network infrastructure may face compatibility issues. |
| Protocol Overhead | Lower protocol overhead compared to HTTP polling, enhancing efficiency. | Initial handshake and setup can introduce some overhead and complexity. |
Server-Sent Events (SSE)

Server-sent events (SSE) offer a streamlined method for servers to push updates to web clients, harnessing the capabilities of HTTP/2 for improved efficiency and performance. Using gzipping and multiplexing, inherent to HTTP/2, enables SSE to deliver updates with reduced bandwidth usage and better connection management. This approach is particularly resource-efficient as it transmits only necessary text-based updates, making it an ideal choice for applications that require server-initiated messages, such as live news feeds or stock tickers.
However, the primary limitation of SSE lies in its unidirectional nature, allowing data to flow solely from server to client. This makes it less suited for applications that require a two-way exchange of information, such as interactive games or chat applications. Furthermore, its focus on text data may restrict its use in scenarios that demand the transmission of binary data or complex data structures. Despite these constraints, SSE’s ease of integration with existing HTTP infrastructure makes it a strong default for one-way streams.
| Aspect | Pros | Cons |
|---|---|---|
| Protocol Advantages | Benefits from HTTP/2 improvements like gzipping for reduced size and multiplexing for better connection efficiency. | |
| Resource Utilization | Sends only necessary updates as text, optimizing bandwidth and server resources. | |
| Scalability | Compatible with standard load balancing strategies, enhancing scalability. | |
| Communication Direction | Limited to server-to-client communication, not supporting client-initiated data streams. | |
| Data Flexibility | Primarily supports text-based data, which may not be ideal for binary or more complex data needs. | |
| Integration Simplicity | More straightforward to implement on top of the existing HTTP infrastructure without significant changes. | |
| Real-Time Capability | Provides near real-time updates to clients, enhancing user experience for live data feeds. | May experience latency issues in high-volume or high-traffic scenarios. |
REST API

REST APIs have long been the standard for web services, prized for their simplicity, standardization, and compatibility with web technologies like HTTP/2. They excel in scenarios where the API’s structure and data requirements are relatively stable and predictable, offering straightforward scalability through load balancing. However, their stateless nature can introduce latency in dynamic environments, and the granularity of data retrieval may result in traffic inefficiencies.
On the other hand, GraphQL represents a modern approach to API design, emphasizing flexibility and efficiency in data retrieval. By allowing clients to specify precisely what data they need, GraphQL can significantly reduce over-fetching, making it an attractive choice for dynamic, data-driven applications. Its type system and caching capabilities further enhance performance and reliability. However, the complexity of queries and potential verbosity pose challenges, particularly regarding traffic overhead and server processing demands.
| Aspect | GraphQL Pros | GraphQL Cons |
|---|---|---|
| API Design | Enables clients to request what they need, reducing overfetching precisely. | |
| Type Safety | The strongly typed nature of GraphQL enhances API safety and reduces client-side errors. | |
| Caching | Advanced caching capabilities at the client level improve application performance. | |
| Latency | Depending on the server’s processing capabilities, complex queries can result in latency. | |
| Connection Reliability | Connection timeouts may occur, similar to REST APIs. | |
| Verbosity | Verbose queries can lead to increased traffic, especially with nested structures. |
