Concepts/2. Compute & Scaling/Load Balancing (Layer 4 vs Layer 7)
⚖️
2. Compute & ScalingIntermediate

Load Balancing (Layer 4 vs Layer 7)

← All 150+ Concepts

Distributes incoming client requests across a pool of backend servers using algorithms like Round Robin, Least Connections, and IP Hash.

STAFF ENGINEER TAKEAWAY: Layer 4 routes raw TCP/UDP packets with zero payload inspection; Layer 7 parses HTTP headers, paths, and cookies.
🔄

L7 Load Balancer Request Distribution

1
Client Ingress
HTTPS request hits VIP
✓
2
L7 Load Balancer
Inspects path /api/orders
✓
3
Least-Conn Algorithm
Picks Server #3 (12 conns vs 90)
✓
4
Backend Server #3
Executes request in 18ms
✓
✓ ARCHITECTURAL ADVANTAGES

Prevents single-node overload, enables zero-downtime rolling upgrades.

✗ TRADE-OFFS & COMPLEXITIES

Adds a network hop; stateful servers require sticky session affinity.

🏢

Production Systems Leveraging This Pattern

⚡AWS ALB/NLB⚡HAProxy⚡NGINXCloudflare Architecture↗
Simulate in Visual Canvas→Read 30-Chapter Curriculum→

More Topics in 2. Compute & Scaling

📈Vertical vs Horizontal Scaling

Vertical scaling upgrades a single node (CPU/RAM). Horizontal scaling adds stateless worker nodes across an autoscaling pool behind a load balancer.

🛡️Reverse Proxy (NGINX / Envoy)

An intermediary proxy server that sits in front of web servers to terminate TLS, compress payloads (Brotli/Gzip), cache responses, and hide internal network topologies.

🚪API Gateway Pattern

Single unified gateway entry point for microservices that handles JWT verification, rate limiting, protocol translation (REST to gRPC), and request routing.

🍩Consistent Hashing & Virtual Nodes

Maps keys and nodes onto a circular hash ring [0, 2^32 - 1]. Adding or removing a node only redistributes K/N keys rather than re-indexing the entire database cluster.