What happens when you type https://www.google.com in your browser and press Enter?
This has been for a while a common interview question for roles pertaining software engineering. It still is, they say.
Full disclosure: This is part of the curriculum of The ALX Software Engineering program, that is why I cannot personally confirmed to have been asked this question in an interview. This should not make you cast any aspersions into the content of this blog post as I have been well equipped to answer it. Plus its 2023 the internet is full of resources including the recent AI tools you can ask the question and it will give a pretty good reply.
That said back to the "classic" interview question. What happens when you type https://www.google.com in your browser and press Enter?
There is much that goes on behind the scenes after you hit enter and when you get the results displayed on your browser. Even as you press each key stroke there are several activities that your device undertake be it a physical keyboard or a touch screen. This is where Electronics Engineering and Software Engineering fuse together you may say. Most electronic/computer devices run in a cyclic manner in very high frequencies the human eye cannot perceive. The operating system (Windows, Linux based, IOS, android, etc) are the main running programs with so many helper scripts/programs to handle different activities. An example is interrupt handlers that listen if there are interrupts like buttons being pressed. So yes every keystroke in itself triggers a number of activities that ends up displaying the characters in the appropriate area on the screen.
In a nutshell browsers are applications used to retrieve information from remote servers to the local machine. For this to occur, a connection has to be established between your local device with the remote server. And for seamless communication, a number of factors need to be taken into account. Such factors include; reliability, speed, integrity of the information shared, etc.
For everything we are going to talk about to make sense, there are important terms that we need to define.
Now that we have an idea what these terms mean, we can start on the journey of retrieving https://www.google.com.
The browser’s first mission is to obtain the IP address of the domain entered, it first looks in its cache, if its available it proceeds to the next step, if its not available it sends a request up depending on how its connected to the internet.
领英推荐
After obtaining the IP address, the next step is to establish a TCP connection.
To establish a TCP connection, the browser sends a SYN (synchronize) packet to the server. The SYN packet contains a sequence number, which is a unique number that is used to identify the connection.
The server responds to the SYN packet with a SYN-ACK (synchronize acknowledgment) packet. The SYN-ACK packet contains the server's sequence number and an acknowledgment of the browser's sequence number.
The browser then sends an ACK (acknowledgment) packet to the server. The ACK packet acknowledges the server's sequence number.
Once the three packets have been exchanged, the TCP connection is established.
The next step is to make the connection secure.
To establish a secure connection, the browser and server exchange certificates. A certificate is a digital document that contains the public key of the device. The public key is used to encrypt the data that is transmitted to the device.
Once the certificates have been exchanged, the browser and server can start exchanging data. The browser will encrypt the data before it is transmitted to the server, and the server will decrypt the data before it is sent to the browser.
Now if the if the domain we are accessing (in this case google.com) uses a single server, then the requests would be handled by the server. But in a case where there are multiple servers as is the case for google, there is a load-balancer in place that will then depending on the configured algorithm determine which server to send our request.
The web server (which are protected by firewalls) that receives the request then sends the request to the web application which in turn does any processing required as per the received request, generates the html code and sends it back to the web server. The web application retrieves and writes to a database as required.
The web server then sends back the html to the browser either through the load-balancer or directly performing all the necessary encryption to secure the data sent.
The browser after receiving and confirming that all the packets were received renders HTML code and displays googles home page.