Skip to content

The Complete Journey of a Request

Introduction

When you type a URL in your browser and press Enter, what exactly happens before the page appears? This is a classic interview question, and more importantly, a key to understanding the entire Web architecture. Understanding this chain lets you see how frontend, backend, network, and databases work together.

What will you learn in this article?

After reading this chapter, you will gain:

  • Full-chain perspective: Understand the complete process of an HTTP request from sending to returning
  • Layer-by-layer responsibility awareness: Know what DNS, TCP, load balancing, web servers, application servers, and databases each do
  • Problem diagnosis ability: Know which layer to start investigating when requests are slow or fail
  • Performance optimization thinking: Each layer has optimization potential; know where the optimization points are
ChapterContentCore Concepts
Chapter 1Browser initiates requestDNS resolution, TCP connection, HTTP request
Chapter 2Network transmissionRouting, CDN, load balancing
Chapter 3Server processingWeb server, application logic, database queries
Chapter 4Response returnSerialization, compression, rendering
Chapter 5Full-chain optimizationCaching, connection reuse, async processing

0. The Big Picture: What Does a Request Go Through?

Use an analogy to understand: you order a book online. This process is strikingly similar to an HTTP request.

Request StageBook Ordering AnalogyTechnical Equivalent
Enter URLYou say "I want to go to that bookstore"Browser parses URL
DNS resolutionLook at a map to find the bookstore's addressDomain → IP address
TCP connectionWalk to the bookstore door, push it openThree-way handshake establishes connection
Send requestTell the clerk "I want the book 'xxx'"HTTP request message
Server processingClerk goes to warehouse to find the book, checks inventory, calculates priceApplication logic + database query
Return responseClerk hands you the bookHTTP response message
Browser renderingYou open the book and start readingHTML/CSS/JS parsing and rendering

1. Browser Initiates the Request

1.1 URL Parsing

When you enter https://api.example.com/books?id=123, the browser breaks it into several parts:

PartValueMeaning
ProtocolhttpsEncrypted communication
Domainapi.example.comThe server's "name"
Path/booksThe resource to access
Query parametersid=123Additional conditions

1.2 DNS Resolution: Domain → IP Address

Computers don't understand domain names; they only understand IP addresses (like 93.184.216.34). DNS is the internet's "phone book."

Browser cache → System cache → Router cache → ISP DNS → Root name server
     ↓ Hit = use directly; miss = check next level

The Significance of DNS Caching

If every request had to query from the root name server, the global internet would be overwhelmed by DNS queries. That's why every layer has caching; most requests can be resolved at the browser or system level.

1.3 TCP Three-Way Handshake

After finding the IP address, the browser needs to "establish a connection" with the server. TCP uses a three-way handshake to ensure both sides are ready:

Client → Server: Hello, I'd like to connect (SYN)
Server → Client: OK, I'm ready (SYN + ACK)
Client → Server: Received, let's start communicating (ACK)

If using HTTPS, an additional TLS handshake is needed to negotiate encryption.

1.4 Sending the HTTP Request

After the connection is established, the browser sends the HTTP request message:

http
GET /books?id=123 HTTP/1.1
Host: api.example.com
Accept: application/json
Authorization: Bearer eyJhbGci...
User-Agent: Chrome/120.0
ComponentContent
Request lineMethod (GET) + Path + Protocol version
Request headersMetadata: authentication, expected data format, etc.
Request bodyOnly for POST/PUT requests; carries the data to submit

2. Network Transmission: The Request on the Road

2.1 Routing and Forwarding

After leaving your computer, the request passes through multiple routers for forwarding, like a package going through multiple transit stations:

Your computer → Home router → ISP network → Backbone network → Target data center

Each router decides the "next hop" based on the IP address. You can use the traceroute command to see which nodes a request passes through.

2.2 CDN Acceleration

If the target website uses a CDN (Content Delivery Network), the request may not need to reach the origin server:

ScenarioRouting
Requesting static resources (images, CSS, JS)CDN edge node returns directly
Requesting dynamic data (API)Passes through CDN, reaches origin server

The essence of CDN is "pre-placing content as close to users as possible."

2.3 Load Balancing

Large websites don't have just one server. A load balancer distributes requests across multiple servers:

User requests → Load balancer → Server A (30% traffic)
                              → Server B (30% traffic)
                              → Server C (40% traffic)

Common distribution strategies:

StrategyPrincipleUse Case
Round robinDistribute sequentiallyServers with identical specs
Weighted round robinDistribute by weightServers with different specs
IP hashSame user → same serverWhen session persistence is needed
Least connectionsAssign to server with fewest connectionsWhen request processing times vary greatly

3. Server Processing: What Happens in the Kitchen

After the request arrives at the server, it goes through multiple layers of processing.

3.1 Web Server (Nginx / Apache)

The first to receive the request is typically the web server, responsible for:

ResponsibilityDescription
Static file servingDirectly returns HTML, CSS, JS, images
Reverse proxyForwards API requests to the backend application
SSL terminationHandles HTTPS encryption/decryption
Request filteringBlocks malicious requests, rate limiting

3.2 Application Server Processing

The web server forwards the request to the application server (Node.js, Spring, Django, etc.). The processing flow:

Request enters → Middleware chain → Route matching → Controller → Service layer → Data access layer

What middleware does:

  1. Parse request body (JSON, form data)
  2. Verify identity (check Token)
  3. Check permissions (can this user access this endpoint?)
  4. Log (who accessed what, when)

3.3 Database Query

Most requests ultimately need to interact with the database:

Application code: SELECT * FROM books WHERE id = 123

Database engine: Parse SQL → Query optimization → Execution plan → Read data

Return result: { id: 123, title: "xxx", price: 59.9 }

Databases Are the Most Common Performance Bottleneck

Network transmission is typically millisecond-level, application logic is fast too, but an unindexed database query can take several seconds or even tens of seconds. So "slow requests" are most likely caused by slow database queries.


4. Response Return: The Data's Journey Back

4.1 Constructing the HTTP Response

After processing, the server constructs the response message:

http
HTTP/1.1 200 OK
Content-Type: application/json
Content-Encoding: gzip
Cache-Control: max-age=3600

{"id": 123, "title": "xxx", "price": 59.9}
ComponentContent
Status lineProtocol version + Status code (200 success, 404 not found, 500 server error)
Response headersData format, caching policy, compression method, etc.
Response bodyThe actual data content (JSON, HTML, etc.)

4.2 Data Compression

The server typically compresses the response body with gzip or brotli to reduce transmission size:

Compression AlgorithmCompression RatioSpeed
gzip~70%Fast
brotli~80%Slower but better compression

A 100KB JSON file might be only 20-30KB after compression.

4.3 Browser Rendering

After the browser receives the response:

  1. Parse HTML → Build DOM tree
  2. Parse CSS → Build style tree
  3. Merge → Generate render tree
  4. Layout → Calculate each element's position and size
  5. Paint → Draw pixels onto the screen

5. Full-Chain Optimization: Every Layer Can Be Faster

5.1 Optimization Methods at Each Layer

LayerOptimization MethodEffect
DNSDNS prefetching, use fast DNS servicesReduce DNS query time
NetworkCDN, HTTP/2, connection reuseReduce transmission latency
ServerCaching (Redis), async processingReduce processing time
DatabaseIndexes, query optimization, read-write splittingReduce query time
FrontendLazy loading, code splitting, asset compressionReduce rendering time

5.2 Caching: The Most Effective Optimization

Caching exists at every layer of the request chain:

Browser cache → CDN cache → Reverse proxy cache → Application cache (Redis) → Database cache

The Essence of Caching

Trading space for time. Store computed results so next time you can use them directly without recomputing. Every 10% improvement in cache hit rate can multiply system performance.

5.3 Troubleshooting When Requests Fail

SymptomPossible Problem LayerInvestigation Method
No response at allDNS / Networkping, nslookup
Connection timeoutNetwork / Server downtelnet, curl
Returns 4xxClient request errorCheck URL, parameters, Token
Returns 5xxServer internal errorCheck server logs
Slow responseDatabase / Application logicCheck slow query logs, APM tools

6. Summary

The complete journey of an HTTP request:

  1. Browser: Parse URL → DNS query → TCP connection → Send request
  2. Network: Route forwarding → CDN check → Load balancing distribution
  3. Server: Web server receives → Middleware processes → Business logic → Database query
  4. Return: Construct response → Compress → Network transmission → Browser rendering

The Value of Understanding the Full Chain

When you can draw the complete request chain in your mind, you'll be able to quickly identify which layer has a problem no matter what issue you encounter. This is the key leap from "junior developer" to "someone who can independently troubleshoot problems."


Further Reading