When you’re preparing for a software engineering interview, one common question you might encounter is “What happens when you enter a URL into a browser and press enter?” In this article, we’ll provide an in-depth answer to this question as explained by a Senior Software Engineer.
If you’re asked this question in an interview, the person interviewing you is likely probing the depth of your knowledge. Candidates with varying degrees of experience will answer this question differently, as they will go as deep as their knowledge takes them.
The browser goes through a series of steps to retrieve and display the requested content.
- The browser first attempts to resolve the domain with an
IPaddress by looking up the domain in the browser’s
- If the first step doesn’t return an
IPaddress, the browser will look up the
DNSrecord in your operating system’s cache. Many operating systems allow you to define the
IPaddress of a
DNSserver that you would want to use, the browser will then use your cache or that defined
IPaddress to attempt to resolve the domain name.
- If the second step fails and the domain still isn’t resolved, it will fall back on your router’s
- If the third step fails as well, and your ISP can’t resolve the domain name, it will fall back on different
DNSservers to try and find the
- Once the domain has been resolved to an
IPaddress, the browser will initiate a
TCPconnection with the server using a
TCP/IPhandshake. The handshake will exchange a synchronize and acknowledge message to establish a connection.
- Once the
TCPconnection is established, the browser sends an
HTTP GETrequest to the web server.
HTTPRequest will contain additional information, for example a user agent and accept Headers.
- If the URL requires authentication, a token / key may be passed in the request.
- The server will then handle the request and send back a response.
- Responses usually contain what’s required for the browser to render the required resource.
- Depending on the load of the server you’re requesting, you may initially meet a load balancer – a small script that knows what servers are available to do the work, and how to route messages to these servers.
- The browser will then display the content for the requested resource by parsing the
HTMLor text and loading