Horizontal vs Vertical Scaling
Explain the difference between horizontal scaling and vertical scaling. What are the key trade-offs, and why do large-scale web systems typically prefer horizontal scaling?
Vertical scaling (scaling up) adds more resources to a single machine — more CPU cores, RAM, or faster storage. It is simple to implement (no code changes needed) but has a hard ceiling: there is a maximum size for any single machine. It also creates a single point of failure.
Horizontal scaling (scaling out) adds more machines to share the load. Large-scale web systems prefer it because:
- There is no theoretical ceiling — you can add thousands of servers.
- No single point of failure; losing one machine degrades capacity slightly rather than taking the system down entirely.
- Cost scales linearly with commodity hardware instead of exponentially with high-end servers.
The key requirement for horizontal scaling is statelessness: application servers must not store per-user state locally. Sessions and user data must live in a shared store (Redis, database) so any server can handle any request.