---
title: "HTTP/2 Stream Multiplexing and Flow Control"
description: "An in-depth technical overview of HTTP/2 stream multiplexing and flow control features"
keywords: ["http2", "stream multiplexing", "flow control", "hpack", "server push", "connection coalescing"]
category: "networking"
---

HTTP/2, introduced in 2015 with RFC 7540, introduced several new features to improve upon the limitations of the older HTTP/1.1 protocol. One of the key advancements in HTTP/2 is its support for stream multiplexing and flow control. 

HTTP/2 defines several new frame types to enable multiplexing. The DATA frame is used to transmit the actual payload data of a request or response. The HEADERS frame is used to send header metadata. The SETTINGS frame allows client and server to exchange configuration parameters, such as the maximum frame size or concurrency limits. Flow control in HTTP/2 is handled via the WINDOW_UPDATE frame, which allows endpoints to advertise their available flow control window sizes.

Another major HTTP/2 feature is HPACK header compression. HPACK, defined in RFC 7541, uses a combination of static and dynamic header tables to efficiently encode and compress HTTP headers, reducing the bandwidth required to transmit them.

Flow control in HTTP/2 is handled at both the connection and stream level. Endpoints use the WINDOW_UPDATE frame to incrementally update their available flow control window sizes, allowing them to manage resource usage and prevent the peer from overwhelming them with data. Flow control window sizes are configurable per connection and per stream.

HTTP/2 also introduces the concept of stream prioritization, where clients can assign a dependency tree and weight to their streams to indicate their relative importance. Servers can then use this information to schedule and prioritize the delivery of responses.

Another HTTP/2 feature is server push, which allows servers to proactively send additional resources to the client before they are requested, reducing roundtrips. Servers indicate a push via the PUSH_PROMISE frame.

HTTP/2 also supports connection coalescing, where multiple HTTP/2 connections between the same client and server can be combined into a single connection, reducing overhead.

If an HTTP/2 connection experiences an unrecoverable error, the GOAWAY frame is used to initiate a graceful shutdown, informing the peer of the last stream it can expect to be processed.

Finally, HTTP/2 introduced an upgrade mechanism called h2c that allows HTTP/1.1 connections to be upgraded to HTTP/2 without requiring a separate TCP connection. This is particularly useful for web servers that want to support HTTP/2 without requiring clients to use a separate port.

HTTP/2 stream multiplexing and flow control features are also leveraged by other protocols, such as gRPC, which uses HTTP/2 as its underlying transport.Building on the previous overview, one important aspect of HTTP/2 stream multiplexing is the ability to prioritize streams. Clients can assign a dependency tree and weight to each stream, allowing the server to schedule and deliver responses based on the specified priorities. For example, a client could mark a critical resource like the main HTML document as the highest priority, while relegating secondary resources like images or scripts to lower priority streams. This enables more efficient use of the available connection bandwidth.

Another key HTTP/2 feature is server push, which allows servers to proactively send additional resources to the client before they are explicitly requested. This can help reduce roundtrip latency by preemptively delivering assets the server knows the client will need, such as CSS, JavaScript files, or font resources. Server push is initiated by the server sending a PUSH_PROMISE frame to the client, which contains the URL of the pushed resource and its associated stream ID.

HTTP/2 also supports connection coalescing, which allows multiple HTTP/2 connections between the same client and server to be combined into a single connection. This helps reduce the overhead associated with establishing and maintaining separate connections. When a new HTTP/2 stream is initiated, the client and server can negotiate whether to reuse an existing connection or create a new one based on factors like connection age and available capacity.

In the event of an unrecoverable error in an HTTP/2 connection, the GOAWAY frame is used to initiate a graceful shutdown. The GOAWAY frame informs the peer of the last stream it can expect to be processed, allowing in-flight requests to complete while preventing new streams from being created. This helps ensure a clean and orderly termination of the connection.

Beyond the standard HTTP/2 protocol, the HTTP/2 transport is also leveraged by other higher-level protocols, such as gRPC. gRPC, a modern open-source RPC framework, utilizes HTTP/2 as its underlying transport, taking advantage of features like stream multiplexing, flow control, and header compression to enable efficient and low-latency communication between clients and servers.

One final HTTP/2 feature worth noting is the h2c upgrade mechanism, which allows HTTP/1.1 connections to be upgraded to HTTP/2 without requiring a separate TCP connection. This is particularly useful for web servers that want to support HTTP/2 without requiring clients to use a separate port or protocol. The h2c upgrade is initiated through an HTTP/1.1 request that includes an Upgrade header, allowing the server to negotiate the protocol upgrade.Building on the previous overview, one crucial aspect of HTTP/2 is the SETTINGS frame, which allows the client and server to exchange configuration parameters that govern the behavior of the connection. These settings can include the maximum frame size, the maximum number of concurrent streams, and the initial flow control window size, among other options. The SETTINGS frame is exchanged during the connection establishment phase, and the configured values can be dynamically adjusted during the lifetime of the connection using subsequent SETTINGS frames.

Another important feature of HTTP/2 is the use of HPACK, a header compression algorithm defined in RFC 7541. HPACK employs a combination of static and dynamic header tables to efficiently encode and transmit HTTP headers, significantly reducing the bandwidth required for header data. The static header table contains a predefined set of common headers, while the dynamic table is populated with headers encountered during the connection. HPACK uses indexed header representations, header huffman coding, and header field splitting to achieve high compression ratios, ultimately improving the overall performance of HTTP/2 connections.

HTTP/2's flow control mechanism is another critical component, operating at both the connection and stream levels. Endpoints use the WINDOW_UPDATE frame to advertise their available flow control window sizes, allowing them to manage resource usage and prevent the peer from overwhelming them with data. The initial flow control window size is configurable per connection and per stream, and can be dynamically adjusted during the lifetime of the connection using subsequent WINDOW_UPDATE frames. This fine-grained control over flow control windows helps prevent resource exhaustion and ensures efficient utilization of the available bandwidth.

Lastly, it's worth noting that the HTTP/2 protocol is not limited to the traditional web browser use case. It has found widespread adoption in other distributed systems, such as gRPC, a modern open-source RPC framework. gRPC leverages the underlying features of HTTP/2, including stream multiplexing, flow control, and header compression, to enable efficient and low-latency communication between clients and servers. This integration of HTTP/2 into higher-level protocols demonstrates the versatility and applicability of the protocol beyond its initial web-centric use case.Building on the previous discussion, another important aspect of HTTP/2 is its support for server push, which allows servers to proactively send additional resources to the client before they are explicitly requested. This can help reduce roundtrip latency by preemptively delivering assets the server knows the client will need, such as CSS, JavaScript files, or font resources. Server push is initiated by the server sending a PUSH_PROMISE frame to the client, which contains the URL of the pushed resource and its associated stream ID. The client can then choose to accept or reject the pushed resource based on its own needs and cache state. This feature can be particularly beneficial for improving the initial load performance of web applications.

HTTP/2 also introduces the concept of connection coalescing, which allows multiple HTTP/2 connections between the same client and server to be combined into a single connection. This helps reduce the overhead associated with establishing and maintaining separate connections, as well as the number of TCP handshakes required. When a new HTTP/2 stream is initiated, the client and server can negotiate whether to reuse an existing connection or create a new one based on factors like connection age and available capacity. This connection coalescing mechanism can lead to significant performance improvements, especially in scenarios with high concurrency or frequent connection establishment.

Another important consideration in HTTP/2 is the handling of connection failures and termination. In the event of an unrecoverable error in an HTTP/2 connection, the GOAWAY frame is used to initiate a graceful shutdown. The GOAWAY frame informs the peer of the last stream it can expect to be processed, allowing in-flight requests to complete while preventing new streams from being created. This helps ensure a clean and orderly termination of the connection, minimizing the impact of the failure on the overall system. The GOAWAY frame can also be used for other purposes, such as signaling the client to migrate to a new connection or indicating that the server is being drained of connections.

Finally, it's worth mentioning the h2c upgrade mechanism, which allows HTTP/1.1 connections to be upgraded to HTTP/2 without requiring a separate TCP connection. This is particularly useful for web servers that want to support HTTP/2 without requiring clients to use a separate port or protocol. The h2c upgrade is initiated through an HTTP/1.1 request that includes an Upgrade header, allowing the server to negotiate the protocol upgrade. This feature helps facilitate the gradual adoption of HTTP/2 by enabling a seamless transition from the older HTTP/1.1 protocol.