What Is HTTP/2

Introduction

HTTP stands for Hypertext Transfer Protocol, HTTP is a mechanism through which client and server can interact with, for instance when a user opens google.com on their machine, the web browser sends an HTTP request to the Google servers for the content to appear on the page, then google servers send HTTP response with the text, images that user’s browser displays.

Till 2015, the above request/response mechanism was happening on HTTP/1.1 and it had some performance limitations as the modern-day applications deal with very heavy load as compared to before. HTTP/2 protocol speeds up page load significantly.

 The article covers,

  • HTTP/1 Limitations
  • What is HTTP/2?
  • New Enhancements in HTTP/2

HTTP/1 Limitations
 

HOL – Head of Line Blocking

When a client sends a request to the server like requesting for google.com, first a TCP Connection is established, initially, it’s just one connection

Assume the requested resource is an index.html file and internally the HTML file requires index.js or style.css file. The first request will be created for single index.html

Since it’s a single TCP connection, so the TCP connection gets blocked until the response is received. Once the response for index.html is received, the next request will be raised for index.js and then for style.css. Eventually, 3 TCP connections will be established between client and server.

Along with HOL blocking problem where until a response for index.html is not received new TCP connection is not created for index.js and style.css, the multiple TCP connections cause Network latency.

Today, in total the browser can send 6 parallel TCP connections, and considering the load today's applications face, these 6 connections are not sufficient.

Repetition of Headers

HTTP is a stateless protocol; in HTTP each request is independent of previous and next requests. Each request carries its own header data like a cookie, user-agent, cache-control, version, method, content-length, etc. These headers were sent repeatedly for every request which leads to a lot of duplicated data, eventually causing data redundancy.

Efforts for Performance Improvement

To address the performance issues because of HTTP/1, developers used performance efforts such as JS/CSS obfuscation, caching, sharding, etc., which created extra workload and optimization problems for them.

HTTP/2.0

In HTTP/2.0 a single TCP connection is created where it creates a stream and internally every request is sent as a part of the stream, in a nutshell, it fetches all 3 files in one TCP connection. The only prerequisite is HTTPS is a must for HTTP/2 to work.

Over one TCP connection, multiple requests are sent over to the server in a stream, and a response for the requested resource is received in the same stream.

What is HTTP/2

Here the number of TCP connections is reduced from 3 to 1, which means the Network latency issue is resolved as well as the HOL problem is resolved as the other required files are pushed in a single TCP connection itself.

HPACK

HTTP/2 follows HPACK compression which is used to compress the size of the Headers, as discussed earlier, today’s applications receive large numbers of requests and the redundant header fields in the requests consume bandwidth. The HPACK compressor reduces the header size by eliminating the redundant (duplicate) header fields.

What is HTTP/2

Server Push

In HTTP/1.1 if the HTML page is received by the browser, then the browser parses it and identifies what extra files or assets is required then it uses to request these assets from the server again.

In HTTP/2, the browser receives more than it asks for it, the assets go to the browser cache, example HTML page requires JS and CSS, but the browser may receive other files as well apart from the required and these files sit in the browser cache and will be immediately available whenever these files are needed, this is a good performance enhancement.

Summary

HTTPS is a must for HTTP/2 to work and most browser supports HTTP/2 these days, for using this protocol the websites must be served over an encrypted connection. Few tools still don’t support HTTP/2 like Postman, for testing we may have to rely on traditional curl utility.


Similar Articles