What happens when you type google.com in your browser and press Enter?
Published: 2024-05-13 01:49:11

_It takes you to the Google search home page!_

---
It is way more than that. A lot of things are going on in the background before the browser can render the search page. This article aims to demystify what happens in the background before the requested resource is rendered.

**Domain Name Service (DNS) request**
Computers generally communicate with each other over the internet using IP addresses. The computer does not automatically recognize "google.com" as a valid resource address. That is where the Domain Name System (DNS) comes in. The primary function of DNS is to resolve domain names to IP addresses. The DNS servers are of four types, each with its distinct function but all working together in the IP address resolution. They include:

1. Recursive resolver
2. Root nameserver
3. Top-level domain (TLD) nameserver
4. Authoritative nameserver

The process of IP address resolution starts with the browser checking its cache to see if it knows the IP for the domain. In our case, the browser checks if it has the IP for "google.com" in its cache. If it does, then the IP is returned. If it doesn't, the "resolver" comes in.

Recursive Resolver acts as a middleman between the client (our browser) and a DNS nameserver. Similar to the browser, it also checks its cache for the domain and returns it if found, else, it makes a request to the root nameserver for the domain name.

The Root nameserver responds with the address of the Top-level domain (TLD) server for the domain name provider (in our case, for ".COM").
The resolver proceeds to the TLD nameserver, making a request to the .com TLD nameserver. The TLD nameserver responds by providing the authoritative name servers for the domain (google.com).
![Authoritative name servers for "google.com"](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ef9g88ln7jx8qrhrmtia.png)
From the image above, we can see that google.com has four (4) authoritative name servers, each with the ability to resolve the domain "google.com" to its IP address. At this point, the resolver makes a request to any of the Authoritative nameservers (ANS). The ANS is the ultimate source of truth for a domain's DNS records which returns the IP address for the domain.

**TCP/IP**
With the IP address at hand, the browser can now initiate communication with the server, in our case, "google.com". This is done through the Transmission Control Protocol and Internet Protocol (TCP/IP). TCP/IP refers to a suite of protocols used by devices to communicate over a network. TCP breaks the messages into packets which are small chunks of the original message. This is to avoid resending the entire message in case of a connection error. Each packet is received and acknowledged by the server and is resent if not received by the server. IP defines the rules and formats by which these packets are exchanged between devices.
The browser uses the Internet Protocol (IP) to define the address of the server, and then uses TCP to securely transport and route packets to the server.

**Firewall**
A firewall is a network security system that monitors and controls incoming and outgoing network traffic based on predetermined security rules. When a request is sent/received by a server, the request is either accepted (allowed) or rejected (disallowed) depending on the firewall configurations of the server. As our browser sends the request to "google.com", the request is first passed through the browser's computer firewall (in a case where it is configured). When it is received by the server (google.com), it also passes through the server's firewall before being processed.

**HTTPS/SSL**
Hypertext Transfer Protocol Secure (HTTPS) is the secured version of the Hypertext Transfer Protocol (HTTP). HTTP is a request-response protocol that allows users to communicate data on the World Wide Web (WWW) and transfer hypertext. It is a protocol that defines how the browser loads web pages and specifies how it responds to specific web requests.

This security comes from the configuration of a Secure Sockets Layer (SSL) on the server. SSL encrypts sensitive information sent across the internet so that only the intended recipient can access it. It provides authentication through a digital certificate known as SSL certificate. It also provides trust as one can be sure that they are sending data to the right server.

So, HTTPS refers to HTTP running over SSL. HTTP/HTTPS relies on a successful TCP connection, after which the browser uses HTTPS to request and handle responses of web resources from the server. In our case, this resource would be the web page to be rendered.

**Load-balancer**
On a server that gets multiple hits like google.com, a load balancer is usually configured to act as a distributor, sharing the workload through a predefined load-balancing algorithm to multiple web servers so that no single web server is overwhelmed with requests.

**Web server**
The primary function of a web server is to host and serve web content over the internet. When our requests reach the web server, the web server responds by returning the requested resources (a web page). It often communicates with the application server if the request requires logical processing.

**Application server**
The application server extends the capabilities of the web server by supporting dynamic content generation, handling business logic and integrating with various resources. In our case:

- The web server sends the request to the application server.
- The application server applies business logic and communicates with the database and other third-party systems to fulfill the request.
- The application server renders a new HTML page and returns it as a response back to the web server.

**Database**
A database stores data for easy retrieval and management. It communicates hand-in-hand with the application server in fulfilling our request.

After the request has been rendered, the response makes its way back from the web server back to our browser. The response is then rendered to us. Hurray!!!

---
That was a long ride, right? When you type "google.com" and press enter, a complex process occurs in the background. This includes DNS resolution, TCP/IP communication, firewall checks, HTTPS/SSL encryption, load balancing, web server processing, application server logic, and database queries. Finally, the requested web page is rendered in your browser. it is quite astonishing that all these happen within a few milliseconds.