Horizontal vs. Vertical Scaling
One-Liner
The two primary strategies for increasing a system’s capacity: adding more resources to an existing machine (vertical) or adding more machines (horizontal).
What It Is
- Vertical Scaling (Scaling Up): Increasing the capacity of a single server by adding more CPU, RAM, or faster storage.
- Horizontal Scaling (Scaling Out): Increasing capacity by adding more servers to a distributed system.
Why It Exists
To provide different approaches to handle increased load and demand on a system. Each has its own benefits and limitations.
How It Works
- Vertical: Upgrade the hardware of a single machine.
- Horizontal: Distribute the workload across multiple machines, often using a load balancer.
Tradeoffs
Vertical Scaling
- Pros: Simpler to implement (no distributed system complexities).
- Cons: Limited by the maximum capacity of a single machine, often more expensive per unit of capacity at higher levels, introduces a single point of failure.
Horizontal Scaling
- Pros: Virtually limitless scalability, high availability (if one server fails, others can take over), often cheaper at scale (using commodity hardware).
- Cons: Significantly increases system complexity (distributed consensus, data consistency, load balancing, service discovery), requires careful design for statelessness.
Failure Modes
- Vertical Scaling: Hardware failure means the entire system goes down.
- Horizontal Scaling: Complexities of distributed systems can lead to new types of failures (e.g., network partitions, data inconsistencies).
Interview Traps
- Not being able to explain the core difference.
- Suggesting vertical scaling as a long-term solution for high-growth systems.
Real-World Usage
- Most modern web applications and microservices architectures rely heavily on horizontal scaling.
Anti-Patterns
- Trying to vertically scale a service indefinitely, leading to a massive, expensive, and fragile single server.
Related Concepts
- Load Balancing
- Statelessness
- Database Sharding
- Service Discovery