How does the WEB ๐ŸŒ work?

How does the WEB ๐ŸŒ work?

ยท

5 min read

Have you ever wondered what happens when you type a URL in the search bar? What happens behind the scenes? Where does YouTube come from when you type youtube.com?

Let's start by understanding what a URL is. A URL is a link ๐Ÿ”— is composed of several parts.

image.png

Components of a URL

  • Protocol

    The protocol is a set of rules that defines the format of data being exchanged between two devices. IP is the protocol for the internet which contains the set of rules on how data should be transferred over the public network. It works along with TCP which divides the data into small chunks called packets. Together, they are called TCP/IP.

  • IP Address

    An IP address is a unique address that is assigned to a local network. It is a set of four numbers separated by a period. IPv4 address ranges from 0.0.0.0 to 255.255.255.255. IPv6 is a newer version that supports a much larger range. In the case of servers, every server usually has a unique IP address assigned to it which is used to fetch information (like webpages) stored in that server (More on this later).

  • Domain

    We humans have a tough time remembering digits. So of course we need a better way to remember the address to your favorite websites. In comes the domain. It's an alias used to represent the string of 4 numbers. The domain contains TLD, SLD and possibly a subdomain.

๐Ÿ’ก Fun Fact: LasVegas.com was purchased for a whopping 90 million dollars in 2005. It stands as the most expensive domain purchase ever.

  • TLD

    TLD or Top-Level-Domain are the domains at the highest level of the hierarchy of Domain Name System (DNS) after the root.

  • SLD

    SLD or Second-Level-Domain are the domains that come after the TLDs in the DNS hierarchy. It consists of the part before the TLD in the URL.

  • Subdomain

    A subdomain comes after the SLD in the DNS hierarchy. For example, www is the subdomain in www.youtube.com. The string of characters that comes before the SLD in the URL is a subdomain for that domain.

image.png

What happens when you search ๐Ÿ” for a URL?

There are several steps that the browser takes to serve the right web page you've requested for. Ultimately, your browser needs to send an HTTP request to the server that hosts the web pages. To send the request you need the server's IP address.

As mentioned previously, IP addresses are given easy to remember aliases called domains. Each website has its own name server which stores the DNS Records. DNS Records provide information like what IP Address is the domain associated with. You can learn more about DNS Records here . To query this DNS record, the browser sends a DNS Query to the DNS Servers that store these records. These servers are usually hosted by your ISP. Imagine a DNS server like a large phone registry where the contact name is the domain name and the IP address is the phone number.

The following steps are taken by your browser to display the web page on the screen:

  1. Before sending the DNS query, the browser first checks if a cached version is stored in the browser to speed up the process.

  2. If it doesn't find anything in the cache, it checks your operating system's cache, then your router's cache and finally it checks with your ISP's cache.

  3. If all the cache checks fail, it sends a DNS query to the DNS server of your ISP.

  4. It may happen that your ISP's DNS server does not contain the record for that website. So it performs a recursive DNS search on all the domain servers until it finds the IP address for the domain name requested.

  5. Once you get the IP address of the server, your browser sends a request to send the desired web page to the server along with a few headers that ensure the user has access to the pages requested.

  6. When the server receives this request, it first checks if the user is authorized using the headers passed. If yes, then the web pages are sent back to the user and the browser displays them.

HTTP vs HTTPS

HTTP stands for Hypertext Transfer Protocol. It facilitates the exchange of resources such as HTML pages over the internet. HTTPS is a secure version of that protocol (S stands for secure) The difference between them is HTTPS sends the request in an encrypted format so that no attacker can snoop on the details sent in the request. It is especially useful when sending sensitive information like passwords and bank details. That's the reason websites that don't have HTTPS are termed risky by your browser.

Let's say you wanna look up something on YouTube. You go to your browser and type youtube.com. Here's what happens...

  • The browser sends the DNS query

image.png

  • It gets the IP address mapped to the domain name

image.png

  • Now that the browser knows where the server address is, it sends the request to the server requesting the web page

image.png

When the request reaches the server, it first checks if the request has the right access. If it does, then it sends the web page back as a response.

image.png

That's it!

This is all that happens to bring up your websites on the screen! If you enjoyed this read do consider following me for more such articles. ๐Ÿ˜‰

Post your comments/feedback down below ๐Ÿ‘‡

image.png image.png

Ciao! ๐Ÿ‘‹

ย