Scale Up vs Scale Out π’
When an application gains popularity, traffic increases exponentially. If the underlying hardware is not optimized, the server will experience memory depletion and crash. Engineers must choose between two scaling strategies:
Vertical Scaling (Scale Up)
Vertical scaling upgrades the compute power of a single node by adding more CPU cores, RAM capacity, or SSD storage. While simple (requiring no code changes), it has significant disadvantages:
- Hardware Ceiling: You eventually hit physical hardware limits where you cannot buy a larger machine.
- Single Point of Failure (SPOF): If that single server goes offline or has a hardware failure, your entire app is down.
- Non-linear Costs: High-end enterprise servers cost exponentially more than several commodity servers combined.
Horizontal Scaling (Scale Out)
Horizontal scaling adds multiple cheaper commodity servers behind a Load Balancer (like Nginx, HAProxy, or AWS ALB). The load balancer accepts incoming traffic and distributes it using algorithms like Round Robin or Least Connections.
Database Scaling: The Real Bottleneck
While web servers scale easily, databases are stateful and difficult to scale out. Common patterns include:
- Read Replicas: Send write queries to a single primary database, and distribute read queries across multiple read-only secondary databases.
- Sharding: Partition database rows horizontally across different servers based on a shard key (e.g. odd user IDs on Server A, even IDs on Server B).