Part 2 of the eight-part How Backend Systems Scale series. Keep the separate powers-of-ten estimation reference nearby for the calculations.
A photo upload finishes, but its thumbnail doesn’t appear. A few seconds later, another upload joins it. By the end of the campaign, thousands of images are waiting.
The instinct to add workers is reasonable. It also leaves a question unanswered: what will those workers spend their time doing?
If they’re computing, more CPU may help. If they’re all waiting for the same saturated storage service, extra workers may only create a longer line there.
Let’s put numbers around the system before changing it. We’ll keep the arithmetic simple, state the assumptions, and follow the work through each tier.
On this page
- Estimate work and resources
- Estimate the whole path, one tier at a time
- A service-time estimate is a bound, not a benchmark
- Distance, serialization, and queues
- Measure the experience users receive
- Availability and the number of nines
Estimate work and resources
Count completed work
Suppose one worker processes a thumbnail in 0.2 seconds and handles one job at a time. Under those assumptions, it can complete 1 / 0.2 = 5 jobs per second.
Four independent workers could complete 20 per second. If 30 new jobs arrive every second, roughly ten more jobs join the backlog each second.
We now have useful names for four different quantities:
- Arrival rate: jobs entering per unit of time.
- Throughput: jobs completed per unit of time.
- Concurrency: jobs in progress together.
- Backlog: jobs waiting to start.
The queue holds work during a burst. It doesn’t make workers faster. If arrivals keep exceeding completions, the waiting time keeps growing.
Our capacity calculation assumes a steady job duration and no shared bottleneck. Measurements will tell us whether the workers can actually sustain it.
Concurrent work follows time spent in the system
Suppose ten jobs arrive per second, and the average time from arrival to completion is two seconds. There will be about twenty jobs in the system on average:
average jobs in the system = arrival rate × average time in the system
This relationship is Little’s Law. It connects averages over matching boundaries in a stable system. If our two-second measurement includes waiting, our count includes waiting jobs too.
It doesn’t give us a CPU count or a worst-case response time. Mixing average processing time with a count that includes the queue would change the meaning of the calculation.
Data size is a different calculation
The workers might keep up with incoming jobs while storage continues growing. Let’s estimate retained originals separately:
- 100,000 uploads per day.
- 2 MB per original.
- Thirty days of retention.
Write the inputs as powers of ten and carry their units:
uploads/day = 10^5
bytes/upload = 2 × 10^6
retention = 3 × 10^1 days
stored bytes = 10^5 × 2 × 10^6 × 3 × 10^1
= 6 × 10^(5 + 6 + 1)
= 6 × 10^12 bytes ≈ 6 TB
Uploads per day, multiplied by bytes per upload and days, leaves bytes. Using decimal storage units, the result is about 6 TB.
That is only the original images. Add the relevant costs explicitly:
- Thumbnails and other derived files.
- Metadata and indexes.
- Additional durable copies.
- Backups and their retention.
- Temporary space during maintenance or migration.
A service can have modest request traffic and still retain a large dataset.
Bigger machine or more machines?
If one machine reaches its limit, we can increase its resources or divide work across more machines:
| Choice | What changes | Useful when | Main limit |
|---|---|---|---|
| Vertical scaling | More resources in one machine | One process needs more RAM or CPU | Machine limits and a larger failure impact |
| Horizontal scaling | More machines share work | Work can be divided independently | Coordination and shared dependencies |
The division only helps if the new workers can do useful work independently. Ten workers waiting on the same constrained storage endpoint still share that limit.
Two related architecture terms describe how resources are shared:
- In a shared-memory design, workers can coordinate through memory accessible to them, usually within one machine.
- In a shared-nothing design, nodes own their memory and storage and communicate over the network.
- A horizontally scaled application can still depend on one shared database. Its application instances don’t make that storage shared-nothing.
Large machines have ceilings. Their cost also need not grow in proportion to useful capacity, so compare actual options rather than assume doubling resources always doubles cost.
Find the narrowest point
Run increasing load with realistic input sizes. Watch what changes when response times rise or errors appear:
- CPU time and utilization.
- Memory and allocation rate.
- Database query and connection waits.
- Network and storage throughput.
- Queue depth and the age of its oldest job.
- Completed work and errors.
The oldest job’s age can reveal a problem even when workers are completing many small jobs. Testing only easy inputs can hide that problem.
Protect the system while it is busy
We also need a response to demand that exceeds capacity:
- Bound waiting work so it can’t consume resources indefinitely.
- Limit each worker’s concurrency.
- Slow producers or reject excess work when necessary. This is backpressure.
- Keep spare capacity for bursts and failures.
As a quick check, five workers completing four jobs per second provide twenty completions per second. With twenty-four arrivals per second, the backlog grows by about four per second. A sixth worker matches demand under these assumptions but leaves no spare capacity.
The Go profiling guide shows how to investigate what a Go process spends its resources on.
Estimate the whole path, one tier at a time
We can apply the same arithmetic to a store’s product metadata. This time, let’s follow the estimate far enough to make a provisional placement decision.
Assume:
10^8retained product records.10^3bytes per cached entry, including the entry overhead assumed here.- Peak traffic of
10^4product reads and10^2metadata writes per second. - A plan to cache the hottest 20% of records.
- An assumed 95% hit rate for that set, to be validated against the workload.
First calculate data and working-set size
single-copy metadata = 10^8 records × 10^3 bytes/record
= 10^11 bytes ≈ 100 GB
planned cache data = 0.2 × 10^11
= 2 × 10^10 bytes ≈ 20 GB
The working set is the data actively needed by the workload. All retained data may occupy 100 GB while the chosen cached subset occupies 20 GB.
The 95% hit rate needs its own justification. It doesn’t follow from the 20% size. With uniformly random reads over equally sized records, caching 20% would produce roughly 20% hits. Popularity is what could make a smaller subset serve a much larger share of requests.
Turn usable memory into cache-node count
Suppose a cache node has 16 GB of RAM. We budget 8 GB for entries after reserving runtime overhead and spare capacity:
cache shards = ceil(20 GB / 8 GB) = 3
ceil means round up. Two nodes don’t hold 20 GB at 8 GB each, so the storage-driven count is three shards.
If we keep three total copies of each shard, that layout uses nine cache nodes. “Three replicas plus a primary” would instead mean four total copies. State the convention before multiplying.
This count addresses one constraint: memory. It doesn’t yet prove that the cache can handle the traffic or survive the intended failures.
Estimate the work arriving at each tier
For cache-aside reads and database writes followed by invalidation:
| Tier | Approximate peak work under these assumptions |
|---|---|
| Application | 10^4 + 10^2 = 10,100 requests/second |
| Cache lookup path | 10^4 lookups/second, plus fills and invalidations |
| Database read path | 10^4 × 0.05 = 500 reads/second |
| Database write path | 10^2 = 100 writes/second, plus any other required writes |
At 95% hits, 10^4 × 0.05 = 500 reads per second reach the database. The 100 writes per second still need their write path.
A read and a write need not cost the same amount. One application request can also cause several database operations. Keep the work types visible when checking storage capacity.
Now assume a load test shows one application instance meets its latency and error goals at 2,000 requests per second:
ceil(10,100 / 2,000) = 6instances meet the simplified peak while all are available.- To retain six after losing one, provision at least seven under that failure assumption.
- Add further margin where uneven routing, bursts, or slower dependencies require it.
The cache and database don’t inherit that instance count. They have their own resources and replication roles.
Cold-cache check
A warm cache sends about 500 miss reads per second to storage. A completely cold cache could send all 10,000.
That changes the design questions:
- Can storage handle the temporary increase?
- Can concurrent requests for the same missing key share one refresh?
- Can traffic ramp up gradually after cache replacement?
- Which work should wait or be rejected before storage becomes overloaded?
The warm-cache calculation helps us plan steady operation. The cold-cache calculation tests whether that plan survives an ordinary disruption.
Repeat the estimate for the database’s storage limit
Suppose each database shard has a 40 GB budget for usable application data:
storage-driven primary shard count = ceil(100 / 40) = 3
with three total database copies per shard = 3 × 3 = 9 database nodes
Those nine database nodes are a different group from the nine cache nodes. They store different representations and perform different work.
Before accepting the count, check:
- Whether the budget includes indexes.
- How much temporary space maintenance needs.
- Whether copies are placed across the intended failure zones.
- Whether each shard’s leader can sustain its writes.
- Whether a busy shard can exceed its limit despite comfortable cluster totals.
Three shards with three copies each provide three ownership groups. They don’t provide nine interchangeable destinations for arbitrary writes.
Decide when to stop calculating
An early estimate should expose a likely constraint. If data fits on one tested database with margin, sharding may add unnecessary complexity. If the cache working set exceeds usable RAM, partitioning its keys addresses a specific limit.
When a result is close to a boundary, tighten the inputs and measure. A clear interview answer might be: “Memory gives us three cache shards under these assumptions. I still need throughput and failure checks.”
A service-time estimate is a bound, not a benchmark
It’s tempting to replace a load test with a formula. A sequential worker does give us a useful starting bound:
ideal requests/second = 1 / service time in seconds
= 1,000 / service time in milliseconds
At 5 ms per request, that is 200 requests per second for the worker under those assumptions.
Now change what the five milliseconds represents:
- Five milliseconds of CPU consumes processor capacity.
- Five milliseconds waiting for I/O can leave the CPU available for another task.
- A hundred threads don’t give one core a hundred times its computing capacity.
- Locks, allocations, and shared dependencies can lower useful throughput further.
The formula helps explain a limit. A realistic workload test tells us the useful per-node capacity while meeting response-time and error goals.
Distance, serialization, and queues
Even an idle server can be slow for a distant caller. To see why, separate the network’s contributions:
| Contributor | Rough estimate | Meaning |
|---|---|---|
| Serialization or transmission | message bits / link bits per second | Time to put the bytes onto a link |
| Propagation | path distance / signal speed | Time for the signal to travel |
| Queuing | Depends on contention | Time waiting for access to a resource |
| Processing | Depends on devices and work | Time spent handling the packet or request |
For a teaching example, assume a 10,000 km path and a signal speed of 2 × 10^8 metres per second in fibre:
one-way propagation ≈ 10^7 metres / (2 × 10^8 metres/second)
= 0.05 seconds = 50 ms
round-trip propagation ≈ 100 ms
That is a physical lower-bound estimate under the chosen path assumption. Real routes, extra hops, and queues add delay. Compression can reduce the bytes transmitted; it cannot shorten the path those bytes travel.
Measure the experience users receive
We have a capacity estimate. We still need to decide what “working well” means to the people using the service.
An average hides the shape
Imagine a hundred product searches:
- Ninety-nine take 10 ms each.
- One takes 4,010 ms.
- Their average is
(99 × 10 + 4,010) / 100 = 50 ms.
A dashboard showing 50 ms and a customer reporting a four-second wait can both be accurate. The average discarded the shape of the experience.
A percentile describes a position in sorted measurements:
- p50: roughly half are at or below this value.
- p95: roughly 95% are at or below it.
- p99: roughly 99% are at or below it.
Exact calculation methods differ between tools. Name the observation window and which requests were included.
Watch throughput and failures beside duration
A service rejecting most requests might report very short response times. Duration needs its neighboring signals:
| Signal | What it tells us | What it can hide alone |
|---|---|---|
| Requests per second | Incoming demand | Whether requests succeed |
| Completed responses per second | Completed work | Work still waiting |
| Response-time distribution | How long measured requests take | Requests excluded by the measurement |
| Error rate | How often requests fail | Very slow successful requests |
| Queue age | How long waiting work has waited | Why workers are slow |
Decide how timeouts and errors appear in the measurements. A p95 of 100 ms for successful requests doesn’t establish health when 8% of all requests time out.
Turn a vague promise into a target
For example:
Over a rolling 28-day window, at least 99% of eligible product searches return a correct response within 300 ms, measured at the public service edge.
This is an illustrative target, not a universal recommendation. Each part needs a definition:
- Which requests are eligible, including invalid input.
- What makes a response correct.
- When the timer starts and stops.
- Which time window applies.
- Where the measurement is taken.
A service-edge measurement doesn’t include every delay inside a customer’s browser. Choose the boundary to match the promise you’re evaluating.
Three similar names
The measurement, its target, and a customer agreement have different roles:
| Name | Plain meaning | Example |
|---|---|---|
| SLI: service-level indicator | The measurement | Fraction of eligible searches that meet the success and time criteria |
| SLO: service-level objective | The target for that measurement | At least 99% over 28 days |
| SLA: service-level agreement | An agreement with consequences | A customer contract that defines a service commitment and remedies |
Keeping them separate lets us improve an internal objective without accidentally redefining a contractual commitment.
An error budget gives the target practical meaning
For 99% good requests, the permitted bad fraction is 1%. Across a million eligible requests, that is 10,000 bad requests, including whichever errors and deadline misses the indicator defines.
This request-based budget isn’t automatically a number of downtime minutes. An outage during a busy period can consume it faster than the same duration overnight.
The budget makes a reliability target usable in planning. It doesn’t remove the effect of failures on the people who experience them. Google SRE’s discussion explains the distinction further.
Availability and the number of nines
If the indicator instead measures available time, we can calculate a time allowance. For a thirty-day month:
| Availability | Allowed unavailable time, approximately |
|---|---|
| 99% | 7 hours 12 minutes |
| 99.9% | 43 minutes 12 seconds |
| 99.99% | 4 minutes 19 seconds |
| 99.999% | 26 seconds |
Use 30 × 24 × 60 × 60 × (1 − availability) to find the permitted unavailable seconds. For a request-based indicator, count bad requests instead.
We began with a thumbnail queue. Counting arrivals, completions, bytes, and waiting time made its limits easier to reason about. The same method gave us provisional node counts and explicit targets. Each estimate answers a particular question; none makes the other questions disappear.
Previous: From Code to Service: Requests, APIs, and Web Servers. Next: Unique IDs: Counters, Base62, Hashes, and Key Pools.