Vertical vs Horizontal Scaling: What Changes When You Add Machines

By Arkaitz

Should we scale vertically or horizontally? is not a real question yet. It becomes one only when you ask what each option commits you to.

Vertical scaling gives one machine more resources. Horizontal scaling adds machines.

That definition is the least useful sentence here. The difference that matters: vertical scaling changes a number in a console, and horizontal scaling changes the shape of your program. One is a capacity decision you can reverse. The other is a state decision wearing a capacity decision's clothes.

You know the small end of this argument. You can run a store with a hundred users on one server, one process, one database file, and it is correct. The system design procedure is that argument in checklist form. This post starts where it stops: the day your box is not enough and someone suggests a second box.

My example throughout is a composite you will recognise. A booking product I'll call Meridian runs on one 8-core, 32 GB app server, one PostgreSQL primary of the same size, a 60 GB database, cookie sessions, local-disk uploads, a 2,000-entry in-process cache, and jobs in a table polled every five seconds. It peaks at 120 requests per second and 4,000 concurrent users, at 45% CPU. Treat it as a worked example, not a client story.

Vertical vs Horizontal Scaling: What Is the Difference?

Vertical scaling gives one machine more CPU, memory, disk, or network. Horizontal scaling adds machines and distributes your work across them. You keep one machine, one failure domain, and one copy of everything in the first case. You get N machines in the second, and every piece of shared state becomes a service, a protocol, or a bug.

You cannot treat these as symmetric choices. Resize, and your code does not change. Add a machine, and your code changes in ways that have nothing to do with throughput: where your session lives, which instance owns the scheduled job, whether your cache read may be stale, how many connections your database sees, and what happens to a request that started on the machine you just drained.

Machines and services are different axes. Running two app servers from the same binary is a scale-out. Splitting into two services with separate deployables is an architecture split with its own trade-offs, which monolith vs microservices covers. You can scale out a monolith without splitting the codebase.

Why should you scale up first?

Memory is the resource teams leave out of the capacity count, and the RAM apocalypse coming for web developers is what that omission looks like on the client.

Because scaling up is one decision, and scaling out is a dozen decisions you take on the same afternoon. One instance size, one bill line, one failure domain, one place to look when the graphs go wrong. That is the argument, and it is usually worth more than the price difference.

Your ceiling is higher than you think. You can rent one cloud instance with 1,920 vCPUs, 32 TiB of memory, 200 Gbps of network, and 160 Gbps of EBS bandwidth. If you are weighing a second app server, you are near the ceiling of the size you picked, not the ceiling of the hardware. Check the next two sizes before you redesign anything.

You can see the same pattern at real scale. Stack Overflow in 2016 served 209 million HTTP requests a day from 11 IIS web servers and four SQL Servers — and Nick Craver's line is that they were down to ***needing*** only 1 web server, which they had tested accidentally and successfully several times. Their web tier bought redundancy and rolling deploys; the write tier stayed one master per cluster. You are allowed to scale out the cheap tier and leave the hard tier alone.

Your vertical scaling has honest costs, so name them. A resize usually costs you a reboot or a live migration with a maintenance window.

You buy sizes in steps, not on a smooth dial — the U7i family runs 6 to 32 TiB — so you pay for the whole next step, including headroom you will not use for months. You stay inside one failure domain. And you hit a hard stop: when the biggest instance in your budget is smaller than your working set, your ladder ends.

The asymmetry you should care about is reversibility. A resize you can undo in a maintenance window. A shard key you cannot.

When does adding machines make a system slower?

When the work of keeping copies in agreement grows faster than the capacity you added.

You can model it, and it has a name: the Universal Scalability Law. You can write your relative capacity as C(p) = p / (1 + σ(p−1) + κp(p−1)), where p is your number of nodes. Your σ term is contention: serialisation, locking, queueing for a shared resource. Your κ term is coherency: the cost of keeping inconsistent copies of data in agreement.

With κ > 0, your curve peaks at p* = sqrt((1−σ)/κ) and goes retrograde beyond it. Past that point you add capacity and get less throughput.

Your coherency term is κp(p−1), so it grows with the number of pairs you run. Two nodes gives you two ordered pairs; eight nodes gives you 56. If each pair exchanges updates to keep a cache coherent, your coordination traffic grows roughly with the square of the fleet while your useful capacity grows linearly. You have seen that shape: teams double the pods and p95 gets worse.

Gunther's classification puts your shared-writable data in the worst case, and names online reservation systems and updating database records as examples. Meridian is a reservation system, so you are in that bucket. The workload you are most likely to be told to scale out is the one where instances buy you the least.

Split your workload by what it shares. Read-only fan-out — a catalogue, a rendered page, a public profile — scales close to linearly, because you have nothing to reconcile. Write-sharing fan-out — inventory, bookings, balances, counters — charges you the κ term on every copy. You do not need a model, only one answer: when two instances disagree, who wins, and how do they find out?

What happens to state when you add a second machine?

Four things that were free become infrastructure: sessions, uploads, local caches, and in-process jobs. On one box, you keep each as a variable or a file path. On two boxes, each is a distributed-systems question, and the second box is where you pay for all four.

Here is your Meridian list, and it is typical:

  • Sessions. A signed cookie survives any instance you add. A server-side session file does not. If you run one box with a local session store, the first instance you drain logs out every user it was serving.
  • Uploads. A local uploads/ directory on box A is a 404 on box B. You need object storage or a shared volume before the balancer exists.
  • Caches. Your 2,000-entry in-process cache becomes 2,000 entries per instance, with no guarantee any two agree. You have a coherence problem, not a memory problem.
  • Jobs. A five-second poller runs once on one box. On four boxes it runs four times, in parallel, on the same rows, so the same hold can be released twice.

The rule that keeps this cheap: state you can afford to lose stays local; state you cannot afford to lose must be external and reachable from any instance before the second instance takes traffic. That is not a scaling optimisation. It is the entry fee.

If you find yourself choosing a partition key for this state, you have left this post. You are in the six decisions that make a system distributed, and the first one — where state lives and how you cut it up — is the one you cannot take back cheaply.

What happens to sessions and caches on N machines?

Sessions need a shared store or a stateless token, and caches need an invalidation channel. Sticky sessions give you neither; they are a delay. They hide the mismatch until the first instance failure, then hand you a user with a new instance and no state.

AWS's documentation is blunt about the limit you are buying. Sticky sessions bind your client to one target for a duration you choose between one second and seven days, and the balancer's cookie expires after seven days regardless. When your target becomes unhealthy, the balancer picks a new healthy target and treats your session as stuck to it, even if the old target comes back. Your user keeps the cookie.

The state you left on the old box is gone. Stickiness buys continuity in the happy path and removes it in the failure you were trying to survive.

So you pick one of two designs. Your session is a signed, encrypted cookie the client carries — stateless, no store, a good default for a small product, and what this example uses. Or your session lives in Redis, keyed by an opaque ID you can revoke. What you cannot do is keep it in process memory and hope the balancer is feeling stable.

Caches are the same argument. Every local cache you keep is a copy, and every copy needs a rule for when it stops being true. Redis's client-side caching shows you the shape: the server tracks which keys each connection has read and sends an invalidation message when one changes. It also shows you the trap.

If any connection drops — including one from a pool — your client flushes its entire local cache, and caching resumes only on the connections that survive. A pool recycle can turn a warm fleet cold at once.

Stack Overflow ran the pragmatic version you can copy: an L1 cache on each web server, an L2 in Redis, and Redis pub/sub used to clear L1 caches on other servers when one web server does a removal for consistency. That is the tax: a message bus whose only job is to tell N copies that one of them changed. The channel exists because you chose copies.

How many database connections do N app servers need?

Far fewer per instance than the default configuration suggests, and the total is what bites. PostgreSQL's max_connections is typically 100 by default, and the server sizes resources directly from that value, including shared memory. It also forks one operating-system process per connection.

Start from the PostgreSQL project's formula: connections = (core_count * 2) + effective_spindle_count, which the project says has held up across benchmarks. HikariCP's commentary is the part you read aloud in a review. A 4-core box with one disk wants about 9–10 connections, not 100.

Even 100 connections, overkill, they write, and the PostgreSQL benchmark they cite flattens around 50. An Oracle demo they cite cut 2,048 connections to 96 and dropped response time from roughly 100 ms to 2 ms. Nothing in that formula mentions your request rate.

Now do the Meridian arithmetic. Your one app server with 8 physical cores — HikariCP excludes hyperthreads from the count — sits at about 16 connections. Four at the same pool size is 64, before a worker, a migration job, and an exporter. Against max_connections = 100, that leaves you little headroom — and the failure looks like random 500s, not like a capacity problem.

The fix that tempts you is a bigger max_connections. The docs tell you why that is not free: your server's resource allocation scales with it. The better fix is a pooler, sized for the database's cores rather than your fleet's replica count. Then its server pool, not your app pools, is what counts against the 100.

You will usually choose transaction-mode pooling, and it changes what a connection can assume between statements — PgBouncer's FAQ has a whole entry on prepared statements there. That is a constraint on your ORM, not a config flag.

The counter-intuitive takeaway: adding app servers does not add database capacity. It multiplies your demand on a budget sized for one machine's cores.

Why does the database primary stay a primary?

Because your writes go to one writer, and replicas buy you read throughput and availability, not write throughput. This is where just add more instances stops being available, however many app servers you own.

Aurora states the ceiling you hit. A cluster allows up to 15 Aurora Replicas, all read-only, and write operations are managed by the primary instance. Replica lag is usually much less than 100 milliseconds and grows when your write rate rises. Fifteen readers behind one writer is a generous read tier you can use. It is not a second writer.

Self-managed PostgreSQL is sharper. Streaming replication is asynchronous by default, with a delay typically under one second when the standby keeps up, so your replica can be missing transactions that already committed. You do not get read-your-writes for free.

The docs describe the workaround: take the primary's WAL insert LSN and run WAIT FOR LSN on the standby before you read. Synchronous replication fixes the staleness and charges you for it: every commit waits at least the round trip between primary and standby, and your transaction locks are held until the transfer is confirmed. The docs warn that incautious use costs response time and contention.

That gives you a decision tree. If reads are your constraint, replicas and caches help, and you owe each read class a staleness rule you wrote down. If writes are your constraint, replicas do nothing, and you are into partitioning, the expensive rung. Name your constraint before you buy the replica, because the two answers point in opposite directions.

What happens to queues and ordering on N machines?

Your consumer parallelism is capped by partition count, and ordering survives only inside a partition. That is the cost of fanning out background work.

Kafka gives you the model plainly: topics are partitioned, events with the same key go to the same partition, and your consumer of a topic-partition reads that partition's events in written order. Kafka does not promise you order across partitions. So your partition count is both your maximum consumer parallelism and the granularity of your ordering guarantee.

Choose three partitions and you have three workers and three independent orders. Choose one to preserve global order and you have rebuilt the single writer you were trying to leave.

In Meridian, you turn the poller into a queue with one job per booking. Key by booking ID and each booking's events stay ordered while different bookings process in parallel — usually the right answer for you. Key by nothing and spread events across partitions, and a cancel can overtake the create it was meant to cancel.

You meet the same shape in any sharded store. Redis Cluster splits your key space into 16,384 hash slots, and multi-key operations work only when every key involved hashes to the same slot; hash tags are the documented workaround. Sharding does not just move your data. It invalidates every operation you wrote assuming one place to look.

For the delivery-semantics half — at-least-once, replay, and the delivery guarantees — read queues vs streams.

What changes about deployment and failure on N machines?

A deploy becomes a period when two versions are live, and a failure becomes a question about how many machines share the same cause. Both are manageable, and neither is optional.

Start with your deploy. One box, one restart. Four boxes, and a rolling release means old and new code answering requests at once, so your schema must be compatible with both.

The documented discipline you want is parallel change — expand, migrate, contract: add the new shape, move callers, remove the old shape. Its write-up names deployments and blue-green as applications of the pattern, and states the cost: during migrate you support two versions, and if you never contract, you can end up worse than you started.

Then the drain. AWS's default deregistration delay is 300 seconds, and a target that terminates a connection before that elapses gives your client a 500-level error; new requests during draining go to healthy targets. Teams shorten it, and in-flight requests fail when they shorten it too far.

The same page gives you slow start, a linear ramp for new targets. That is the vendor admitting your cold instance should not take a full share — your cold JIT, empty cache, and unopened pool are the reason.

Now failure. Four machines means four chances of a hardware fault, but your correlated risks matter more: the same bad config pushed to all four, the same dependency missing for all four, the same deploy that passes health checks and dies under load. Adding machines turns independent failures into a blast-radius question, and blast radius is your design choice — the subject of how to design a highly available system, not a side effect of instance count.

One more: every scheduled task now runs N times unless you make it a singleton. You need a leader election, a database advisory lock, or a queue with one consumer. The cron job that was fine on one box is a duplicate-charge bug on the four you now run.

What does the cost curve look like at each step?

Your vertical cost is a step function; your horizontal cost is additive and metered. That difference explains most arguments about which is cheaper, because each side is comparing a different curve.

Vertically, you buy in steps. Sizes come in coarse jumps: you pay for the next one, including headroom above your need, and you may sit at 30% utilisation for months.

In exchange, your bill has one line. You have no balancer, no cross-zone replication traffic, no per-node observability agent, and no new failure mode. Use your provider's price list for the two sizes you are choosing between; the shape transfers, my arithmetic would not.

Horizontally, you buy a stack. Instances scale roughly with count, but they are not your whole bill.

A load balancer bills you hourly plus capacity units in the major clouds. Cross-zone traffic is metered in both directions. Observability is priced per host or per gigabyte of logs, and the pooler is another process for you to run.

Then there is the line item nobody puts in the spreadsheet: your engineering time to externalise state, choose partition keys, and debug a request that touched four machines. You pay that permanently, not once.

So you compare cost per unit of delivered capacity, not price per vCPU. Your horizontal tier delivers less than the sum of its parts whenever your workload shares writes. A four-instance tier that spends a fifth of its cycles on cache invalidation delivers a bit over three instances of capacity. That is the κ term showing up in your finance spreadsheet.

What is the order of operations when you must scale out?

Find the saturated resource, grow the box if you can, externalise state, then add stateless compute, then read capacity, and only then partition writes. Skip a rung and you end up with four app servers, a Redis cluster, and the same p95 you had before.

  1. Name the resource you have saturated. CPU, memory, disk IOPS, network, database CPU, lock waits, or connection count. Each has a different fix, and resizing the wrong dimension is the most common wasted quarter. Your database at 90% CPU does not care that your app servers are idle.
  2. Grow the box if the ceiling allows. Record the new ceiling and next step size in your runbook.
  3. Externalise your state before the second instance. Sessions, uploads, caches, scheduled jobs. This is a prerequisite, not a performance task. Do it under load with a broken deploy and you get an outage.
  4. Add stateless compute behind a balancer. Set your drain timeout and slow-start window deliberately, and learn what a 500 during drain looks like.
  5. Add a pooler and a read path. Size the pool for the database's cores, then give each read class a staleness budget, so replica lag is a product decision.
  6. Add caches and read replicas for reads. Only after step 5, and only if reads are your constraint.
  7. Partition your writes last. A shard key, a partition count, a slot map. This is the rung you cannot undo in a maintenance window, because changing it moves your data.

The order is sorted by reversibility, and each rung removes options you will want later. That is why scale up first is not conservatism. You are buying time in the currency you will need later: the ability to change your mind.

You will struggle with horizontal scaling for a reason that has nothing to do with balancers. You treat a state decision as a capacity decision, add machines, and discover that every copy of your data needs an owner, an invalidation rule, and a failure story.

Vertical scaling asks how much machine you need. Horizontal scaling asks you where the truth lives. Answer the second question before you buy the third server.

Related Reading