What is Scaling?
Imagine you run a delivery business with one truck that carries 100 packages. Business is booming and now you need to deliver 500 packages daily. You have two options:
Option A: Buy a BIGGER truck that carries 500 packages → Vertical Scaling
Option B: Buy 4 more trucks of the same size → Horizontal Scaling
Vertical Scaling (Scale Up)
Add more power to your existing server — more CPU, more RAM, faster SSD.
Before: 🖥️ (4 CPU, 8GB RAM)
After: 🖥️ (32 CPU, 128GB RAM)
Pros:
Cons:
Real example: Your PostgreSQL database is slow. You upgrade from 8GB RAM to 64GB RAM. Queries are faster now. Simple.
Horizontal Scaling (Scale Out)
Add more servers of the same size and distribute the load.
Before: 🖥️ (handles 1000 req/s)
After: 🖥️🖥️🖥️🖥️🖥️ (handles 5000 req/s)
↑
Load Balancer distributes traffic
Pros:
Cons:
Real example: Netflix adds more servers during peak hours (Friday evenings) and removes them during off-peak. They scale from 1,000 to 10,000 servers dynamically.
When to Use Which?
Start with Vertical Scaling when:
Switch to Horizontal Scaling when:
The Real-World Pattern
Most companies use BOTH:
Load Balancer
├── Server 1 (16 CPU, 32GB RAM) ← vertically scaled
├── Server 2 (16 CPU, 32GB RAM)
├── Server 3 (16 CPU, 32GB RAM)
└── Server 4 (16 CPU, 32GB RAM) ← horizontally scaled
Each server is reasonably powerful (vertical), and there are multiple of them (horizontal). This is the sweet spot.
Key Takeaway
Vertical scaling is simple but limited. Horizontal scaling is complex but unlimited. In interviews, always mention that you'd start vertical for simplicity and move to horizontal as traffic grows. This shows practical thinking.