Sub topic 1
Why One Server Is Not Enough: Scaling and Availability
Prerequisites
Assume you understand basic HTTP client-server communication, TCP, IP addresses, ports, and configuration files.
Why One Server Is Not Enough
A single server limits capacity and availability. As request volume grows, CPU, memory, network bandwidth, or connection limits can become bottlenecks. Adding larger hardware is vertical scaling, but it has practical and cost limits.
Horizontal scaling adds more servers. If one server fails, the application can continue serving requests from the others. However, clients need a way to reach the available servers without knowing their individual addresses.
What a Load Balancer Does
A load balancer is a service that receives client traffic and forwards each connection or request to a backend server. The backend is a server that runs the application.
The load balancer can:
- Distribute traffic across multiple backends.
- Stop sending traffic to failed backends.
- Provide one stable address for clients.
- Terminate TLS, depending on its configuration.
- Support gradual deployments by removing servers from service.
The load balancer itself must also be redundant. Two application servers do not remove the single point of failure if every client depends on one load-balancer instance.
Layer 4 vs Layer 7 Load Balancing
Layer 4 balancing operates on transport information such as TCP or UDP addresses and ports. It does not need to understand HTTP. It is fast and supports protocols that are not HTTP, but it cannot route based on URLs, headers, or cookies.
Layer 7 balancing understands application protocols such as HTTP. It can route /api to one backend and /images to another, inspect headers, terminate TLS, and apply request-level policies. This requires more processing and protocol configuration.
| Type | Understands | Typical choice |
|---|---|---|
| Layer 4 | IP addresses, ports, TCP or UDP | Generic TCP or UDP services |
| Layer 7 | HTTP paths, headers, cookies | Web applications needing request routing |
Choose Layer 4 for simple, protocol-agnostic forwarding. Choose Layer 7 when routing or security decisions depend on HTTP details.
Exercise
Which layer should route /payments to a particular backend based on the request path?
Show answer
Layer 7, because it understands HTTP request paths.