What Happens When You Type 'www.google.com' and press Enter.
Tags: webdev, networking, devops, codenewbie
Published: 2023-10-15 19:52:59

Have you ever wondered what happens behind the scene when you enter a URL like 'www.google.com' into your web browser and hit Enter?

The process might appear as though it’s simple, but under the hood, so many complex operations take place to deliver the web page you requested. In this article, we’ll walk through the journey of a web request, explaining in detail each stage from the moment you press enter to the moment you see Google’s homepage.

---

![Schema illustrating the flow of the request created when you type https://www.google.com in your browser and press Enter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lyq1blj08lbmajpdu4ix.png)
*Schema illustrating the flow of the request created when you type https://www.google.com in your browser and press Enter*

Here’s an overview of the things we’ll be discussing during the course of this article;

- DNS Request.
- TCP/IP.
- Firewall.
- HTTPS/SSL.
- Load-balancer.
- Web server.
- Application server.
- Database.

Now, let’s take all these one after the other.

## DNS request.
The moment you enter a website address in your web browser and hit Enter, your browser initiates a Domain Name System (DNS) request. The DNS server’s job is to translate human-readable URL such as 'www.google.com' into an IP address which is how computers identify websites on the internet.

### Why does this have to happen?
Computers identify servers through IP addresses. An Internet Protocol (IP) address is the unique identifying number assigned to every device connected to the internet, they usually look something like this “192.168.123.132”. Imagine having to memorize numerical IP addresses of every single website you visit, a really challenging task given the vast number of websites available. So, that’s where DNS comes in, DNS simplifies the process, allowing you to use user-friendly domain names (which are easier to remember by the way), while it takes care of the translation behind the scenes. Now, let’s take a look at the behind the scenes process.

### The DNS resolution process.
- When you enter a URL like 'www.google.com' in your browser, and press enter, your device sends  a **DNS query** to a local DNS **resolver**.
- The **resolver** checks its **cache** to see if it has the IP address for 'www.google.com'.
- If not, it contacts the **root server**. The root server does not have the specific IP address, but it directs the resolver to the **authoritative name server** for .com **TLD** (Top Level Domain).
- The .com TLD's authoritative name server in turn, guides the resolver to **Google’s authoritative name server**.
- Google’s authoritative name server finally provides the IP address for 'www.google.com' to the resolver.
- The resolver then caches this information on your local system for future use. This way, it no longer has to go through this lengthy resolution process when next you want to visit 'www.google.com'. This also gravely increases speed.

## TCP/IP connection.

After the DNS resolution process, the next crucial step in the journey of a web request is to establish a **TCP/IP** (Transmission Control Protocol/Internet Protocol) connection. This step ensures that there is a **reliable** and **organized** exchange of data between your device and the web server. TCP/IP is the foundational protocol suite of the internet. It consists of two primary protocols;

- **Internet Protocol (IP)** - handles the routing and addressing of **data packets**, ensuring they reach their intended destination.
- **Transmission Control Protocol (TCP)** - manages the orderly and reliable transfer of data.

### What are Data Packets?

In the digital world, data is divided into small units of information called packets, which can be transmitted over the internet. You can picture a packet as letters in the postal service, each one having addresses and content of the letter within the envelope, packets also contain **data** (the data to be transferred) and **metadata** (information such as source and destination IP address, port numbers and sequence numbers).

The process of initiating a connection between your device (client) and the web server (server) involves a **three-way handshake**;
- **SYN (Synchronize)** - the client sends a SYN packet to the server to request a connection.
- **SYN-ACK (Synchronize Acknowledgement)** - the server acknowledges the request by sending a SYN-ACK packet.
- **ACK (Acknowledgement)** - the client then sends back an ACK packet, confirming the connection.

**NOTE:** The above process is to ensure that both parties (i.e client and server) are ready to communicate.

## Firewall.

After the TCP/IP connection, the next crucial layer of defense in the journey of your web request is the Firewall. A firewall acts as a **digital gate keeper**, monitoring and controlling the flow of data packets to protect your device and network from potential threats. It examines data packets to determine whether they should be allowed or blocked based on predefined rules. These rules can include criteria such as source and destination IP addresses, port numbers, and the protocol being used (i.e TCP or UDP).

  Firewalls are also configured with **security policies** which helps determine the level of access and permissions for different types of traffic. Common policies include allowing HTTP (port 80) and HTTPS (port 443) for web browsing, while blocking potentially harmful traffic.

## HTTPS/SSL.

Now, following the firewall’s role in securing your internet connection, another important layer of security is HTTPS (Hypertext Transfer Protocol Secure) and SSL (Secure Sockets Layer). These two technologies work alongside one another to protect the privacy and integrity of data exchanged between the client and the server. HTTPS is a secure version of HTTP which is used to transfer data between the client and the server.

### Why do we need HTTPS/SSL?
 The internet is a very wide and interconnected network where data travels across numerous routes. Some of these routes may not be entirely secure, making it very important to encrypt data so as to protect it from tampering or interception. HTTPS and SSL provides the encryption needed to transfer data over the network.

**NOTE:** SSL provides the encryption and secure connection used in HTTPS.

To establish trust and verify the identity of a web server, HTTPS uses **digital certificates** (SSL certificates). These digital certificates are issued by trusted Certificate Authorities (CAs). Examples of CAs include **Comodo**, **GeoTrust**, and **Symantec**. So, when you visit an HTTPS-enabled website, your browser checks the digital certificate to ensure it is valid and signed by a trusted CA.

## Load-balancer.
Once a secure connection has been established between the client and the server through HTTPS/SSL, the next step in the journey of your web request is often managed by load-balancers. Although this part is not always in play because load-balancers are meant to improve performance, and enhance the reliability of web services, which might not be needed for a website with very little traffic. But for a big company like Google, it’s a very important aspect because as websites and web applications grow in popularity, they often experience a significant increase in traffic and this can strain a single web server's capacity and lead to performance issues or even downtime.

  Load balancers address these challenges by efficiently distributing incoming requests among multiple servers, preventing overloads, and improving responsiveness. Now, the client request is sent to the load balancer, which in turn directs this request to one of Google’s web servers for further processing of the request.

## Web server.

A web server is specialized software or hardware that listens for incoming HTTP or HTTPS requests from clients, such as web browsers. Web servers are a very essential component of the web infrastructure. They are responsible for receiving and responding to client requests, serving web pages, and processing dynamic content, etc.

When a client's request arrives at the web server, the server identifies the requested resource, whether it's an HTML page, an image, a script, or any other web content.
The web server retrieves the resource from its storage (if it's a static content) or generates it dynamically by executing scripts or querying databases (if it's a dynamic content). Then based on the request made, it sends whatever content requested back to the client (as a response) for display in the browser. All these sending of data back and forth (from client to server and back) occurs through either HTTP or HTTPS (since web servers can handle both unencrypted HTTP requests and secure, encrypted HTTPS requests).

### There are various types of web server solutions, these two are the most popular.
- **Apache HTTP Server:** An open-source and widely used web server.
- **Nginx:** Known for its performance and scalability, often used as a reverse proxy server in combination with Apache.

## Application server.

Application servers are specialized software or frameworks that handle dynamic, data-driven web applications, providing the **logic** and **functionality** required to serve complex web services.

### Roles of an application server.
- Application servers execute the business logic of web applications. This includes handling user authentication, managing sessions, processing form submissions, and enforcing security policies.
- They interact with web servers to process client requests, generate dynamic content, and communicate with databases and other resources.
- Application servers play a crucial role in the development and delivery of dynamic web applications. These applications generate content on-the-fly, responding to user interactions, database queries, and various forms of input.
- They also expose **API endpoints** that allow external services, web applications, or mobile apps to interact with the system. These APIs are crucial for data exchange and integration.

So, basically, after the web server's role in delivering static and some dynamic content, the application server's role is to generate dynamic responses, process complex business logic, and deliver interactive and data-driven web applications.

## Databases.

Databases are key foundational components of modern web applications, responsible for the secure storage, retrieval, and management of data. After the application server's role in presenting dynamic web applications, the journey of your web request takes an important step by interacting with a database. Databases are used to persistently **store data**, such as user profiles, content, transaction records, etc.

### Most common types of databases.

- **Relational databases** (also known as SQL databases) - they use tables to organize data into rows and columns. They are excellent for structured data and transactions.
- **Non-relational databases** (also known as NoSQL databases) - are designed for unstructured or semi-structured data. They are often used for flexible data storage.

Basically, after the application server processes dynamic content, databases store and manage the data required to drive web applications, making them essential for applications ranging from e-commerce websites to social media platforms and beyond.

## Conclusion.

The seemingly simple act of typing a URL and pressing Enter involves a beautiful and remarkable journey through various stages of internet technology. From DNS translation to security protocols, load balancing, and server-side processing, each step contributes to the seamless experience of accessing the web.

Now that you understand this process, I hope you can now appreciate the complexity that goes into serving the web pages we use daily 🤗.

Thanks for reading, cheers ✨🎉.