Vertical vs Horizontal Scaling: Choosing Where the Next 10x Comes From
“Should we scale up or scale out?” is usually asked too early.
The useful question comes first: what exactly is running out? CPU on the API tier? Connections on the database? Write throughput on a single partition? Memory for a cache? The answer decides the strategy far more than any general rule about vertical versus horizontal scaling.
In this article, we’ll start with how to find the bottleneck. Then we’ll look at when a bigger machine is the right call, what it really takes to scale out, why the data tier is where scaling gets hard, and why adding machines can sometimes make a system slower.
Image courtesy Wikipedia
1. Find the bottleneck first
Two simple tools go a long way.
Little’s Law
For any stable system:
concurrency = throughput × latency
A service handling 2,000 requests per second with an average latency of 50 ms has, on average, 2,000 × 0.05 = 100 requests in flight.
That number tells you how many worker goroutines, threads, or database connections you actually need. It also shows why latency regressions are capacity problems: if a slow downstream dependency pushes latency to 500 ms, the same traffic now needs 1,000 concurrent requests in flight. Connection pools and memory run out long before CPU does.
The USE method
For every resource (CPU, memory, disk, network, connection pools, locks), check:
- Utilization: how busy is it?
- Saturation: is work queueing for it?
- Errors: is it failing?
The resource that saturates first is your bottleneck. Scaling anything else just moves money around.
A common surprise is that the bottleneck isn’t hardware at all: a single global mutex, a hot row in the database, or a fixed-size connection pool. Neither scaling up nor scaling out fixes those.
2. Vertical scaling: underrated
Vertical scaling (scaling up) means giving a machine more resources: more cores, more memory, faster disks.
It has an unfair reputation as the naive option. In reality, it has real strengths.
No code changes
The application doesn’t need to know anything changed. There is no new coordination, no partitioning, and no new failure modes.
Consistency stays simple
One database on one machine gives you ACID transactions, joins and strong consistency without any distributed systems machinery.
Machines are very big now
Cloud providers offer instances with hundreds of vCPUs and multiple terabytes of memory, and NVMe storage handles hundreds of thousands of IOPS. Many workloads that “needed” a distributed database fit comfortably on one well-tuned machine.
The limits are real too:
- The cost curve bends upward. The largest instance sizes often cost disproportionately more per unit of capacity.
- There’s a ceiling. When you hit the largest available machine, you have nowhere left to go, and you’ll be redesigning under pressure.
- One machine is one failure domain. You still need replicas for availability, even if they don’t serve traffic.
- Resizing often means a restart, which needs a failover plan.
- Not everything scales with cores. A single-threaded event loop or a hot lock won’t go faster on a 96-core machine.
A good rule: if one more size up on the current machine buys you a year or more of growth, it’s often the cheapest engineering decision available. Spend the saved effort on the problems that really need it.
3. Horizontal scaling for stateless services
Horizontal scaling (scaling out) means adding more machines and spreading the work between them.
For a stateless service tier, this is the default, and it’s mostly a solved problem: put instances behind a load balancer and add more as traffic grows. Autoscaling makes it elastic.
The catch is the word stateless. Many services contain state that only becomes a problem once a second instance appears. User sessions are the classic example:
type SessionStore interface {
Get(ctx context.Context, id string) (*Session, error)
Put(ctx context.Context, id string, s *Session, ttl time.Duration) error
}
// memoryStore works perfectly on one instance. Behind a load balancer,
// a user's next request lands on another instance and their session is gone.
type memoryStore struct {
mu sync.RWMutex
sessions map[string]*Session
}
// redisStore moves the state out of the process, so any instance
// can serve any request.
type redisStore struct {
rdb *redis.Client
}
func (r *redisStore) Get(ctx context.Context, id string) (*Session, error) {
data, err := r.rdb.Get(ctx, "session:"+id).Bytes()
if errors.Is(err, redis.Nil) {
return nil, ErrNoSession
}
if err != nil {
return nil, err
}
var s Session
if err := json.Unmarshal(data, &s); err != nil {
return nil, err
}
return &s, nil
}
func (r *redisStore) Put(ctx context.Context, id string, s *Session, ttl time.Duration) error {
data, err := json.Marshal(s)
if err != nil {
return err
}
return r.rdb.Set(ctx, "session:"+id, data, ttl).Err()
}
Sticky sessions at the load balancer can hide this problem, but they come back to bite you during deploys, scale-in events and instance failures.
Making a service genuinely horizontally scalable usually also means:
- Externalizing state: sessions, caches, uploaded files and scheduled jobs all need a home outside the process.
- Graceful shutdown: draining in-flight requests when an instance is removed.
- Health checks that reflect whether the instance can actually serve traffic.
- Idempotent operations, because load balancers and clients retry, and the retry may land on a different instance.
- Coordinated background work: a cron job that ran once on one instance now runs ten times on ten instances, unless something coordinates it.
Notice where the state went: into Redis and the database. Scaling out the stateless tier doesn’t remove state. It concentrates it in the data tier, which is where scaling gets hard.
4. Scaling the data tier
Databases are where the real trade-offs appear. There are three main techniques, roughly in order of increasing complexity.
Read replicas
Copy data to replicas and send reads to them. This works well for read-heavy workloads, but replication is usually asynchronous, so replicas lag behind.
The classic bug: a user updates their profile, the page reloads from a replica, and their change appears to have vanished. You’ll need a read-your-writes strategy, such as routing a user’s reads to the primary for a short period after they write.
Caching
A cache absorbs repeated reads and can reduce database load dramatically. In exchange you have to deal with invalidation, stale data, and the thundering herd that hits the database when a popular key expires.
Partitioning (sharding)
When writes or total data volume outgrow one machine, split the data across several machines by key. This is the only technique that scales writes, and it’s the one with the most lasting consequences:
- Queries and transactions that span partitions become expensive or impossible.
- A badly chosen key creates hot partitions (one celebrity account, one large tenant).
- Adding partitions means moving data.
That last point depends heavily on how keys are assigned. The obvious approach is hash(key) % N. Here’s what happens when you grow from 4 shards to 5, compared with a consistent-hash ring:
func hashKey(s string) uint32 {
h := fnv.New32a()
h.Write([]byte(s))
return h.Sum32()
}
// Ring is a minimal consistent-hash ring with virtual nodes.
type Ring struct {
points []uint32
owner map[uint32]string
}
func NewRing(nodes []string, vnodes int) *Ring {
r := &Ring{owner: make(map[uint32]string)}
for _, n := range nodes {
for v := 0; v < vnodes; v++ {
p := hashKey(n + "#" + strconv.Itoa(v))
r.points = append(r.points, p)
r.owner[p] = n
}
}
sort.Slice(r.points, func(i, j int) bool { return r.points[i] < r.points[j] })
return r
}
func (r *Ring) Lookup(key string) string {
h := hashKey(key)
i := sort.Search(len(r.points), func(i int) bool { return r.points[i] >= h })
if i == len(r.points) {
i = 0 // wrap around the ring
}
return r.owner[r.points[i]]
}
func main() {
const keys = 1_000_000
before := []string{"db-0", "db-1", "db-2", "db-3"}
after := append(append([]string{}, before...), "db-4")
ringBefore, ringAfter := NewRing(before, 200), NewRing(after, 200)
movedMod, movedRing := 0, 0
for i := 0; i < keys; i++ {
k := "user:" + strconv.Itoa(i)
h := hashKey(k)
if h%4 != h%5 {
movedMod++
}
if ringBefore.Lookup(k) != ringAfter.Lookup(k) {
movedRing++
}
}
fmt.Printf("hash %% N: %.1f%% of keys moved\n", 100*float64(movedMod)/keys)
fmt.Printf("consistent hash: %.1f%% of keys moved\n", 100*float64(movedRing)/keys)
}
Output:
hash % N: 80.0% of keys moved
consistent hash: 17.6% of keys moved
With modulo hashing, adding one shard relocates 80% of all data, which in practice means a large, risky migration. With consistent hashing, close to the theoretical minimum of 1/5 (20%) moves, and only onto the new node. This is why Cassandra and DynamoDB use consistent hashing, and why systems like CockroachDB and Vitess split data into many small ranges or shards that can be moved individually.
5. Why adding nodes can make things slower
It’s tempting to assume that twice the machines means twice the throughput. Neil Gunther’s Universal Scalability Law explains why it doesn’t:
N
C(N) = ─────────────────────────
1 + α(N − 1) + βN(N − 1)
Nis the number of nodes (or threads, or cores).αis contention: work that is serialized, such as a shared lock, a single leader or a single hot row.βis coherence: the cost of nodes keeping each other in sync, such as cache invalidation, replication or cross-node coordination.
With α alone you get Amdahl’s law: throughput approaches a ceiling. With any non-zero β, throughput eventually peaks and then declines, because coordination costs grow with the square of the node count.
This is why simply adding nodes stops helping, and why the most scalable designs work so hard to avoid coordination: partitioning so that most operations touch one shard, asynchronous replication where it’s acceptable, and keeping consensus off the hot path.
6. A decision framework
| Situation | Usually the better first move |
|---|---|
| Stateless service, CPU-bound, traffic growing | Scale out behind a load balancer |
| Relational database, moderate growth, needs transactions | Scale up, then add read replicas |
| Read-heavy workload | Caching and read replicas |
| Write volume or dataset exceeds the largest machine | Partition (and choose the key carefully) |
| Need to survive the loss of a machine or zone | Replicate across failure domains, whatever the capacity plan |
| Bursty or unpredictable traffic | Scale out with autoscaling and load shedding |
| Bottleneck is a lock, hot key or serial step | Neither: fix the design |
In practice, mature systems do both: a horizontally scaled stateless tier in front of a data tier that is scaled up as far as is sensible, then replicated, and partitioned only where it must be.
7. What this means for production systems
- Measure before choosing. Know which resource saturates first and at what load.
- Don’t dismiss scaling up. A bigger machine is often the lowest-risk way to buy time, and time is valuable.
- Make stateless tiers truly stateless. Find hidden state before the second instance finds it for you.
- Choose partition keys as if you’ll live with them for years, because you will.
- Plan capacity ahead of demand. Scaling a stateful system during an incident is the hardest possible time to do it.
Conclusion
Vertical and horizontal scaling aren’t competing philosophies. They’re tools for different bottlenecks.
Scaling up is simple, keeps consistency easy, and goes further than most people expect. Scaling out is unbounded in principle, but it pushes state into the data tier, adds coordination costs, and turns resharding into an engineering project. The skill lies in knowing which resource is actually running out, and choosing the least complex change that buys the most headroom.
What’s next?
Once data is partitioned across machines, a single business operation may need to update several of them at once. Making that atomic is the subject of:
Further reading:
Comments