A while ago, I was interviewing for an engineering role and the recruiter asked me the question: can you explain how an HTTP request is processed? 🤔 I thought that was an interesting question because it wasn’t the typical question about traversing a binary tree or optimising a search algorithm. I had to take a moment to reflect on my CS knowledge.
Let’s dig into how this works to get a better understanding of what happens from the moment you type a URL in the address bar of your browser, to when you get a response. It is noteworthy to highlight here that this entire process touches on quite several technologies. Some of which are beyond the scope of this post.
HTTP Request Simplified
Say you type the URL codeisbae.com into your browser address bar, what happens next? 🤔
- DNS Lookup: the browser sends a query to the DNS server asking for the IP address of the website you requested. Each website on the internet has a unique IP address that looks like 126.96.36.199 (
github.comIP address). What you type on the address bar is a human-readable representation of this address.
- TCP/IP handshake: After the IP address has been resolved. Your browser makes a request to the server at that IP address asking for a copy of the page you want. This communication between the client (your browser) and the server is done through TCP ↗︎.
- On the server, the request from the client is processed. If successful, the server returns a status code of 200 which means that everything went as expected, along with the requested resources. These are sent back to the browser in small chunks called data packets ↗︎.
The above is a simple walkthrough of how an HTTP request is proceessed without going into so much detail.