What happens when you type google.com in your browser and press Enter?
Renish Okago
Software engineer || Frontend Developer || JavaScript || Tailwindcss || React js
An interesting topic, right? Some of you might say, it's simple, a google website page pops up, duh. ?Off-course you are right. Well, everybody knows what kind of result it gives us, but few know how it works under the view of the screen! Ready to find out what happens? Let's get started!
INTRODUCTION TO HOW THE WEB STACK WORKS
We use the internet for almost everything in the digital era. But does it work magically? And the web pages we see in that rectangle machine must come from somewhere. So how is it all happening? What is happening under the hood between the moment we enter a URL (Uniform Resource Locator) in the search bar and the moment we receive the content of the desired page?
Like making a call that needs a receiver or someone to pick the phone up, we also need some kind of responder from the google side for that webpage, and we call it a server. A server is nothing more than a computer. So, in this case, our computer is a client, and the google ‘computer’ is a server. But this is not merely what happens when you type ‘www. google. com’. There are many other layers between the client and the server in a client-server model, let’s break it down.
1. The DNS Server
When we type the URL www. google. com into our browser (could be Google, Firefox, Safari, et cetera) and press ‘Enter’, the first thing that the browser is going to do is break down the URL in pieces. The browser is going to consider the google. com part first, which is a domain name. To understand what a ‘domain name’ is, first we need to know what an ‘IP address’ is. IP - Internet Protocol.
Considering our previous example, an IP address works the same as a phone number. The same way one requires a specific number to call a specific person is the same thing as IP addresses, they have a specific format. There should be four numbers, from 0 to 255 separated by dots, like this, 100.59.90.224. And different websites have different IP addresses. As you can see, it is already getting difficult to memorize the IP addresses. Imagine we have to search websites with IP addresses. The good news is we have the domain name to our rescue. ?Like you save your friend’s phone number in your contact with a name you want to, domain names are alphabetic representations for IP addresses. The reason we have domain names in the first place is that humans remember words better than numbers. Thankfully, the DNS is here for us to remember the IP of each domain. If the browser doesn’t know that domain name (it’s not stored in its cache), it is going to ask the Domain Name System for the IP address corresponding to this particular domain name.
The DNS request first goes through the resolver. The resolver is usually our Internet Service Provider, and if it doesn’t find the IP in its cache, it’s going to request the root server. The root server knows where the TLD (Top-Level Domain) server is. In our case, the top-level domain is .com. Other types of TLD are .net, .fr, etc. If the TLD server doesn’t know the IP, it points the resolver to the Authoritative Name Servers for the domain name. Usually, there is more than one name server attached to one domain name. But any of those name servers can give the IP for the domain name they are attached to. Now the resolver has the IP address (for example, 54.172.4.191), and can send it back to the browser which will perform its request to the corresponding server.
2. Protocols: TCP/IP
The?Transmission Control Protocol (TCP)?is a transport protocol that is used on top of IP to ensure the reliable transmission of packets. It’s a set of rules that define how servers and clients interact over the network, and how data should be transferred, broken into packets, received, etc.
3. Firewall
A firewall is a network security device that monitors incoming and outgoing network traffic and decides whether to allow or block specific traffic based on a defined set of security rules.
To protect themselves from hackers and attacks, servers are often equipped with a firewall. A firewall is software that sets rules about what can enter or leave a part of a network. In the case of our example, when the browser asks for the website at the address 230.56.109.36, that request has been processed by a firewall which will decide if it’s safe, or if it’s a threat to the server’s security. The browser itself can also be equipped with a firewall to detect if the IP given by the DNS request is a potential malicious agent.
4. HTTPS/SLL (Security & Encryption)
HTTPS stands for HyperText Transfer Protocol Secure and is a secure version of the regular HTTP. Now that the browser has the IP address, it is going to take care of the other part of the URL, the https:// part. This transfer protocol defines different types of requests and responses served to clients and servers over a network. In other terms, it’s the main way to transfer data between a browser and a website. HTTP and HTTPS requests include GET, POST, PUT, and others. The HTTPS requests and responses are encrypted, which ensures the users that their data can’t be stolen or used by third parties. For example, if we put our credit card information on a website that uses HTTPS, we are guaranteed that this info is not going to be stored in plain text somewhere accessible to anybody.
SSL stands for Secure Sockets Layer (also known as TSL, Transport Layer Security). The certificate needs to be issued from a trusted Certificate Authority, like the famous Let’s Encrypt for example, which gives free SSL certificates. When a website has this certificate, we’re able to see a little lock icon next to the website name in the search bar. On some browsers and with certain types of SSL certificates, the bar turns green.
领英推荐
5. Load Balancer
A load-balancer is a software program that distributes network requests between several servers, following a load-balancing algorithm. HAproxy is a very famous load-balancer, and example of algorithms that we can use are the round-robin, which distributes the requests alternating between all the servers evenly and consequentially, or the least-connection, which distributes requests depending on the current server loads.
?For most websites where the traffic is consequent, it would be impossible to be hosted on a single server. Plus, it would create a Single Point of Failure (SPOF), because it would only need one attack on the said server to take the whole site down. As the need for higher availability and security rises, websites started augmenting the number of servers they have, organizing them in clusters, and using load balancers.
6. Web Server
Once the requests have been evenly distributed to the servers, they will be processed by one or more web servers. A web server is a software program that serves static content, like simple HTML pages, images, or plain text files. Examples of web servers are Nginx and Apache. The web server is responsible for finding where the static content corresponding to the address asked for is living, and for serving it as an HTTP, or HTTPS response.
7. Application Server
Having a web server is the basis of any web page. But most sites don’t just want a static page where no interaction is happening, and most websites are dynamic. That means that it’s possible to interact with the site, save information on it, log in with a username and a password, etc.
This is made possible by the use of one or more application servers. These are software programs responsible for operating applications, communicating with databases, and managing user information, among other things. they work behind web servers and will be able to serve a dynamic application using the static content from the web server.
8. Data Base
The last step in our web infrastructure is the Data Base Management System (DBMS). A database is a collection of data, and the DBMS is the program that is going to interact with the database and retrieves, adds and modifies data in it.
There are several types of database models. The two main ones are relational databases and non-relational databases. A relational database can be seen as a collection of tables representing objects, where each column is an attribute, and each row is an instance of that object. We can perform SQL (Structured Query Language) queries on those databases. MySQL and PostgreSQL are two popular relational databases. A non-relational database can have many forms, as the data inserted in it doesn’t have to follow a particular schema. They are also called NoSQL databases.
Conclusion
When we type a URL in a browser, it takes only microseconds for all the agents we talked about to form a response and serve it to the client. Even knowing what is happening behind the monitor, it is still pretty magical to see it happening before our eyes.
Thanks for reading hope you learned something new!
publisher:
Melvin Renish.