understanding the internet - noob edition

How does the Internet work? An interviewer from Amazon asked me.

Oh BTW this article might be a complete rant on the COVID-19 issues which made my college cancel my Internship at Amazon and I might put some of my personal feelings into the content as well. Just kidding! -_-

Where does your knowledge lie? At the frontend? Is it the backend? Is it networking?

Somewhere. If you're into computer science, your understanding lies somewhere. So if you're a person that works on the web, which is what most people interested in CS do, you should know at least some part of this.

So how does the internet work?

I think a lot of us, when we think of what internet is, we think of web browsers, and we think of, I dont know, may be streaming movies or something like that. Mostly what people interact with the internet is the World Wide Web, that's the www dot something. We all know that but I guarantee you my future daughter will not know what www stands for.

That's just a part of the internet. There's still FTP, there's other things that run over the internet, BitTorrent or Movie Streaming, and lots of other examples.

Noob Note: Intranet is little different from Internet. Intranet is like the internet, but it's private. Most companies use a VPN, a Virtual Private Network, it's one of the best practices. So, if you're on a VPN, you're on an intranet, which is just a private internet of different servers talking to each other, but it's inaccessible from the outside.


Internet runs on trust

It's a really weird concept that, collectively as humanity, we have our disagreements on politics and war and the best type of linux distribution. But we all collectively said, hey let's agree on a set of standards and protocols that my computer can use to talk to your computer and vice versa. And believe me, this is a really big deal in the course of mankind.

They said, hey, this is how my computer can talk to you. And that protocol is called IP (Internet Protocol). Now, a label assigned to an internet connected device is called an IP Address.

IPv4

  • e.g. 8.8.8.8
  • 4 integers in [0,255] separated by dots.
  • 4,294,967,296 distinct IP Addresses

When IPv4 was being adopted, people thought that there'll definitely be not more than 4.3 billion computers in the world. Well, we're way past that. So they invented IPv6.

IPv6

  • e.g. 2001:0db8:85a3:0000:0000:8a2e:0370:7334
  • 8 groups of four hexadecimal digits, each group representing 16 bits
  • 340,282,366,920,938,463,463,374,607,431,768,211,456 distinct IP Addresses

So, these are IP addresses:

Addresses used by the Internet Protocol to kind of talk to each other. Hey, here I am and here's how you can get to me.

Now this all runs on a different Protocol called TCP, Transmission Control Protocol. And most of you have heard of TCP over IP. You also hear the phrase UDP, User Datagram Protocol.

Let's go over some differences in TCP and UDP:

  • TCP is lossless. If I send you some information over TCP, it is going to make it. It's got error correction/checking.
  • UDP is different, it's like I just shouted "Hey" and I assume you heard me and I don't care if you didn't. Essentially, it's just a one way blast of information.
  • TCP has to say, "hey, you there?" (SYN packet) and the client responds with "yeah! I'm here" (ACK).

You don't need to know this stuff, but it's just like this nerd level trivia that might make you look cool at the bar next time you're hanging out.

Yeah, so TCP is slower. Oh BTW I have a good joke about UDP but you might not get it.


Time to do an exercise, let's try ping.

Ping is just a really short request. It just says hey, hey, hey, that's all it does. So, let's go in ping karngyan.com into your terminal.

ping karngyan.com

Hey there, it's alive. Ping is useful for debugging your site. If you're saying, man my clients are complaining about the connection being really slow. What's the cheapest, easiest way to find out if my site up and running?

Domain Name System

But I pinged karngyan.com and not an IP Address. And the way that works is another set of protocols - DNS. DNS is run by ICANN (The Internet Corporation for Assigned Names and Numbers). When you buy a domain name, you actually pay a little bit of fee and they help create this domain name system.

DNS says, what's the closest server this resolves to? It just maps domain names to IP addresses. DNS is just a way of making internet accessible for more people.

Domains

I guarantee you've seen domains and domain is something like google.com, twitter.com etc. The dot com, dot me, dot biz, dot anything - that's the top level domain, i.e TLD. TLDs are owned by specific companies, entities or countries.

Remember that phase a few years ago with the dot lys? It was like bitly, fastly, that was like the hot new thing. Now there's dot io which is really expensive. Almost every country has their own top level domain.

Q: Why would I use a subdomain versus a path? e.g. Path: karngyan.com/mail

It just tells the user you're at a completely different part of the site and it's affiliated with the site, but it's probably a different application entirely. Versus the path like karngyan.com/about which is a part of the site but you're just on a different route.

Nameservers

Because of DNS I can map a domain name to an IP address, so when I type in karngyan.com the DNS resolvers figure out the IP from it. But how do they figure that out?

Nameservers.

There are a lot of servers. The nameserver is the actual entity that keeps that mapping. So whenever you buy a new domain from GoDaddy, Google or one of the big ones. They all have name servers. And that just says hey, this person bought this domain and it's probably not going anywhere but if you need to look it up, I know exactly where that is.

So nameservers are essentially the record keepers of the internet.


Let's do an exercise.

Trace Routes

$ man traceroute
$ traceroute google.com

Traceroute Google.com

Instead of ping, which hits a server that replies back and says hey, I'm alive, Traceroute gives you a map of every single hop along that point. Traceroute gives you a map of every single hop along that point when trying to reach google.com.

I love traceroutes, 'cause:

  1. It makes me look cool.
  2. It helps diagnose network problems.

Traceroute and Ping both run a thing called ICMP requests (Internet Control Message Protocol), instead of TCP. These are health checks of sort.

You can configure your server not to respond to ICMP requests at all. This is what we call blackholing, whereas if you wanna explicitly deny requests, you can say we're not gonna accept that. Blackholing is just saying we're not even gonna respond to your requests.


Packet

It's a little bit of information.

You can think of a packet like an envelope. It's got the address of where you're trying to get to, and it's got information about where you're coming from. Inside a packet, we have information. That's what a packet is, it's just this base unit of information of how everything's transmitting.

For example right now when you opened this blog, it's not just one packet but it's trillions of them and often using TCP. It starts with one and it says, hey I've got one but there's 50 more of my cousins coming along too. And that's why TCP is called error correcting because it has all these packets and it says like, hey there's 50 packets. And the client says, hey I got all of them except for three. I'm missing 28, 42, and 49. The server acknowledges and sends those last three packets.


Ah! Alright for a noob you know enough now. Let's recap a bit.

Q: How does the internet work?

  • Internet runs over TCP/IP, which is a protocol that everybody agrees on.
  • On that protocol, are packets. There's different kind of packets.
  • And all this runs on a series of trust, and trust means that if I send you this packet I guarantee you're gonna hand it off to the next guy.
  • We know that if we type a domain in to the browser, that gets resolved by the name servers using the DNS system and that resolves to a server somewhere.

Not bad, we know how the internet works.


Politics

Now it is necessary to know about a little bit of the politics going around the internet. Net neutrality means that ISPs can start charging your data depending on where it's going.

So that's the debate about net neutrality:

Should the ISPs be just dumb pipes, that if I send a letter it just gets there or should they start prioritizing traffic, based on how much someone pays them.

But you know what, internet is just a series of tubes.

And about the answer I gave to my interviewer. I said, "It's a series of publicly interconnected devices". He said, "Elaborate!"

Hope you had a good time reading it. Have a good day. :)