Isak Berglind

Isak Berglind

How does the web work?

Isak Berglind • May 10, 2020

Almost everyone browses the internet daily. We read news, check social media, check when the pizzeria closes and so on, but do you know how it actually works? When you type in www.google.com in the url-bar and hit enter, and google magically appears on the screen - how did that happen?

Actually, there is a lot going on, and in this article series, I will try to explain every step of the way and hopefully you can learn a thing or two.

The example we will use is this very page. What happened when you landed here on this article?

Jargon

Before we start, I need to clairify some jargon I'll be using, so you know what I'm talking about.

Browser

The program you use to browse the internet. There is quite a few browsers out there, but the most popular are Chrome, Firefox, Safari, Internet explorer and Edge.

Server

The computer on which the website you're trying to visit is hosted on. I will explain what a server is in more detail later on, but for now, let's just think of it as a computer that is connected to the internet and has website on it.

URL

Stands for 'Uniform Resource Locator' and is simply a web address. https://www.facebook.com is a URL, as well as https://isakberglind.se/blog/how-web-works-part-1/ which is this page's URL.

That'll be all for now, let's dive in!

DNS

Bah, we start with a mysterious and hostile shortening that doesn't say anything about what it is. Let's see what it stands for - it's 'Domain name service'. Still not clear? Of course not, but let's break it down!

Every device that's connected to the internet has an IP-address. I'm sure you've heard the term before but maybe don't know exacly what it is. It stands for 'Internet protocol' and is simply a sequence of digits and dots*, and acts an address to the device. It's just like your street address, if someone want's to visit your house, you give them your street address, and they know where to drive. Likewise, when you want to visit a website, you go to its IP-address. This website for example has the following IP-address: 165.227.12.111

Okay cool, but haven't we strayed away from the topic? We were supposed to talk about DNS! What is this IP-address stuff?

As it turns out. DNS is alot about IP-addresses. When you visited this site you probably didn't type 165.227.12.111, right? you typed www.isakberglind.se. This is where the DNS comes into play! The DNS maps the domain names (isakberglind.se) to the servers IP-adresses. This way, you don't need to remember a bunch of numbers, but instead use convenient domain names. It has more benefits too! IP-addresses can change. Maybe a website moves from one server to another, then the IP would change and you have to remember a new IP for that site. That would be horrible. The DNS takes care of that and makes sure that when you type in the domains name, you get the right IP-address.

Now we know what the DNS does. But what is the DNS?

The DNS is simply a network of servers. Your operating system has a list of DNS server IP-adresses (You see? IPs again!) that it provides to the browser, and the browser uses the first one on that list. If that one fails for some reason, it will try the next one, and so on. That DNS server in turn looks up the domain name with help from the other servers, but that is transparent to the browser.

So, when you type the url and hit enter, the browser asks the DNS-server which IP-address www.isakberglind.se points to, and the DNS looks it up and sends it back. Easy!

If this explanation satisfied your curiosity - Awesome, you're done, stop reading and continue to the next step! But if it spawned even more questions like 'How does the actual DNS work internally?', 'How does the DNS know all these IP-adresses?' and 'If this happens everytime someone visits a website, wouldn't the DNS-server explode from all the traffic?', then I have a great resource for you. Cloudflare has done a great job explaining this is this article: https://www.cloudflare.com/learning/dns/what-is-dns/

That's all for the DNS. The next step is the browser actually connecting to that IP-address, and that will be covered in the next article.


* That's not always the case thought. Digits and dots are Ipv4-addresses (Internet protocol version 4). There is also Ipv6-addresses that looks a bit different, more on that here