Highlights

Contents

Part V
05

Scaling and Amdahl’s law

We ask which work can run independently. A larger fleet cannot remove a serial dependency by itself. We will compare scaling directions, expose state placement, and calculate the bound from serial work.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1Latency, throughput andLittle's law2p50, p95 and p99 latency3IOPS, bandwidth andstorage4CPU-bound, I/O-bound andbottlenecks5Scaling and Amdahl's law6Queueing and backpressure7Case study: capacityestimation

#Section 21Vertical versus horizontal scaling

Heron can move a database to a larger machine or add application instances. Vertical scaling gives a machine more resources. Horizontal scaling distributes work across more machines. Each solves a capacity problem only when the added resource serves the limiting work.

A larger machine keeps local state and coordination in one place. It can enlarge memory for cached pages, add compute, or provide stronger storage. Its limits include the available machine size, the downtime or migration needed to change it, and the consequences of losing that machine. A single hot lock can remain serial on a larger host.

More application instances distribute independently executable requests. They introduce load routing, connection budgets, deployment coordination, and more copies of local state. When state is shared in a database, the database must absorb the combined demand. Adding callers can therefore worsen the exact bottleneck you hoped to remove.

Choose the smallest change that addresses measured demand. If page misses are the limit and a larger memory tier contains the working set, vertical scaling may be enough. If independent application CPU work is the limit, additional instances may distribute it. Explain the failure behavior and state boundary alongside the capacity benefit.

WHERE THE CAPACITY IS ADDEDvertical: grow one machinehorizontal: add machinesbeforemore cores, memory, storageshared state stays local; one hot lock stays serialload balancershared staterouting, pool budgets and state need a planfirst identify independent work
Figure 2.24Illustrative scaling choices; their usefulness depends on the measured limiting resource.

#Section 22Stateless requests and shared state

A load balancer sends successive score reads to different Heron workers. A stateless request handler can complete a request using its input and shared services without requiring an earlier request to have reached the same worker. This property makes routing and replacement simpler, but the system still has state somewhere.

Move durable score records and session validation behind explicit shared contracts. Local caches may differ temporarily, so define how stale they may be and how they refresh. A worker can disappear without deleting the authoritative score. Its in-flight requests may still need retry or cancellation handling.

Now count the shared limits. Five illustrative instances with 20 database pool slots each offer 100 simultaneous operations. Doubling application instances while leaving per-instance pools unchanged doubles that offered concurrency. The database does not gain service capacity merely because the callers became easier to replace.

State placement also controls failure blast radius. A per-worker live connection belongs to that worker until reconnect; it cannot become stateless by naming the application tier stateless. A gateway needs reconnect and subscription recovery rules. State which parts can move freely and which require replay, reattachment, or coordination.

PER-INSTANCE POOLS COMBINE AT THE DEPENDENCY20 slots eachone shared database100 calls5 instances × 20 slots = 100 simultaneous operationsadding callers adds offered loaddoubling the instances offers 200; the database gains no service capacity
Figure 2.25Illustrative five instances contribute 100 shared database pool slots in total.

#Section 23Partitioning and hot work

One match attracts most of Heron’s viewers while other matches are quiet. Partitioning divides data or work into separately owned subsets. It can make independent owners scale, but one popular key can still overload its owner while the fleet average looks comfortable.

Choose the unit that can run independently. Different matches may have independent score histories, while events within a single match need an order. Adding partitions for quiet matches does little for one match’s write sequence. Viewer delivery, however, can distribute recipients across gateways without reordering the authoritative match updates.

Splitting a hot key changes the read plan. A latest-score value is easy to replicate as a derived read copy; an ordered event history may need multiple ranges merged or a sequencer retained. Count the extra messages and define which owner enforces the invariant. Distribution changes the work as well as the location.

A cache or replica can spread reads when staleness permits. Writes that update one invariant need a coordination rule even when clients run everywhere. Explain which part of the operation is parallel and which must remain ordered. That answer determines whether horizontal scaling is possible or only creates more contention.

FLEET AVERAGES HIDE ONE BUSY OWNERmatch 122%match 230%match 318%match 426%hot match96%match 620%match 724%match 828%dashed line: fleet average 33% looks comfortablescorere41e42e43e44ordered writes stay on one ownerderived read copies spread viewersspread reads without inventing writers
Figure 2.26Illustrative independent matches and one hot match show why average fleet capacity can mislead.

#Section 24Amdahl’s law, step by step

An illustrative Heron maintenance job takes 100 ms on one worker. It spends 20 ms in a serial step and 80 ms in work that can divide perfectly across workers. Amdahl’s law bounds speedup for a fixed workload with that unchanged serial fraction.

With four workers, parallel work takes 80/4=2080/4=20 ms, so total time is 20+20=4020+20=40 ms. Speedup is 100/40=2.5100/40=2.5. With eight workers, parallel work takes 10 ms, total time is 30 ms, and speedup is 3.3333, rounded to four decimals. The serial 20 ms does not divide.

S(n)=1s+(1−s)/nS(n)=\frac{1}{s+(1-s)/n}

Read this as: speedup SS with nn workers is the reciprocal of serial fraction ss plus parallel fraction 1−s1-s divided by worker count nn. Here s=0.2s=0.2. With unlimited ideal workers, parallel time approaches zero and speedup approaches 1/0.2=51/0.2=5.

The model omits added communication, scheduling, and contention, so measured speedup can be worse. It also assumes the same job rather than a larger workload. Increasing throughput by processing more independent jobs is a different question from shortening one job's serial critical path. State which outcome the calculation predicts.

ILLUSTRATIVE SPEEDUP WITH A SERIAL FRACTIONworkers nspeeduplimit 1 / 0.2 = 5×ideal if nothing were serial4 workers: 2.5×8 workers: 3.3333×S(n) = 1 / (s + (1 − s) / n), s = 0.2148163215fixed work, ideal parallel part, no communication cost
Figure 2.27Computed fixed-work speedups for illustrative serial fraction 0.2.
THE SERIAL INTERVAL DOES NOT DIVIDE1 worker20 ms serial80 ms parallel work100 ms4 workers40 ms, speedup 2.58 workers30 ms, speedup 3.33330 ms20 ms40 ms60 ms80 ms100 ms20 + 80 / 4 = 40 ms 20 + 80 / 8 = 30 msthe serial 20 ms does not divide
Figure 2.28Illustrative 100 ms job becomes 40 ms with four workers and 30 ms with eight.

#Section 25Reducing the serial fraction

After adding eight workers, the maintenance job still spends most of its remaining duration in the serial step. More workers have diminishing benefit because they reduce the smaller remaining parallel component. The next useful action is to inspect why the serial step exists.

Some order is essential, such as applying one match's updates in sequence. Other serial work comes from an avoidable shared lock, repeated setup, or a central queue. Separate the invariant from its current implementation. Sharding independent match ownership can preserve each match's order without serializing unrelated matches together.

For a second illustrative fixed-work comparison, reduce the serial fraction to 0.1 while keeping normalized one-worker work equal to one. With eight ideal workers, speedup becomes 1/(0.1+0.9/8)=4.70591/(0.1+0.9/8)=4.7059, rounded to four decimals. This illustrates the effect of the fraction; it does not claim an implementation change costs no work.

Measure the revised job from start to finish. Removing a lock can add coordination elsewhere, and splitting work can increase total CPU even when wall time improves. Keep wall-clock duration, total service demand, and useful throughput as separate outcomes. The fastest design for one request is not automatically the least expensive design for a whole workload.

REDUCING SHARED SERIAL WORK CHANGES THE BOUNDserial fraction 0.21 worker1.08 workers0.31 / 0.3 = 3.3333×limit 5×serial fraction 0.11 worker1.08 workers0.21251 / 0.2125 = 4.7059×limit 10×serialparallelnormalized one-worker work = 1, eight ideal workers
Figure 2.29Computed normalized speedups at eight workers, with illustrative serial fractions 0.2 and 0.1.