# Vertical and Horizontal Scaling

> Know when to buy a bigger machine, when to add more machines, and what your code must do to allow the latter. Free notes, key concepts, resources and a mini...

Canonical: https://www.internhack.in/roadmaps/tracks/backend/scaling-strategies
Last updated: 2026-11-28

Know when to buy a bigger machine, when to add more machines, and what your code must do to allow the latter.

Intermediate · about 3 hours · difficulty 3/5

Learn first: [Reverse Proxies and Load Balancers](https://www.internhack.in/roadmaps/tracks/backend/reverse-proxies-load-balancers), [Twelve-Factor Apps and Cloud-Native Habits](https://www.internhack.in/roadmaps/tracks/backend/twelve-factor-apps)

Scaling means handling more load without falling over or slowing down. There are two basic moves, and most real systems use both.

### Vertical scaling (scale up)

Give the same server more CPU, memory or faster disks. It is simple, needs no code changes, and modern machines are enormous; a single well-tuned Postgres server handles far more than most startups need. Limits: a ceiling on machine size, cost that rises steeply at the top, and a single point of failure.

### Horizontal scaling (scale out)

Run more instances behind a load balancer. It gives near-unlimited capacity and redundancy, but requires your app to be **stateless**:

- Sessions in Redis or signed tokens, not process memory.
- Uploads in object storage, not local disk.
- Scheduled jobs that run once across the fleet, not once per instance.
- Caches that are shared or tolerant of inconsistency.

### Autoscaling

Platforms add and remove instances based on CPU, request rate, queue depth or custom metrics. Set sensible minimums (for redundancy), maximums (for cost and database protection) and cooldowns to avoid flapping.

### Scaling the rest of the stack

The app tier is usually the easy part. The database, caches and third-party APIs become the next bottlenecks, which is why pooling, replicas, caching and queues exist. Think about each **stateful** component separately.

### Capacity planning

Know your current peak, your growth rate and the load at which each component saturates (from load tests). Plan headroom (for example handle 2x peak) and revisit it regularly.

### Pitfalls

- Scaling out an app whose database is the bottleneck, which only makes contention worse.
- Premature distribution: running twenty instances of a service that one machine could handle.

You are ready to move on when your app runs correctly as three instances behind a load balancer, and you can name the next bottleneck and what you would do about it.

## Key concepts

- **Vertical scaling**
- **Horizontal scaling**
- **Stateless application design**
- **Autoscaling policies**
- **Scaling stateful components**
- **Capacity planning**

## Mini project

Run your app as three instances behind a load balancer, move all instance-local state to shared services, and prove it by killing instances during a load test with no failed user sessions.

## Check yourself

List three kinds of state that break when you go from one instance to three, and where each should live instead.

## Free resources

- [The System Design Primer](https://github.com/donnemartin/system-design-primer) (GitHub)
- [AWS Well-Architected Framework](https://docs.aws.amazon.com/wellarchitected/latest/framework/welcome.html) (AWS)
- [Autoscaling guidance](https://learn.microsoft.com/en-us/azure/architecture/best-practices/auto-scaling) (Microsoft Learn)

Previous: [Performance Profiling and Load Testing](https://www.internhack.in/roadmaps/tracks/backend/performance-profiling) · Next: [Timeouts, Retries and Circuit Breakers](https://www.internhack.in/roadmaps/tracks/backend/resilience-patterns)

## More in Building for Scale and Resilience

- [Vertical and Horizontal Scaling](https://www.internhack.in/roadmaps/tracks/backend/scaling-strategies)
- [Timeouts, Retries and Circuit Breakers](https://www.internhack.in/roadmaps/tracks/backend/resilience-patterns)
- [Throttling, Backpressure and Graceful Degradation](https://www.internhack.in/roadmaps/tracks/backend/load-management)
- [Zero-Downtime Deploys and Migrations](https://www.internhack.in/roadmaps/tracks/backend/zero-downtime-changes)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Backend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/backend)
