Ensiklopedia VibeKoding: A Panorama of Request Flow.Ensiklopedia VibeKoding: A Panorama of Request Flow.
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.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?What will you learn in this article?
After reading this chapter, you will gain:After reading this chapter, you will gain:
| Chapter | Content | Core Concepts |
|---|---|---|
| Chapter 1 | Browser initiates request | DNS resolution, TCP connection, HTTP request |
| Chapter 2 | Network transmission | Routing, CDN, load balancing |
| Chapter 3 | Server processing | Web server, application logic, database queries |
| Chapter 4 | Response return | Serialization, compression, rendering |
| Chapter 5 | Full-chain optimization | Caching, connection reuse, async processing |
------
Use an analogy to understand: you order a book online. This process is strikingly similar to an HTTP request.Use an analogy to understand: you order a book online. This process is strikingly similar to an HTTP request.
| Request Stage | Book Ordering Analogy | Technical Equivalent |
|---|---|---|
| Enter URL | You say "I want to go to that bookstore" | Browser parses URL |
| DNS resolution | Look at a map to find the bookstore's address | Domain โ IP address |
| TCP connection | Walk to the bookstore door, push it open | Three-way handshake establishes connection |
| Send request | Tell the clerk "I want the book 'xxx'" | HTTP request message |
| Server processing | Clerk goes to warehouse to find the book, checks inventory, calculates price | Application logic + database query |
| Return response | Clerk hands you the book | HTTP response message |
| Browser rendering | You open the book and start reading | HTML/CSS/JS parsing and rendering |
------
When you enter https://api.example.com/books?id=123, the browser breaks it into several parts:When you enter https://api.example.com/books?id=123, the browser breaks it into several parts:
| Part | Value | Meaning |
|---|---|---|
| Protocol | https | Encrypted communication |
| Domain | api.example.com | The server's "name" |
| Path | /books | The resource to access |
| Query parameters | id=123 | Additional conditions |
Computers don't understand domain names; they only understand IP addresses (like 93.184.216.34). DNS is the internet's "phone book."Computers don't understand domain names; they only understand IP addresses (like 93.184.216.34). DNS is the internet's "phone book."
CODE Browser cache โ System cache โ Router cache โ ISP DNS โ Root name server โ Hit = use directly; miss = check next level
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.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.
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: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:
CODE 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.If using HTTPS, an additional TLS handshake is needed to negotiate encryption.
After the connection is established, the browser sends the HTTP request message: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
| Component | Content |
|---|---|
| Request line | Method (GET) + Path + Protocol version |
| Request headers | Metadata: authentication, expected data format, etc. |
| Request body | Only for POST/PUT requests; carries the data to submit |
------
After leaving your computer, the request passes through multiple routers for forwarding, like a package going through multiple transit stations:After leaving your computer, the request passes through multiple routers for forwarding, like a package going through multiple transit stations:
CODE 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.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.
If the target website uses a CDN (Content Delivery Network), the request may not need to reach the origin server:If the target website uses a CDN (Content Delivery Network), the request may not need to reach the origin server:
| Scenario | Routing |
|---|---|
| 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."The essence of CDN is "pre-placing content as close to users as possible."
Large websites don't have just one server. A load balancer distributes requests across multiple servers:Large websites don't have just one server. A load balancer distributes requests across multiple servers:
CODE User requests โ Load balancer โ Server A (30% traffic) โ Server B (30% traffic) โ Server C (40% traffic)
Common distribution strategies:Common distribution strategies:
| Strategy | Principle | Use Case |
|---|---|---|
| Round robin | Distribute sequentially | Servers with identical specs |
| Weighted round robin | Distribute by weight | Servers with different specs |
| IP hash | Same user โ same server | When session persistence is needed |
| Least connections | Assign to server with fewest connections | When request processing times vary greatly |
------
After the request arrives at the server, it goes through multiple layers of processing.After the request arrives at the server, it goes through multiple layers of processing.
The first to receive the request is typically the web server, responsible for:The first to receive the request is typically the web server, responsible for:
| Responsibility | Description |
|---|---|
| Static file serving | Directly returns HTML, CSS, JS, images |
| Reverse proxy | Forwards API requests to the backend application |
| SSL termination | Handles HTTPS encryption/decryption |
| Request filtering | Blocks malicious requests, rate limiting |
The web server forwards the request to the application server (Node.js, Spring, Django, etc.). The processing flow:The web server forwards the request to the application server (Node.js, Spring, Django, etc.). The processing flow:
CODE Request enters โ Middleware chain โ Route matching โ Controller โ Service layer โ Data access layer
What middleware does:What middleware does:
Most requests ultimately need to interact with the database:Most requests ultimately need to interact with the database:
CODE 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 }
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.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.
------
After processing, the server constructs the response message: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}
| Component | Content |
|---|---|
| Status line | Protocol version + Status code (200 success, 404 not found, 500 server error) |
| Response headers | Data format, caching policy, compression method, etc. |
| Response body | The actual data content (JSON, HTML, etc.) |
The server typically compresses the response body with gzip or brotli to reduce transmission size:The server typically compresses the response body with gzip or brotli to reduce transmission size:
| Compression Algorithm | Compression Ratio | Speed |
|---|---|---|
| gzip | ~70% | Fast |
| brotli | ~80% | Slower but better compression |
A 100KB JSON file might be only 20-30KB after compression.A 100KB JSON file might be only 20-30KB after compression.
After the browser receives the response:After the browser receives the response:
------
| Layer | Optimization Method | Effect |
|---|---|---|
| DNS | DNS prefetching, use fast DNS services | Reduce DNS query time |
| Network | CDN, HTTP/2, connection reuse | Reduce transmission latency |
| Server | Caching (Redis), async processing | Reduce processing time |
| Database | Indexes, query optimization, read-write splitting | Reduce query time |
| Frontend | Lazy loading, code splitting, asset compression | Reduce rendering time |
Caching exists at every layer of the request chain:Caching exists at every layer of the request chain:
CODE Browser cache โ CDN cache โ Reverse proxy cache โ Application cache (Redis) โ Database cache
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.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.
| Symptom | Possible Problem Layer | Investigation Method |
|---|---|---|
| No response at all | DNS / Network | ping, nslookup |
| Connection timeout | Network / Server down | telnet, curl |
| Returns 4xx | Client request error | Check URL, parameters, Token |
| Returns 5xx | Server internal error | Check server logs |
| Slow response | Database / Application logic | Check slow query logs, APM tools |
------
The complete journey of an HTTP request:The complete journey of an HTTP request:
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."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."
------