What it is
Horizontal scaling, or scaling out, means adding more machines that run the same software, instead of making one machine bigger. A load balancer (or DNS, or the clients themselves) spreads requests across the instances, so to clients the fleet looks like one service at one address. To handle more traffic you add instances; to save money you remove them.
Why it exists
A single machine has a largest size, a steep price curve near the top and no protection against its own failure. Many ordinary machines together have none of those limits for work that can be split up: capacity grows roughly with the number of instances, one failure takes away only a fraction of it, and instances can be replaced or upgraded one at a time without downtime.
How it works
A single entry point. Clients talk to a load balancer, which keeps a list of healthy instances and forwards each request to one of them. Instances are registered when they start and removed when they fail health checks or are shut down.
Interchangeable instances. Any instance must be able to serve any request. That means no user state kept only in an instance's memory or local disk: sessions go to a shared cache or database (or into signed tokens carried by the client), uploads go to object storage, and scheduled jobs are coordinated so they do not run on every instance at once.
Sizing. If one instance handles C requests per second, and you want to run at a target utilisation u (often 0.6–0.7, to keep queueing delays low), a peak of P needs about P ÷ (C × u) instances, rounded up. Add at least one more so the fleet still fits the peak with one instance down (N+1), and more if you must survive losing a whole availability zone.
Changing the count. Because instances are identical, adding one is a repeatable operation: start it from the same image, let it pass health checks, and the balancer starts sending it traffic. Autoscaling automates this based on CPU, request rate or queue depth.
When to use it
- Stateless tiers: web servers, API servers, workers pulling from a queue.
- When you need availability: a service that must survive the loss of an instance or a zone.
- When load varies a lot over the day or year, so the fleet can grow and shrink with it.
- When growth will outrun the largest single machine.
When not to
- Small, steady workloads that one machine handles comfortably: the balancer, deployment tooling and monitoring for a fleet may cost more than they save.
- Stateful components that cannot simply be copied, such as a relational primary. Those need replication or sharding, which are different and harder techniques.
- When the bottleneck is a shared dependency: adding app instances then only adds load to it.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Scale out instead of up | Headroom past one machine, survives instance failures | Load balancer, stateless design, more moving parts |
| Many small instances | Small blast radius per failure, fine-grained scaling | More per-instance overhead, more connections to shared stores |
| Few large instances | Less overhead, fewer connections | Each failure removes a larger share of capacity |
| Low target utilisation | Low latency, room to absorb a failure or spike | Paying for idle capacity |
| Sticky sessions | Keep in-memory sessions | Uneven load, lost sessions when an instance dies |
Alternatives
- Vertical scaling: one bigger machine. Simpler and often right for databases, but capped and a single point of failure.
- Caching: serve repeated work from memory so fewer instances are needed.
- Asynchronous processing: move slow work to a queue and workers, so the request path needs less capacity.
- Serverless functions: the platform scales instances per request for you, with cold starts and per-invocation limits as the trade-off.
Failure modes
- No headroom for failure: the fleet is sized exactly for peak, so losing one instance overloads the rest and the failure spreads.
- Hidden local state: sessions, caches or files on one instance break users when requests land elsewhere or the instance dies.
- Shared dependency saturates: more instances mean more connections and queries; a database, cache or downstream API hits its limit and every instance waits on it.
- Connection explosion: each instance opens its own connection pool, so 50 instances × 20 connections can exceed what a database accepts.
- Thundering herd on scale-out: new instances start with cold caches and JIT, and can be slower than the existing ones for their first minutes.
In production
Build instances from one immutable image and treat them as replaceable. Run them across at least two availability zones with enough spare capacity to lose one. Put a connection pooler in front of the database when the instance count grows. Use autoscaling with sensible minimums, maximums and cool-down periods, and watch per-instance metrics as well as totals so that one bad instance stands out. Deploy with rolling or blue-green releases, draining connections from each instance before it stops.
Common misconceptions
- "Twice the instances means twice the throughput." Only until a shared dependency, a lock or the network saturates.
- "It fits, so it is fine." Running at 90% utilisation fits on paper but queues requests and has no room for a failure.
- "Sticky sessions make an app scalable." They make a stateful app run on several machines, with uneven load and lost sessions on failure.
- "Scaling out is always cheaper." Many small instances carry more overhead (memory per process, connections, licences) than fewer large ones.
Interview angle
Expect to put a load balancer and several stateless instances in front of every request-serving tier, then justify the number: "each instance does about 75 req/s, peak is 210, at 70% target that is four, five with a spare." Interviewers then push on state (where do sessions live?), failure (what happens when one dies, or a zone?), and the next bottleneck (the database). Naming that bottleneck before they ask, and how you would scale it, is what distinguishes a strong answer.
Model assumptions
The simulation is a simplified model, not a benchmark. Each instance has 6 workers, an 80 ms mean service time (lognormal, cv 0.35) and room for 12 waiting requests (about 75 req/s). The load balancer uses round robin and health checks every 500 ms (2 failures eject, 3 successes restore). The shared database has 3 connections at 12 ms per query (about 250 queries/s) and a 200 ms pool timeout; app workers stay occupied while they wait for it. The session store is drawn for illustration only and is not simulated. Arrivals are random (Poisson); network hops take a fixed 2–25 ms. Utilisation is the fraction of busy workers, not CPU. Numbers show behaviour and orders of magnitude only.