Woodstock Blog

a tech blog for general algorithmic interview questions

[CC150v4] 17.1 Type a URL in Browser and Hit Enter

Question

17.1 Explain what happens, step by step, after you type a URL into a browser Use as much detail as possible.

Short Answer

  1. Browser contacts the DNS server to find the IP address of URL
  2. DNS returns back the IP address of the site
  3. Browser opens TCP connection to the web server at port 80
  4. The browser sends a GET request to the server, asking for the file
  5. Browser fetches the html code
  6. Browser renders the HTML in the display window
  7. Browser terminates the connection when window is closed

ref

More Details

Phase 1:

  1. browser checks cache; if requested object is in cache and is fresh, skip to Phase 3 #4
  2. browser asks OS for server’s IP address
  3. OS makes a DNS lookup and replies the IP address to the browser
  4. browser opens a TCP connection to server (this step is much more complex with HTTPS)
  5. browser sends the HTTP request through TCP connection

ref

Phase 2:

  1. That computer receives the HTTP request from the TCP/IP connection and passes it to the web server program.
  2. Web server reads the hostname and path and finds or generates the data that you’ve asked for.
  3. Web server generates an HTTP response containing that data.
  4. Web server sends that HTTP response back down the TCP/IP connection to your machine.

ref

Phase 3:

  1. browser receives HTTP response and may close the TCP connection, or reuse it for another request
  2. browser checks if the response is a redirect (3xx result status codes), authorization request (401), error (4xx and 5xx), etc.; these are handled differently from normal responses (2xx)
  3. if cacheable, response is stored in cache
  4. browser decodes response (e.g. if it’s gzipped)
  5. browser determines what to do with response (e.g. is it a HTML page, is it an image, is it a sound clip?)
  6. browser renders response, or offers a download dialog for unrecognized types

Miscellaneous:

Each domain name server is divided into zones A single server may only be responsible for knowing the host names and IP addresses for a small subset of a zone, but DNS servers can work together to map all domain names to their IP addresses That means if one domain name server is unable to find the IP addresses of a requested domain then it requests the information from other domain name servers

The firewall will control connections to & from your computer. For the most part it will just be controlling who can connect to your computer and on what ports. For web browsing your firewall generally won’t be doing a whole lot.

Your router essentially guides your request through the network, helping the packets get from computer to computer and potentially doing some NAT (Network Address Tranlator) to translate IP addresses along the way (so your internat LAN request can be transitioned onto the wider internet and back).

Even more

An even more detailed article can be found here. And a __great step-by-step example using facebook.com can be found here.