VibeKoding / Ensiklopedia ยท Fondasi KuatEnsiklopedia ยท Fondasi Kuat / A Panorama of Request FlowA Panorama of Request Flow
VK

A Panorama of Request FlowA Panorama of Request Flow

๐Ÿ“š Ensiklopedia ยท Fondasi KuatEnsiklopedia ยท Fondasi Kuat ๐ŸŒ Dual Bahasa (ID / EN) โšก VibeKoding Native

Ensiklopedia VibeKoding: A Panorama of Request Flow.Ensiklopedia VibeKoding: A Panorama of Request Flow.

๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

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:

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 Through0. 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.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 Request1. Browser Initiates the Request

1.1 URL Parsing1.1 URL Parsing

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:

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

1.2 DNS Resolution: Domain โ†’ IP Address1.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."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
๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

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.

1.3 TCP Three-Way Handshake1.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: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.

1.4 Sending the HTTP Request1.4 Sending the HTTP Request

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
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 Road2. Network Transmission: The Request on the Road

2.1 Routing and Forwarding2.1 Routing and Forwarding

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.

2.2 CDN Acceleration2.2 CDN Acceleration

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:

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."The essence of CDN is "pre-placing content as close to users as possible."

2.3 Load Balancing2.3 Load Balancing

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:

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 Kitchen3. Server Processing: What Happens in the Kitchen

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.

3.1 Web Server (Nginx / Apache)3.1 Web Server (Nginx / Apache)

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:

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 Processing3.2 Application Server Processing

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:

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

    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 }
    
    ๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

    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.

    ------

    4. Response Return: The Data's Journey Back4. Response Return: The Data's Journey Back

    4.1 Constructing the HTTP Response4.1 Constructing the HTTP Response

    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}
    
    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 Compression4.2 Data Compression

    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 AlgorithmCompression RatioSpeed
    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.

    4.3 Browser Rendering4.3 Browser Rendering

    After the browser receives the response:After the browser receives the response:

    1. Parse HTML โ†’ Build DOM treeParse HTML โ†’ Build DOM tree
    2. Parse CSS โ†’ Build style treeParse CSS โ†’ Build style tree
    3. Merge โ†’ Generate render treeMerge โ†’ Generate render tree
    4. Layout โ†’ Calculate each element's position and sizeLayout โ†’ Calculate each element's position and size
    5. Paint โ†’ Draw pixels onto the screenPaint โ†’ Draw pixels onto the screen
    6. ------

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

      5.1 Optimization Methods at Each Layer5.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 Optimization5.2 Caching: The Most Effective Optimization

      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
      
      ๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

      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.

      5.3 Troubleshooting When Requests Fail5.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. Summary6. Summary

      The complete journey of an HTTP request:The complete journey of an HTTP request:

      1. Browser: Parse URL โ†’ DNS query โ†’ TCP connection โ†’ Send requestBrowser: Parse URL โ†’ DNS query โ†’ TCP connection โ†’ Send request
      2. Network: Route forwarding โ†’ CDN check โ†’ Load balancing distributionNetwork: Route forwarding โ†’ CDN check โ†’ Load balancing distribution
      3. Server: Web server receives โ†’ Middleware processes โ†’ Business logic โ†’ Database queryServer: Web server receives โ†’ Middleware processes โ†’ Business logic โ†’ Database query
      4. Return: Construct response โ†’ Compress โ†’ Network transmission โ†’ Browser renderingReturn: Construct response โ†’ Compress โ†’ Network transmission โ†’ Browser rendering
      5. ๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

        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."

        ------

        Further ReadingFurther Reading

        • [HTTP Documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP) โ€” MDN's HTTP documentation[HTTP Documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP) โ€” MDN's HTTP documentation
        • [High Performance Browser Networking](https://hpbn.co/) โ€” Browser network performance optimization[High Performance Browser Networking](https://hpbn.co/) โ€” Browser network performance optimization
        • [What happens when...](https://github.com/alex/what-happens-when) โ€” The classic "what happens after you type a URL" deep dive[What happens when...](https://github.com/alex/what-happens-when) โ€” The classic "what happens after you type a URL" deep dive