DEV Community

Abinaya Dhanraj
Abinaya Dhanraj

Posted on

How a Request Travels from Client to Server

Title: How a Request Travels from Client to Server

Whenever I open a website or click something in an app, a request is sent from my device to a server. This happens very fast, but there are multiple steps involved. In this blog, I am explaining how a request starts from the client and finally reaches the server.

What is a client and server

Client means the user side, like my mobile, laptop, or browser.
Server is a system that stores data and responds to requests.

Step 1: User action

The process starts when I do some action like typing a URL in the browser or clicking a button.

Example: I type amazon.com in the browser.

Step 2: DNS resolution

The browser cannot understand amazon.com directly. It needs an IP address.

So it asks the DNS system to convert the domain name into an IP address.

After this step, the browser gets something like 54.x.x.x.

Step 3: Creating the request

Now the browser prepares an HTTP request.

This request contains
method like GET or POST
URL
headers
sometimes body data

Example: If I just open a website, it sends a GET request.

Step 4: TCP connection

Before sending the request, a connection must be established with the server.

This is done using TCP handshake.

Client sends SYN
Server replies with SYN-ACK
Client sends ACK

Now the connection is established.

Step 5: Sending the request

After connection is ready, the HTTP request is sent through the network.

The request travels through routers and different networks on the internet.

Step 6: Reaching the server

The request finally reaches the server using the IP address.

The server receives the request and processes it.

It may
fetch data from database
run some logic
prepare a response

Step 7: Server sends response

After processing, the server sends back an HTTP response.

This response contains
status code like 200, 404
headers
response body like HTML or JSON

Step 8: Client receives response

The browser receives the response.

If it is a webpage, it renders the HTML and shows it on the screen.

If it is API data, it processes it accordingly.

Step 9: Connection close or reuse

After response, the connection may be closed or reused for further requests.

What I understood

A simple click or typing a URL involves many steps like DNS lookup, connection setup, request sending, and response receiving.

Even though it looks simple, many systems work together to make it happen.

Conclusion

The journey from client to server is an important concept in networking. Understanding this helps in learning web development, APIs, and system design in a better way.

Top comments (0)