DEV Community

Jonah Blessy
Jonah Blessy

Posted on • Edited on

How a request originates from client and reaches the server ?

When a user interacts with the internet, a lot of processes happen behind the scenes to make sure the request reaches the correct server and a proper response is returned. Even though it looks simple from the user’s point of view, like just typing a URL and getting a webpage, internally there are multiple steps involved such as identifying the correct server using an IP address, resolving human-readable domain names using DNS, and routing the request across different networks efficiently. To understand this clearly, it helps to break down the entire flow of how a request starts from the client side and travels all the way to the server and back.

USER-RESPONSE CYCLE:

User initiates the request
The process begins when the user enters a URL like www.wikipedia.org into the browser and presses enter. This action tells the browser that it needs to fetch the corresponding webpage.

Browser checks local cache
Before making any external requests, the system tries to optimize by checking if the IP address is already known. It looks into browser cache and operating system cache. If the IP address is already stored from a previous visit, the browser can directly use it and skip the DNS lookup step, making the process faster.

DNS query is initiated
If the IP address is not found in the cache, the browser needs to find it. So it starts a DNS (Domain Name System) query to translate the domain name into an IP address.

Local resolver
The DNS request first goes to the local resolver present on the user’s machine. This component is responsible for handling DNS queries and forwarding them if needed.

Request goes to ISP resolver
If the local resolver doesn’t have the answer, it forwards the request to the ISP’s DNS resolver. This resolver plays a major role in finding the correct IP by communicating with other DNS servers.

Root Name Server
The ISP resolver contacts a root name server. This server doesn’t provide the exact IP address but instead guides the request by pointing it to the appropriate TLD (Top Level Domain) server based on the domain.

TLD (Top Level Domain) server
Depending on the domain extension like .com, .org, .in, etc., the request is directed to the respective TLD server. This server knows where to find the authoritative server for that domain.

Zone file
The request finally reaches the authoritative DNS server, which contains the actual records (zone file) for the domain. These records include:

  • A record - IPv4 address
  • AAAA record - IPv6 address
  • CNAME - alias mappings
  • MX - mail server info From here, the correct IP address of the domain is obtained.

IP address returned to client
The IP address is then sent back through the same chain:
authoritative > TLD > root > ISP resolver > local resolver > browser
At the same time, this result may be cached at different levels to speed up future requests.

HTTP request is sent to server
Now that the browser knows the IP address, it sends an HTTP request to the server asking for the required resource like a webpage.

Server processes the request
The server receives the request, processes it with backend logic, database queries, etc., and prepares the appropriate response.

Response is sent back
The server sends an HTTP response back to the client, which includes the requested data along with status codes and headers.

Browser renders the content
Finally, the browser receives the response, interprets the data (HTML, CSS, JS), and displays the webpage to the user.

This entire process happens within milliseconds, but involves multiple systems working together to ensure that the request is correctly resolved and the response is delivered efficiently. It is fascinating to learn how the webpages we use everyday actually work!!

Top comments (0)