What Happens When You Enter a URL into a Browser? Interview Question Answered by a Senior Software Engineer

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 IP address by looking up the domain in the browser’s DNS cache.

If the first step doesn’t return an IP address, the browser will look up the DNS record in your operating system’s cache. Many operating systems allow you to define the IP address of a DNS server that you would want to use, the browser will then use your cache or that defined IP address 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 DNS entries.

If the third step fails as well, and your ISP can’t resolve the domain name, it will fall back on different DNS servers to try and find the IP address.

Once the domain has been resolved to an IP address, the browser will initiate a TCP connection with the server using a TCP/IP handshake. The handshake will exchange a synchronize and acknowledge message to establish a connection.

Once the TCP connection is established, the browser sends an HTTP GET request to the web server.

The HTTP Request 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 HTML or text and loading CSS and JavaScript resources.

Here is a recent blog post on the subject by Abhishek Saha