HTTP/2 multiplexing
I learned about HTTP/2 back in university but never thought much about it. It had only been released 1 year ago and the web was still vastly using HTTP/1.1. Nowadays, HTTP/2 is already widely used but my brain still thinks in HTTP/1.1. So, time to review HTTP/2.
Some new concepts in HTTP/2:
A stream is a bidirectional flow of messages within a TCP connection. It can carry one or more messages. Each stream has a unique identifier and optional priority.
A message is a complete sequence of frames comprehending an HTTP request or response.
A frame is the smallest unit of HTTP/2 communication and can represent HTTP headers, part of the body, etc. A frame has a header specifying the stream it belongs to.
With HTTP/2, communication is done through a persistent TCP connection that can multiplex multiple streams. Frames from different streams can be interleaved and they are assembled in the client/server by relying on the stream header.
This new multiplexing feature avoids having to set up a TCP connection per HTTP request. This leads to better latencies since we avoid the TCP slow start in each new connection Since we are keeping fewer connections open on the application side, it will also reduce its memory footprint.