24 min read Servers & Distributed Systems Lesson 9 / 13
Part 4 — Modern Web Infrastructure & Real-Time Systems

Lesson 09 — Servers, Reverse Proxies, Load Balancers & CDNs: Where Does a Request Actually Go?

Web vs Application Servers, Reverse Proxies, Load Balancing Algorithms, Edge CDNs, Multi-Tier Caching, and Enterprise Distributed Request Pipelines

What We Will Learn in This Lesson

By the end of this lesson, you will master the inner anatomy of server-side web infrastructure and hyper-scale distributed architectures:

  • What a "Server" actually is — hardware, VMs vs architectural roles
  • Web Server (Nginx) vs Application Server (Node/Django/Spring)
  • Reverse Proxy front-door role, TLS offloading, and routing
  • Load Balancers, balancing algorithms & active health checks
  • Horizontal vs Vertical Scaling fundamentals
  • CDN (Content Delivery Network), Edge Caching & Origin Servers
  • Cache Hit vs Cache Miss and the Cache-Aside pattern
  • The 16-step enterprise request pipeline from browser to database
1

Where We Left Off & The Question of "The Server"

In previous lessons, we witnessed the journey of web communication through the lens of a client browser. Imagine typing the following URL into your browser's address bar:

https://example.com/products

The complete progression we uncovered so far:

URL
→ DNS
→ IP Address
→ Port (443)
→ TLS Handshake
→ HTTP Request

The client browser has successfully dispatched an encrypted HTTP GET request over fiber optic cables and routers toward the destination. But right here, a profound question arises:

"What do we actually mean by 'The Server'?"

Is a server simply a single computer sitting under a desk? A specific software daemon? A colossal room crammed with thousands of racks? Or an orchestrated mesh of dozens of specialized architectural tiers?

The answer is: Depending on the context, all of the above are true! For a small personal blog, the server might just be a humble virtual private server. But for large-scale enterprise services like Google, Netflix, YouTube, or Amazon, your single click traverses dozens of intermediate infrastructure components before ever touching a database row.

2

A Tiny All-In-One Website vs 1 Million Concurrent Users

To understand why enterprise architectures exist, let us first visualize a tiny hobby website. You build an online shop and rent a single small cloud instance. Everything runs on that solitary machine:

// All-In-One Single Box Architecture (Small Hobby Website)
User (Browser)
  ↓ (Public Internet)
Single Cloud Server (e.g. 1 vCPU, 2GB RAM)
  ├── Web Server (Nginx — Port 80/443)
  ├── Application Process (Node.js / Python / PHP)
  └── Database Engine (MySQL / PostgreSQL — Localhost)

When you have 50 or 100 visitors a day, this all-in-one setup works smoothly and costs pennies. But now imagine your product goes viral on social media, and suddenly 1 million users hit your store simultaneously!

Why a Single Server Instantly Crashes Under Load:

  • CPU & Memory Saturation: Millions of concurrent TLS handshakes and dynamic script executions push CPU usage to 100% and trigger Out-Of-Memory (OOM) kernel panics.
  • Database Lock & Connection Exhaustion: Relational databases default to a few hundred concurrent connections. Flooding it with millions of queries causes total deadlock and freezing.
  • Single Point of Failure (SPOF): If that single machine suffers a power outage, OS kernel panic, or broken cable, the entire business goes dark.
  • Geographic Latency: If the server resides in North America, a visitor in South Asia waits 250–300 ms of round-trip fiber delay on every single HTTP asset.

What is a Server Really? (Hardware vs Architectural Role)

Technically, a server is not the name of a specific physical chassis. It is fundamentally an architectural "role". Any computing system or daemon that listens on a network port, accepts incoming requests from clients, and returns services or responses acts as a server. It can be bare-metal hardware, a virtual machine (VM), a Docker container, or a cloud serverless function.

3

Web Server vs Application Server

In professional production systems, server responsibilities are split into two distinct tiers: the Web Server and the Application Server. Their jobs, performance profiles, and design philosophies are radically different.

Web Server (e.g. Nginx, Apache, Caddy)

The web server is the frontline warrior facing the public internet. It accepts incoming HTTP/HTTPS connections and delivers Static Files directly from disk or kernel memory with lightning speed.

Static Assets:
• logo.png, hero.webp (Images)
• style.css, font.woff2 (Stylesheets & Fonts)
• app.js, bundle.js (Pre-built JavaScript)

Why separate? Serving an image requires zero business logic and zero database queries. Written in event-driven C, Nginx can deliver tens of thousands of static files per second while consuming virtually zero CPU.

Application Server (e.g. Node.js, Django, Laravel, Spring)

The application server executes Dynamic Business Logic. It processes user input, verifies authentication, calculates algorithms, and queries databases to construct dynamic responses.

Dynamic Operations:
• GET /products/25 (Fetch live price & inventory)
• POST /login (Verify password hash & issue JWT)
• POST /checkout (Charge credit card via Stripe)

Why separate? Dynamic code is computationally heavy and memory-intensive. Keeping it shielded in an internal private network behind a lean web server keeps the entire system resilient.

The Classic Tag-Team: Nginx + Node.js

When an HTTP request for GET /logo.png arrives, Nginx serves it straight from the disk in under 1 millisecond without waking up Node.js. But when a request for GET /products/25 arrives, Nginx recognizes it as a dynamic route and forwards it directly to Node.js listening on an internal port.

4

What is a Reverse Proxy?

One of the most foundational patterns in modern cloud engineering is the Reverse Proxy. While a traditional forward proxy represents the client navigating out to the web, a reverse proxy represents the server cluster facing incoming client traffic.

Client Browser
  ↓ (HTTPS Request)
[ REVERSE PROXY (Nginx / HAProxy / Envoy) ] ← Public IP (Entrance)
  ├── → App Server 1 (Private IP: 10.0.1.5)
  ├── → App Server 2 (Private IP: 10.0.1.6)
  └── → Media Service (Private IP: 10.0.2.10)

The Analogy: Corporate Front-Desk Receptionist

Imagine entering a 50-story corporate headquarters. You do not know which room the Chief Financial Officer occupies, nor where the payroll servers are stored. You go to the front-desk receptionist. The receptionist checks your ID badge, verifies your purpose, and dials the internal extension to connect you. The internal floorplan is never exposed to the outside world. The reverse proxy is that indispensable receptionist.

Critical Capabilities of a Reverse Proxy:

1. TLS/SSL Termination Handles CPU-intensive asymmetric crypto handshakes at the edge. Forwards clean, plain HTTP over secure internal networks to save application CPU.
2. Backend Anonymity & Security Internal application servers possess zero public IP addresses, making them immune to direct internet scans and port attacks.
3. Path-Based Intelligent Routing Routes /api/* to dynamic Go/Node services, /static/* to object storage, and blocks /admin/* from untrusted IPs.
4. Gzip/Brotli Compression & Buffering Compresses HTTP responses by up to 80% before transmission and buffers slow mobile uploads so application threads are never held hostage.
5

Load Balancers, Routing Algorithms & Live Health Checks

Imagine your application runs across 5 identical backend instances: Server A, B, C, D, and E. When 100,000 requests stream in per minute, which instance should handle which request? That critical orchestration is performed by a Load Balancer.

// Traffic Distribution Topology
Incoming User Traffic (10,000 req/s)
↓
LOAD BALANCER (HAProxy / AWS ALB / Nginx)
↙   ↓   ↘
Server A (20%)
Server B (20%)
Server C (20%)
Server D (20%)
Server E (20%)

How Does a Load Balancer Pick a Server? (Core Algorithms)

1. Round Robin:

Requests cycle sequentially: Request 1 → Server A, Request 2 → Server B, Request 3 → Server C, then back to A. Perfect when all backend servers have equal hardware specifications and workloads are uniformly sized.

2. Least Connections:

The load balancer monitors active open TCP/HTTP sockets across all nodes. New requests are dispatched to the server currently handling the fewest active connections. Ideal for long-lived transactions or video encoding tasks.

3. Weighted Round Robin:

If Server A has 64 CPU cores while Server B has only 16 cores, you assign A a weight of 4 and B a weight of 1. The balancer sends 4 requests to A for every 1 request sent to B.

4. IP Hash (Sticky Sessions):

A hash of the client's IP address maps them deterministically to the same backend node. Whenever that user refreshes, their request always hits the same server, preserving local in-memory session caches.

Active Health Checks

Every 2–5 seconds, the load balancer sends a probe to each backend's /healthz endpoint. If Server C crashes or returns 500 Internal Server Errors, the balancer instantly isolates it from the routing pool. Zero users experience an error page!

Vertical vs Horizontal Scaling

Vertical Scaling (Scale Up): Adding more RAM and CPU to a single machine. Suffers from physical hardware limits and severe downtime risks.
Horizontal Scaling (Scale Out): Adding 50 identical commodity servers side-by-side. With a load balancer, this unlocks near-infinite cloud elasticity.

6

CDNs (Content Delivery Networks) & Caching Mechanics

Your origin datacenter might be located in Northern Virginia or Frankfurt, Germany. When a student in Dhaka or Tokyo opens our academy page, light traveling through undersea fiber cables takes roughly 200–250 milliseconds of pure physics latency per round-trip. To eliminate this geographic barrier, the web relies on Content Delivery Networks (CDNs).

User in Dhaka, Bangladesh
  ↓ (Latency: just 5ms!)
Local CDN Edge Server (POP in Dhaka / Singapore)
  ├── [CACHE HIT] → Return Cached style.css / logo.png → Done!
  └── [CACHE MISS] ↓ (Subsea Fiber Route: 200ms)
Origin Datacenter (AWS Frankfurt, Germany)

Cache Hit (Direct from Local Edge)

The requested asset (like a stylesheet, font, or logo) is already stored in the local Edge server's SSD RAM cache. The CDN responds in 5 milliseconds. The origin server in Frankfurt never even knows the request occurred!

Cache Miss (Fetched from Origin)

No local copy exists on the Edge yet. The CDN pulls the asset across its private backbone from the Origin Server, streams it to the user, and caches a local copy for all subsequent regional visitors.

Are Modern CDNs Only for Static Files?

Far from it! Leading edge networks like Cloudflare, Fastly, and Akamai act as full-featured distributed computing and security shields:
• Volumetric DDoS Mitigation & WAF: Absorbs terabit-scale SYN floods and SQL injection attempts at edge Points of Presence (POPs) before they reach your origin.
• Edge TLS Termination: Completes the TLS handshake at the local edge, slashing dynamic connection establishment times by 80%.
• Edge Computing (Serverless Workers): Executes JavaScript, Rust, or WebAssembly routines within 50 miles of the user for instantaneous geo-routing and personalization.

7

Modern Enterprise Web Architecture & The 16-Step Journey

Now let us assemble all individual puzzle pieces into the definitive enterprise topology. When you browse to https://shop.example/products/25, how does your request traverse this multi-tier ecosystem?

Global Enterprise Request Pipeline (Master Topography)
👤 User Browser (Device in Client Location)
↓ 1. Anycast DNS & Local ISP Gateway
🌐 CDN Edge POP (Regional Node — DDoS Protection & Static Cache)
↓ 2. Cache Miss → Dynamic Request Forwarded over Backbone
⚖️ Cloud Load Balancer (AWS ALB / GCP LB — TLS Offloaded)
↓ 3. Internal Private VPC Network Routing
🛡️ Reverse Proxy Cluster (Nginx / Envoy / Ingress Gateway)
↓ 4. Path Routing (/products/*) to Target App Cluster
⚙️ Application Servers (Node.js / Go / Django Microservices)
↓ 5. Cache-Aside Pattern Check
⚡ In-Memory Cache
(Redis Cluster)
🗄️ Persistent Database
(PostgreSQL Primary)

The 16-Step Request-Response Execution:

  1. URL Parsing: The browser segments scheme (https), host (shop.example), and path (/products/25).
  2. Anycast DNS: Recursive resolvers direct the client to the nearest CDN Edge POP IP.
  3. TCP & TLS Handshake: A secure TLS 1.3 tunnel establishes with the local edge in 15 ms.
  4. HTTP GET Transmission: The browser sends GET /products/25 HTTP/2.
  5. CDN Edge Lookup: The Edge identifies this as a dynamic API route; it misses the local cache.
  6. Backbone Forwarding: The CDN routes the request over its low-latency fiber trunk to the origin.
  7. Load Balancer Inspection: The cloud load balancer picks a healthy Nginx reverse proxy instance.
  8. Reverse Proxy Routing: Nginx inspects the path and proxies the socket to the Product-Service container.
  9. Application Business Logic: The microservice validates session headers and JWT claims.
  10. Cache-Aside Redis Query: The app checks Redis for the key product:25.
  11. Cache Miss & Database Query: On a miss, the app queries PostgreSQL: SELECT * FROM products WHERE id=25.
  12. Redis Cache Population: The app saves the retrieved product record into Redis with a 1-hour TTL.
  13. JSON Response Serialization: The app serializes the product object into structured JSON.
  14. Reverse Proxy Buffering & Compression: Nginx compresses the JSON payload with Brotli.
  15. CDN Edge Delivery: The edge delivers the encrypted packets to the browser.
  16. Browser DOM Rendering: The browser builds the DOM and displays the product card on screen!

Distinct Roles: CDN vs In-Memory Cache vs Database

Attribute CDN (Content Delivery Network) In-Memory Cache (Redis/Memcached) Persistent Database (SQL/NoSQL)
Location Distributed edge POPs close to users RAM alongside backend app servers Dedicated private storage cluster
Primary Purpose Accelerate static assets and edge TLS Store hot database query results in RAM Authoritative persistent data storage
Typical Latency 5 – 20 milliseconds < 1 millisecond (Sub-millisecond) 5 – 100 milliseconds
Persistence Ephemeral (TTL-driven eviction) Ephemeral (RAM-based, volatile) Durable & ACID Transactional
8

Microservices, Defense-in-Depth & Case Study: YouTube

Modern architectures are rarely built as monolithic software blocks. An enterprise e-commerce platform decomposes into autonomous, loosely coupled services:

📦 Product Service
🛒 Order Service
💳 Payment Service
🔑 User Auth Service
🔍 Search & ML Service
🔔 Notification Service

East-West Internal Traffic

The browser is not the only client! When you click "Place Order", the Order Service acts as an internal client making HTTP/gRPC API calls to the Payment Service, Inventory Service, and Email Service. External incoming traffic is called North-South Traffic, while internal service-to-service communication is termed East-West Traffic.

Real-World Case Study: How YouTube Streams Video

When you press play on a 4K video, does the 5-gigabyte file stream directly out of a SQL database? Never! Video files are sliced into small 5-second segments (.ts / .m4s chunks):
• Metadata DB (Google Spanner / Bigtable): Holds only lightweight metadata: titles, view counts, and user likes.
• Object Storage (Google Cloud Storage): Stores cold video chunks on durable distributed block disks.
• Google Global Cache (GGC): Edge servers deployed physically inside your local ISP cache trending video chunks. When you watch a viral video, you pull bytes from a rack located right in your hometown!

9

The Master Mental Model & Looking Ahead to Lesson 10

The most crucial takeaway from this lesson is simple: The Internet ≠ Web Server! The internet is the global physical and routing ocean across which packets travel; the web and its distributed backend tiers are specialized vessels sailing upon that ocean.

The 15-Tier Universal Request Pipeline
Browser → DNS → IP/Port → TLS Handshake → HTTP → CDN Edge → Load Balancer → Reverse Proxy → App Server → In-Memory Cache → Database

We now understand how requests travel from client browsers deep into distributed cloud datacenters. But a fascinating question remains on the home front: How does your personal home Wi-Fi router connect all your family devices to the public internet using only one IP address?

Next Lesson Preview:

Lesson 10 — How NAT, Firewalls & Home Routers Power the Internet

Network Address Translation (NAT), port mapping, stateful packet filtering, and the mechanics of private LANs.

Explore Lesson 10

Interactive Lab: Enterprise Infrastructure Simulator

Experiment with end-to-end request flows, load balancer algorithms, and distributed microservice communication

Simulation Mode:
1. Client
2. CDN Edge
3. Load Balancer
4. Reverse Proxy
5. App & Cache
6. Database
Step 1: Client Browser Initiates Request Latency: 0 ms

The user navigates to https://shop.example/products/25. The browser discovers the nearest CDN Edge POP IP address via DNS and constructs an encrypted HTTP/2 GET request over TLS 1.3.

GET /products/25 HTTP/2 • Host: shop.example • User-Agent: Chrome/124
Packet enters local ISP gateway and fiber optic trunk lines...

Knowledge Check Quiz

1. What is the primary architectural rationale for placing a Web Server (e.g. Nginx) in front of an Application Server (e.g. Node/Django)?

2. In a Content Delivery Network (CDN), what does a "Cache Miss" mean?

3. How does a production Load Balancer actively detect that a backend instance has crashed?