Architecture & opsUpdated 2026-11-20

Horizontal scaling

Adding machines instead of a bigger machine: what it requires, what it costs, and why I do not reach for it early.

A second cashier opens a till, so the line moves twice as fast.

That is horizontal scaling. When the line is too long for one cashier, you do not make the cashier faster. You add another one beside them and share the queue.

How it works

Instead of a bigger machine, you run more machines and spread the traffic across them.

Code
          ┌── Server 1
          │
Users → LB├── Server 2
          │
          └── Server 3

A load balancer sits in front and sends each request to an instance that is healthy and not busy. If one instance fails, the others carry on, so you also gain redundancy.

The requirement: stateless servers

Scaling out only works when the app servers are mostly stateless. If an instance keeps a session in memory, the next request may land on another instance that does not have it. So state moves out to the database, a shared store or a signed token before the second instance goes live.

Compared with vertical scaling

Vertical scaling makes one machine bigger: more CPU, more memory, faster disk.

Code
Vertical:   one server   4 CPU → 16 CPU
Horizontal: 1 server → 3 servers, same size

Vertical is simple. There is no code change and no distributed-systems problem. Its limits are that hardware tops out, cost climbs steeply at the high end, and one big machine is still a single point of failure. I reach for it first, and for databases in particular. A single-primary relational database is hard to spread across machines, so making it bigger is often the sensible move.

When to use it

  • Traffic has grown past what one machine can serve.
  • You need to survive a server failure without an outage.
  • Different parts of the system need to scale independently.

Scaling automatically

Once instances are stateless, adding and removing them can be automated from a measured signal such as CPU, memory or request queue length. The part I plan for is the slow edge: a new instance takes time to start and warm up, so scaling on a signal that has already peaked arrives late. Health checks decide when a new instance may receive traffic, and a drain period lets a departing instance finish its work. A fixed minimum of two keeps one failure from becoming an outage.

Where I used it

I haven't shipped this in a public project yet.

What I have done is choose not to. IMS is a modular monolith on one Postgres database, chosen so stock, reservations and documents commit atomically, with database contention to be measured. That is a deliberate decision to keep the data tier simple. It is also not a claim about how many app instances run in front of it, and I have no scaling numbers to show.

The intent is to keep the app tier stateless, so that a second instance later is a configuration change.

Trade-offs

  • State must be externalised. Sessions, files and counters move into shared stores, and each store has to be run and protected.
  • More to operate. A balancer, health checks, deployment across several instances and shared configuration all appear. The work is not in the extra servers. It is in everything that coordinates them.
  • Harder debugging. One user's session can leave logs and traces on three machines. You need request ids and central logging before you need the second server.
  • Cost of idle capacity. Extra instances for peak load sit unused the rest of the time unless something scales them up and down automatically.
  • It does not fix a slow database. More app servers can send more queries to the same database. If the database is the bottleneck, scaling the app tier makes it worse.
  • Too early is a cost. For a prototype or a low-traffic product, the added complexity is not justified.

The rule I use: write down the requirement first. If it is traffic past one machine, or surviving a server failure, scale out. If it is simply that it feels more serious, a bigger single machine is cheaper and easier to reason about.