The behind the scenes of typing a url into your web browser

TL;DR: Machines don’t really understand the url’s that we type everyday, they have to use a system to translate them into something they can understand!

Whenever you go to a website, have you ever thought something like:

Hmm, I wonder what really happens behind the scenes, how does my browser knows where or how to look for this url and then show me the page that I was looking for?

Well, I had asked me that question multiple times in the past, until I finally understood how that works.

The first important thing to understand is that the web works with a concept called client-server. When a program works under this concept, means that there is a main machine(s) that contains the information, code, and/or resources that it needs. Then, one or more client machines connect to one main machine to get the required resources. In the web, the clients are all the devices that can browse through the internet, like computers, tablets, smart phones, smart tv's, and anything that can access a website.

The client machines use programs designed to establish a communication between them and the main ones. Usually, this programs are the web browsers like Google Chrome, Firefox, Safari, Edge, among others. Those programs have been built with the required specifications to establish the communication between the main machines, which we will call servers.

As of the date of this post, there are more than 2 billion of web sites, being served by multiple (distributed around the world) server machines. To coordinate the way those server machines communicate with the millions of clients that exist, a set of rules that must be follow had to be defined. That set of rules is called a protocol, which in this case, for client and server machines is called the http protocol. The http protocol is used by the internet, which in this case is the communication channel between client and servers.

Now, whenever a client tries to access a website, it needs to know which computer to talk to and where that computer is located. For this task, there is something called IP (Internet Protocol), which is a set of numbers that identify a machine that is connected in the network. An example of an IP could be 172.217.3.164.

As you may have realized by now, those set of numbers are really hard to remember. Imagine that in order to access Google Search, you had to type 172.217.3.164 instead of www.google.com, of course it's easier to write the later one.

Then, how does a machine knows that www.google.com equals 172.217.3.164? Here is when we need to introduce a new system called DNS (Domain Name System), which is the one in charge of correlate an url and an IP .

But how does this DNS works? First, the web browser receives a request to display a website, for example www.google.com. Then, the browser looks inside its registry (which we will call cache for easier understanding) to know if there is already an entry (the IP) for www.google.com. That cache will be updated whenever someone visits a web site.

If the browser does not find the IP address in its cache, it will ask the Operative System (OS), which also contains a registry similar to the one described above. In case the OS does not contain anything in its cache, the browser will ask the resolver. The resolver is basically your ISP (Internet Service Provider).

All ISP's have their own registries as well. But if none of them contains the entry to know the IP for the requested address (which honestly this would be really hard), then the resolvers will go and ask to the roots. One main task that a resolver has is to know where the roots are located. There are only ~12 roots located around the world, but this does not mean that they are only 12 computers. Those 12 roots are operated by hundreds (maybe thousands) of machines distributed around the world.

The roots are the ones in charge of redirecting the petition to the TLD’s (Top Level Domains). The TLD’s are the machines with the registries for all the entries for .com, .net, .mx, .edu, and so on. The TLD will give the name servers assigned to a web site. The name servers’ data reaches the TLD whenever someone purchases of a domain. For example, when the purchase and registration of google.com was made, it was stored in the TLD .com.

Domain is the technical name given to the sites.

When a domain is registered, the owner is the one that specifies which are the name servers. Those are the ones that will have the correlation between a domain and an IP.

As you have seen, getting the IP for a website is not an easy task, that’s why each one of the steps have their own cache to make things faster.

If you wanna know more about how the DNS works, I recommend you to take a look into https://howdns.works. It’s a friendly website that shows you this topic in depth using a comic-like environment 🤓

With the IP address obtained, your browser already knows which machine to go to, make the request, and then display the web page you were looking for.

Pretty easy, huh? I must say that even though it looks easy, there is a lot of engineering behind the scenes that makes things like this pretty fast, reliable, and cool 🔥