What happens when you open a site in your browser?

Rabi Siddique
3 min readMay 21, 2022

--

Every day, we consume content from various sites on the internet. Be it a video on Youtube, a post on Facebook, or some random blog on Medium, you’ve just read, you navigate to these pages via typing a URL in the address bar of your browser or by opening a certain link. Ever wondered, what is happening under the hood when you’ve tried to open a website? Simple! an HTTP request is made to a server where the website content you’re trying to consume is present. All we need is to get that content from the server via an HTTP response and render it in our browser in order to see it.

Note that the words “Client” and “Browser” are used interchangeably in this post. They both mean the same in this post. Browser == Client ;)

This process of getting a website’s content from some server on the Internet can be divided into 6 steps:

1-DNS Lookup
2-TCP Connection
3-Client sends an HTTP Request
4-Client waits for a response from the server.
5-Client loads the contents of the response it received.
6-Client closes the TCP connection.

DNS Lookup

DNS Lookup is the process by which the domain name of a site is resolved to a unique identifier, the IP address of the server, where the site content is present. The browser needs this IP address so as to send HTTP requests to the right place. In simple words, the DNS converts domain names i.e. www.google.com.pk into their respective IP addresses i.e. 8.8.8.8

To obtain the IP address of the server where the site content is present, the client sends a query to the local ISP DNS server which in turn resolves the domain name and sends an IP address for the respective domain name, to the client.

TCP Connection

Now that client has the IP address of the server from where it needs to get site data and load it, it first needs to establish a connection with that server, using the TCP protocol’s 3-Way-HandShake mechanism.

TCP is a protocol that is responsible for the reliable and secure transmission of data between the client and server. So, in order for the client and server to exchange data, a TCP connection is first established using the 3-Way-Handshake. In 3-Way-Handshake, the client uses the IP address received from the local ISP DNS server to establish a TCP connection with the server. The 3-Way-Handshake happens as follows:

1-Client sends a packet containing SYN(Synchronize) bit to the server.
2-The server sends back a packet containing the SYN and ACK(Acknowledge) bit to the client.
3-The client sends a packet to the server with an ACK bit.

Now, 3-Way-Handshake is complete. The client and server are connected and ready to exchange data.

Client sends an HTTP Request

Since the client has now established a connection with the server, it makes an HTTP request to the server, for the contents of the site.

Client waits for a response from the server

After sending the HTTP request, the client waits for a response from the server. The server process the client’s HTTP request, finds the resource requested by the client, and sends it back to the client via an HTTP response.

Client loads the contents of the response it received

The client after receiving the HTTP response from the server parses it and loads it in order to view it.

Client closes the TCP connection

The client sends a FIN(Finish) bit in a packet to close the TCP connection.

Thanks for reading the post and hope you found it useful. :)

Let’s connect:
LinkedIn
Twitter

--

--

Rabi Siddique
Rabi Siddique

Written by Rabi Siddique

A passionate Software Engineer who intends to be the best and nothing less.

No responses yet