There would not be a single day in your life that you will pass by without clicking a link in today's day. We click several links throughout our day, without even knowing what is happening in the background. So, if you are curious to know what happens in the background when you click a link, then I am here to tell you that.
In my explanation, I will be assuming that you are someone who is not from the tech-related world, so I will be explaining things in the simplest manner that I can.
Before we get started
Before we get started, there are few things that you should know:-
What is an IP Address?
To describe in brief, an IP address is a set of numbers used to uniquely identify a device on the internet or a local network.
What are Network Layers?
The internet is divided, into four layers and each layer has its own functions and responsibilities.
Types of network layers
- Application layer: The layer where applications such as youtube run.
- Transport layer: Responsible for the process to process communication, e.g: facebook's messenger to messenger.
- Network layer: Responsible for locating the destination and routing a path to the destination.
- Data Link Layer: Responsible for the one-to-one connection between the devices, e.g: your phone to the wifi.
What are requests and responses?
Requests are kind of a signal sent by the clients ( your devices, i.g., mobile, laptops ) requesting for some kind of data, i.e., images, videos, text, and in return on receiving the requests the servers send back a response containing the data asked through the requests.
Lets get started
You clicked a link
What now? what will happen now? Well, when we want to visit a website, we actually want to locate and access that website's server, and to locate a server, we need its IP Address. In order to find that IP address, the URL/link that you clicked is going to help us.
The application layer takes that URL/link and passes it to the DNS server( what is a DNS server? ) to get the corresponding IP Address.
Okay, now that we have the IP address, things are going to be easy. We know where to send the data/request to.
Fun begins
Now the real fun begins.
No matter, what you do in your application, it is going to generate either a request or a response, either way, it is going to be treated as info or data. Now the application layer takes this data and embeds it into the application header and passes it down to the transport layer.
Now, the transport layer takes the application header and it may or may not break the application header further into pieces, depending upon the size. It appends the application header with the transport header and the transport header contains a port number. This port number is used to uniquely identify an application because it might happen that at the receiver's end there may be more than one application running at the same time and at that point of time the port number helps to identify that the data was meant to be received by which application.
The network layer takes the transport header and appends the network header with it and the network header contains the destination IP address( that we got from the DNS server ). Now that the packets( data units at the network layer ) have the destination with them, they all can travel through the internet individually and independently, to the destination and this process of traveling is known as datagram packet switching.
The packet needs to travel to the gateway router ( e.g., wifi router ) through the data link layer. But for that, the data link layer needs the MAC address of the gateway router. Initially, when our device such as a mobile phone gets connected to a DHCP server ( e.g., router ), the DHCP server gives it all the necessary configuration to get connected to the internet and that includes the gateway router's IP address as well. So, the device with the packets, broadcasts the IP address of the gateway in the closed network, and in return, the gateway router sends back its MAC address as a response, on receiving its IP address. This process is known as ARP( Address resolution protocol )
Now, the data link layer appends the mac header with the packet and ensures the smooth transmission of the frame and in between if the frame gets distorted due to the physical channel, the data link layer retransmits the same frame back to the receiver.
Then the frame is sent to the gateway router, and from there the packet is sent to the receiving end's router through the datagram packet switching process. The receiving end's router sends the packet to the server and then the data is retrieved from the packet at the server's end. The server in return sends back a response( e.g., video, image, text ) to the client( your device ) through a similar process.
So, this was the entire process that happens behind the scenes after you click a link and enjoy your favorite content.
I know it's quite a lot to take at once, but give it some time and you will get it. I hope you enjoyed the read.