Interview Question: Explain the lifecycle of HTTP request
DeveloperJoe
Posted on May 1, 2024
It is one of the most common question these days for interviews. However I think this question has very little utility. A person can be excellent front end engineer without ever having to know how DNS works.
But those who are looking for answers I have written this answer by referring to this excellent resource for frontend engineering.
Request Initiation
Request is often initiated by some user action. Typing url in browser, clicking on a link etc. The browser obtains the link and decides to fetch it for you by first looking at the TLD of the hostname. For example www.mydomain.com/path would make the browser first look at mydomain.com
DNS Resolution
Browser queries the DNS service in OS to convert mydomain.com to an ip address. Once it is resolved it looks up the www.mydomain.com which is called the subdomain.
TCP connection
Browser that tries to open a connection on port 80 on the resolved IP address. These days it is going to be port 443 because of SSL.
This process involves TCP/TLS handshake. Once the connection is established browser looks at the "path" portion in the URL.
PATH
Browser then presents the rest of the path to the server with which it has oppened the connection. Depending on the request type (GET/POST/DELETE) etc. it might also provide additional data to server.
The server will handle this information based on what kind of technology and architecture it has.
The server takes in all the input and generates an outpu
This output is passed back to the server.
Both client and server close the TCP connection.
The browser loads everything on the screen.
The browser then looks at the content-Type of the response and renders it in the viewport.
There are plenty of steps that go into this rendering process but we will leave that out.
Conclusion
This is what an interviewer is looking for in such questions whether you have good basic understanding of most of these steps or not.
[1] https://www.frontendeng.dev/blog/46-explain-lifecycle-of-internet-request
Posted on May 1, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024
November 30, 2024