What Happens When You Type google.com in your Browser and Press ENTER
Check this out. Ever wondered what happens in the background whenever you type something like “google.com” or like https://onirele.tech in your Uniform Resource Locator (URL) bar of your browser and press ENTER on your computer keyboard? If the details around this background process are either unclear or you’re familiar with the basics, this article is for you. The last two decades have seen the world better connected through the internet compared to the preceding decades. This means that more people now refer to the internet to access information or leverage software tools to solve tasks previously solved by humans. Therefore, as an technocrat (engineer, developer etc.) or user of the internet, it is imperative that you do have a good understanding of what goes on behind the hood of your browser when you type something like https://onirele.tech in your browser.
In this article, we shall go through what happens when you type a URL into your browser and press enter, the end to end processes between your browser and the server plus your operating system to ultimately display that web page. However, before we can proceed, let us go over some common terminologies used in this process.
A webpage is just a text file with certain formatting applied so that it can be read by your browser, such as Chrome, Firefox, Safari, etc. This formatting could be in the form of HyperText Markup Language (HTML), Portable Document Format (pdf), Cascading Style Sheets (CSS), Javascript, images etc.
A Server - The files mentioned above are stored on computers (servers) that provide functionality to other programmes or devices called “clients”. The functionality provided includes storing the above files and serving them to the client when requested for. Servers can vary in classes; web servers, application servers and database servers.
Uniform Resource Locator (URL) – used to uniquely identify a resource over the web.
A client is any tool that acts on the user’s behalf. On most modern computers, this role is performed by browsers but can also be performed by specialised applications used by software engineers while working with codebases.
Web server?- is computer software with underlying hardware that connects to the Internet and supports physical data interchange with other devices connected to the web.
Client requests?- queries sent to the server by the client.
Domain Name System (DNS)?– Is like the address book of websites. When you type a web address the DNS is looked at by the browser to identify the web address based on a unique Internet Protocol (IP) address.
Internet Protocol address (IP)?– is a set of four numbers within a range of 0 to 255 separated by periods such as 192.0.2.1. The IP address belong to a computer (server) and is used for either network interface identification and location addressing.
HyperText Transfer Protocol (HTTP)?- a stateless protocol for retrieving resources such as HTML documents. It is the basis of all data exchange on the web and it is a stateless client-server protocol. This means requests are initiated by the recipient, usually a web browser and once responded to by the server are not kept in memory.
Load balancer?-?is any software or hardware device whose main goal is to distribute network or application traffic across many servers. They aim to increase reliability, efficiency and availability of a website or enterprise application.
Application server?- a type of server designed to install, operate and host-associated services and applications for the IT services, end-users and organizations.
Database?- is an organized collection of structured information, or data, typically stored electronically in a computer system.
Database Server – These hold the above database and can be updated, and consulted upon to carryout various CRUD operations. To learn more about CRUD operations, refer to this article.
Firewall?- ?is a networking and security terminology commonly used to refer to a set of preconfigured rules to manage incoming and outgoing network traffic between two networks.
Internet?- the Internet is a vast network that connects computers all over the world.
Internet Service Provider (ISP)?- an organization that provides services for accessing, using, or participating in the Internet.
Resolver?- a set of dynamic library routines used by applications that need to know machine names.
Transmission Control Protocol (TCP)?- a?connection-oriented?protocol that means it establishes the connection before the communication that occurs between the computing devices in a network. This protocol is used with an IP protocol, so together, they are referred to as a TCP/IP.
What Actually Happens…
Back to the question at hand, what happens when you type www.google.com or any other URL (Uniform Resource Locator) in your web browser and press Enter? In summary after the enter key is pressed on your keyboard, a switch is closed and current flows into a small chip to generate a scan code which is transferred to the operating system of your computer. The scan code is thereafter converted to an ASCII or Unicode character based on the key pressed and ultimately an event is created based on the application currently open at the time the key was pressed. In our case the browser.
This event kick starts a chain reaction that starts with the browser parsing the content currently contained in the URL, locating the server hosting the website, connect to it, sending a request to retrieve a certain page, managing the server's response, and handling how the page is shown to you, the viewer that may interact with the website. This article will not focus on the details of the processes behind the pressing of the ENTER key. If you are inquisitive you can read more about it here For this article we shall for go through steps your browser takes to;
1) Parse Content in the URL
Once the browser parses the content in your URL, you will have something similar to this below;?
From the above image, the protocol is a scheme belonging to Hypertext Transfer Protocol Secure (HTTPS) to enable secure exchange of encrypted data across the internet using other secure protocols like SSL (Secure Sockets Layer) and TLS (Transport Layer Security), a domain name to represent a IP address of the server to connect to, the path to the web page resource file you are requesting for and lastly a subdomain which is basically belongs to the root of the domain. So for the emphasis of our article, guess what each field stands for in www.google.com You can read more about HTTPs, SSL, TLS, domains and subdomains through these links; https://www.instantssl.com/http-vs-https and https://landingi.com/help/domains-vs-subdomains/ ?Once the browser has parsed the content in the URL address box and validated it, it will go ahead and locate the IP address of the server corresponding to the domain name.
2) Browser Looks Up IP Address for the Domain
Time to look for that IP Address of the server corresponding to the domain name in the URL address box. To do this, the browser uses a DNS Look up. Since DNS look process is a complex process we shall go over it at a high level. You can read about how the DNS works here. The DNS Look up does a recursive search from DNS server to DNS server until the IP address corresponding to a domain name is found. This recursive search starts with your browser checking its cache to see if this website has been visited before and if it knows its IP address. If the IP address for the requested URL is not found, the browser asks the operating system to find the website. The first place the operating system looks for the address of the specified URL is the hosts file /etc/hosts in Linux and Mac OS, c:\windows\system32\drivers\etc\hosts in Windows. If the URL is not found in this file, the operating system makes a DNS query to find the website's IP address. The first step is to ask your resolver (or ISP) server to check its cache to see if it recognizes your IP address. If the resolver doesn't know it, then it asks the root server to ask the top level domain (.COM TLD) server like in the image below. If the URL ends in .net, the TLD server will be .NET, etc. (refer to image below) - the TLD server will check its cache again to see if the requested IP address exists. At least one of the authoritative name servers is usually associated to the URL, and after that will go to the name servers and the IP address associated with the URL is returned.
领英推荐
But one could ask a question, of why not just use the IP Address of the server directly instead of going through the hustle of the above DNS Look up process. Well, that could be effective but how many numerical IP addresses containing different sets of numbers (192.0.2.1) would you have to recall for regularly accessed websites? It is just easier to recall names of websites in text based form than numbers and that is where the DNS comes in handy to map the correct text based domain name to its corresponding IP Address.
Note that under scenarios, when the browser neither detects a valid scheme nor a valid domain name, it redirects the content in the URL address box to its default search engine.
But that a story for another time. So the browser has got hold of the corresponding IP address of the serve to the domain name, what next?
3) Browser Initiates TCP Connection with the Server
Once the browser has the correct IP address, it establishes a connection with the server matching that IP address to transfer information. Your browser uses Internet protocols to establish such connections. There are several Internet protocols available, but TCP is the most commonly used protocol for many types of HTTP requests. If HTTPs is being used, a TLS or SSL handshake takes place to secure the communication. This handshake is a three-step process where the client and the server exchange SYN(synchronize) and ACK(acknowledge) messages to establish a connection.
After the successful completion of the above three steps, the browser can establish a data transmission connection with the server.
4) Browser Sends the HTTP Request to the Server
Now that the browser has a connection to the server, it follows the rules of
communication for the HTTP(s) protocol. It starts with the browser sending an
HTTPS request using a GET request to the server to request the contents of the
page. If you’re entering credentials or submitting a form, this could be a POST
request. The HTTP request contains a request line, headers (or metadata about
the request), and a body. The request line contains information that the server
can use to determine what the client (in this case, your browser) wants to do.
The request line contains the following:
Here’s an example of the full request for the URL, with the request line and headers (no body since this is a GET):
If you’re curious about what’s going on behind the scenes, you can use tools such as curl for those using Linux distributions to take a look at HTTP requests.
On its way (HTTPS Request) to the server, the request is checked by both the operating system and the server's firewall to make sure that there are no security violations.
5) Server Processes Request and Sends Back a Response
And upon receiving the request and based on the info in the request line, headers and body, the server (usually a load balancer that directs traffic to the available server for that website). Load balancers are an interesting area of study and you can read more about them here. The Load balancer sends a response with the IP Address of the chosen server along with the SSL (Secure Sockets Layer) certificate to initiate a secure session (HTTPS). The chosen server contains a web server (i.e., Apache, Nginx etc) that receives the request from the load balancer and passes it to a request handler to read and generate a response. The request handler is a program (written in ASP.NET, PHP, Ruby, etc.) that reads the request, its’ headers, and cookies to check what is being requested and also update the information on the server if needed. Then it will assemble a response in a particular format (JSON, XML, HTML). The response contains the following:
The status line contains both the HTTP version and a numeric and text representation of the status of the request. The response looks like this:
6) Browser Renders the Content
The browser displays the HTML content in phases. First, it inspects the response headers for information on how to render the resource. The?Content-Type?header above tells the browser it received an HTML resource in the response body. A bare bone HTML skeleton will be rendered from the first GET request. Then it will check the HTML tags and send out GET requests for additional elements on the web page, such as images, CSS stylesheets, JavaScript files, etc. These static files are cached by the browser, so it doesn’t have to fetch them again the next time you visit the page. In the end, you’ll see google.com appearing on your browser. That’s it!
I hope this short article has given you a better understanding of everything that happens "under the hood" when you type www.google.com in your browser and press ENTER.
Thank you for reading!