Understand when to scale up (vertical) vs scale out (horizontal), and the statelessness requirement for horizontal scaling.
Published April 12, 2025
Scaling is the process of handling increased load. The two fundamental strategies differ in whether you add more power to existing machines or add more machines.
Replace a server with a more powerful one: more CPU, RAM, faster disk.
Before: After:
┌─────────────────┐ ┌──────────────────────────┐
│ 4 cores, 16GB │ → │ 64 cores, 512GB RAM │
│ 500GB SSD │ │ 2TB NVMe │
└─────────────────┘ └──────────────────────────┘
Pros:
Cons:
Add more machines and distribute load across them.
┌────────────┐
Requests → │ Load ├→ Server 1
│ Balancer ├→ Server 2
└────────────┘→ Server 3
Pros:
Cons:
For horizontal scaling to work, each server must be stateless — any server can handle any request.
❌ Stateful (broken with horizontal scaling):
User session stored in Server 1's memory
→ If load balancer routes next request to Server 2, session is lost!
✅ Stateless (works with horizontal scaling):
User session stored in Redis (shared cache)
JWT token carries auth state
All servers read from the same database
→ Any server can handle any request
| Scenario | Use |
|---|---|
| Early-stage startup, simple app | Vertical — less complexity |
| Single database instance | Vertical — avoid distributed DB complexity |
| High availability required | Horizontal — eliminate SPOF |
| Millions of users | Horizontal — vertical has a ceiling |
| Read-heavy workload | Horizontal — add read replicas |
| Stateful applications | Vertical — or redesign to be stateless first |
Modern cloud platforms (AWS EC2 Auto Scaling, GKE, Kubernetes HPA) add/remove servers automatically based on CPU, memory, or custom metrics:
# Kubernetes Horizontal Pod Autoscaler
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
spec:
minReplicas: 2
maxReplicas: 20
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70