alex / alex/what-happens-when

What happens when you type google.com in your browser and press Enter?

Aperta
#1,109 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Nessun dato sulla lingua
Stelle
43.3k
Fork
5.7k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

When you type google.com in your browser and press, Enter, many things are going on in the background before Google’s homepage is displayed on your screen. Sure, it happens in milliseconds, but a lot happens under the hood.

In this piece, I will take you through the networking side of the process to give you a little bit of an understanding of what goes on under the hood.

Brief Introduction to a Browser

The URL(Uniform Resource Locator) that you type, which in our case is ‘google.com,’ is typed on a browser. A browser is a software application that gives you access to information on the World Wide Web. You can think of it as an intermediary between you and the Internet that helps you navigate websites and interact with various online content.

Browsers include programs such as Google Chrome, Microsoft Edge, Safari, and Opera. Once you press enter, the browser recognizes ‘google.com’ as a domain name and seeks to match it to the correct server to serve you with the right content.

DNS Request

Just like humans have names to differentiate one person from another, computers use IP addresses for identification. Therefore, after pressing enter, the first step is to convert the text into an IP address. This step has a successive procedure.

1. The browser looks into its cache to see if it has a record matching the domain name to its IP address. If it has the record, the browser uses the IP address to send a request to the server. If the browser does not have the record, it forwards the look up to the computer’s operating system(OS).

2. If the OS does not have the record in its cache, it forwards the request to the resolver.

3. The resolver is usually your ISP (Internet Service Provider). All resolvers know where they can locate the root server. If the resolver does not have the record in its cache, it forwards the resolution request to the root server.

4. A root server is one of the 13 authoritative name servers that respond to DNS queries by referring the resolver to the appropriate top-level domain server. Top-level domains (TLDs) include .com, .org, .ke, and .uk. The resolver then stores the IP address for the appropriate TLD, which in our case, is the “.com” TLD that is given by the root server.

5. At this point, the resolver forwards the DNS resolution request to the TLD server. In response, the TLD server provides the IP addresses of the authoritative name servers.

6. The name servers then relay the IP address of the DNS request. The resolver stores this information in its cache for later use.

7. The resolver then responds to the OS query, forwarding a response to the browser.

8. The OS and browser cache this information to enable a quicker resolution time for future requests. The TTL (Time To Live), the length of time a DNS record can be cached, is configured by the domain owner or determined by the authoritative name servers.

TCP/IP

Now that the browser has an IP address, it must create a connection to the server that matches the IP address to facilitate communication and data exchange. There are various protocols to facilitate data transmission and processing on the Internet. However, most HTTP requests use TCP.

TCP (Transmission Control Protocol) ensures reliable and ordered data transfer between devices through data packets. Data packets are smaller data units that are easier to transmit and process. TCP is highly preferred for HTTP requests as it has additional features such as flow control, error detection, and retransmission of lost packets.

IP (Internet Protocol) is responsible for assigning a unique address to each device on the Internet for ease of identification. It also ensures the packets are encapsulated, addressed, and routed appropriately across the networks.

The TCP/IP connection is established in a three-way handshake.

1. SYN(Synchronize)

Your computer, which is the client machine, sends a packet containing a sequence number to the server. This step indicates the intention of the client machine to establish a connection.

2. SYN-ACK(Synchronize-Acknowledge)

Upon receiving the SYN packet, the server checks whether it has open ports to accept and initiate new connections. If there are open ports, it responds with a SYN-ACK packet. This packet has two crucial parts. First, it acknowledges receipt of the SYN packet by confirming the sequence number. Second, the server includes its sequence number to signify its readiness to establish a connection.

3. ACK(Acknowledgement)

Upon receiving the SYN-ACK packet, the client machine responds with an ACK packet. This packet acknowledges receipt of the SYN-ACK packet and confirms the server’s sequence number.

After the three-way handshake, a connection is established, and the devices can reliably exchange data.

At this point, the browser sends a GET request asking for a google.com web page over the established TCP connection. The server receives the request and responds with the HTML code for the homepage of google.com. The browser will display the HTML skeleton, and if the web page requires additional resources, the browser sends out more requests. These additional requests can be for elements such as images, Javascript files, and CSS stylesheets.

Firewall

A firewall can either be a physical device or software that acts as a barrier between an internal and external network. Firewalls monitor and control incoming and outgoing network traffic based on predefined security regulations. In doing so, they protect the network from potential threats and unauthorized access.

Firewalls examine network packets and apply predefined rules to determine whether to allow or block them. These security rules are based on various criteria, such as;

Allowing or blocking network traffic based on the following;

· Source and destination IP address.

· Port numbers

· Characteristics of the packet content.

When the browser requests Google’s server for the web page, Google’s firewall checks the incoming request. If the request meets the predefined security rules, it is allowed, and a response is generated. Otherwise, it is blocked if the request does not meet security standards.

HTTPS/SSL

HTTP is a protocol used to transmit data over the Internet. It handles the communication between the browser and server in the form of requests and responses. As the name suggests, HTTPS(Hypertext Transfer Protocol Secure) is a secure version of HTTP. By secure, we mean that the data transmitted over HTTPS remain confidential and cannot be tampered with or intercepted by attackers.

A cryptographic algorithm is used for encryption which can either be SSL(Secure Sockets Layer) or TLS(Transport Layer Security) to achieve security in HTTPS. These layers of security are acquired from trusted Certificate Authorities, such as LetsEncrypt, as a certificate. When a website has this certificate, a small padlock icon is seen on some browsers’ search bar while others turn green. This encryption means the data transmitted is unreadable to any other person or machine. Only the browser you are using and the server can decrypt the data.

Load-balancer

A load-balancer is a networking device or software that distributes incoming network traffic across various servers to optimize efficiency and improve reliability. In our case, for instance, Google receives many requests to access its webpage. As such, they cannot operate on one server. They will require multiple servers that can handle the requests and responses. Hence, minimize their SPOF(Single Point of Failure).

Load balancers manage the servers and know which server will handle which request. A load balancer evenly distributes the workload across the various servers following a load-balancing algorithm. For instance, HAproxy is one of the most famous load balancers that can be configured with a round-robin algorithm. With such a configuration, a request is sent to one server and then the next until all servers handle a request, and the cycle continues.

Web Server

Once the load-balancer distributes the request, it goes to the web server. Web servers are software that serves web content upon request. Web content includes web pages, images, and files, among other resources. Web servers include programs such as Nginx, Apache, and Microsoft Internet Information Services.

Upon receiving the request from the load balancer, the web server responds with appropriate resources, which are forwarded to the load balancer and ultimately to the browser.

Application Server

Web servers handle static content, but you might want to interact with the website in most cases. In our case, when you type google.com, you most likely want to continue to search for other things on Google. Application servers handle this interaction.

An application server handles dynamic content, including managing user information, communicating with databases where necessary, and operating applications.

Therefore, after the web server receives a request, if the request is an interaction, it forwards it to the application server. If the application server can respond to the query, it generates a response and forwards it to the web server. If the application server cannot generate a response as it requires additional information, it forwards the request to the database.

Database

A database is a collection of well-organized and stored data to allow efficient retrieval, modification, and addition of data. There are various models of databases. The main ones are relational databases such as MySQL and PostgreSQL and non-relational databases such as MongoDB and Cassandra.

You require a DBMS(Database Management System) to access a database. DBMS is software that has tools and functionalities for creating, deleting, adding, querying, and administering a database.

When the application server needs additional information, it forwards the request to the DBMS. The DBMS interacts with the database and responds to the application server. The application server, in turn, responds to the web server, which responds to the browser.

After receiving the necessary resources, the browser renders the whole page.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.