Highlights

Contents

Part I
01

Latency, throughput and Little’s law

We count arriving work, completed work, and the time spent between them. A service can finish many requests while making each viewer wait. We will follow one request, separate rates from durations, and derive the concurrency budget.

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 1Latency versus throughput

You open Heron’s score page and wait while thousands of other viewers do the same. Your wait and the service’s completed-request count answer different questions. Latency is elapsed time between a chosen operation’s start and finish. Throughput is work completed per unit time. Neither number tells the whole story alone.

Mark the boundaries before measuring. Client latency includes network travel and browser work when those occur inside the timer. Application latency may start only after a proxy has accepted the request. Database latency can exclude waiting for a connection. Each timer can be correct while reporting a different duration for the same user action.

Suppose our illustrative service accepts 1,000 requests during a second and finishes 900 successfully. Arrival rate is 1,000 requests per second, useful throughput is 900, and the difference is 100 requests. Those requests might wait, fail, or still be executing. Calling the arrival count throughput hides that distinction and makes overload look like success.

A faster response does not necessarily increase fleet throughput. Removing a network wait helps a viewer, but a shared write lock may still cap completions. More asynchronous callers may increase completions while increasing each caller’s queueing delay. Say which outcome you need before suggesting a fix.

ILLUSTRATIVE DAILY AVERAGE AND PEAKhour of dayrequests/sdaily average 100 req/smatch start: peak 1,000 req/s00:0006:0012:0018:0024:00the average hidesthe match-start burst8,640,000 requests / 86,400 s = 100 req/s, × 10 at peak = 1,000 req/scurve shape illustrative; its mean is exactly the daily average
Figure 2.1Illustrative daily demand is 8,640,000; average and peak rates are computed.

#Section 2Where one request spends its time

A score lookup feels like one action, but several clocks run inside it. The proxy waits for an application worker, the worker waits for a database connection, and the query waits for its result. Service time is time actively consuming the resource being studied. Queueing time is time waiting to receive that service.

Our illustrative trace spends 30 ms reaching the application, 20 ms waiting for admission, 10 ms acquiring a database connection, 40 ms on database work, and 100 ms returning and finishing the response. Adding these sequential intervals gives 200 ms. The database’s 40 ms measurement is only part of the viewer’s 200 ms experience.

Draw the intervals along one timeline. A parent span contains a child span, so adding both durations counts the same time twice. Parallel calls overlap, so their durations also cannot simply be added. Sum disjoint sequential intervals; use the latest completion when the parent waits for parallel children.

Now imagine reducing database work while leaving pool acquisition untouched. The query chart improves, yet an exhausted pool can still dominate the user’s wait. Inspect the longest unexplained interval, then identify the resource or policy that owns it. This gives the optimization a specific target instead of treating latency as one undifferentiated number.

DISJOINT INTERVALS ADD TO 200 MSparent span: whole request, 200 msreach app · 30 msproxyadmission wait · 20 msapppool wait · 10 msappDB query · 40 msdatabasereturn + finish · 100 msapp + network0 ms50 ms100 ms150 ms200 ms30 + 20 + 10 + 40 + 100 = 200 msadding the parent span as well would count 400 ms: every wait twicethe database sawonly 40 of them
Figure 2.2Illustrative disjoint intervals sum to 200 ms; overlapping spans must not be added again.

#Section 3Daily averages and peak demand

Heron receives 8,640,000 API requests in an illustrative day. Dividing by the day’s 86,400 seconds gives 100 requests per second. This is useful for daily traffic totals, but match starts concentrate demand. Our assumed peak multiplier of 10 gives 1,000 requests per second, with no claim that a real service has this exact shape.

Queries per second, abbreviated QPS, counts queries inside a named measurement boundary. Interview sizing often uses the same arithmetic for incoming API requests, so say which operations the count represents. One API request can issue several database queries, and a cache hit can issue none. Heron’s 100 average API requests per second is therefore not automatically 100 database QPS.

λavg=D/T\lambda_{\text{avg}}=D/T

Read this as: average arrival rate λavg\lambda_{\text{avg}} equals request count DD divided by observation duration TT. Keep the time units consistent. If the observation is a day, the denominator must be seconds per day when the output is requests per second.

A window can conceal its own burst. An illustrative pair of 10-second windows contains 3,000 requests and 7,000 requests. Their rates are 300 and 700 requests per second. Combining them reports 500 requests per second over 20 seconds, even though the second window needs more capacity than that average suggests.

Record the peak's duration and what causes it. A brief rush can fit in a bounded queue; a long capacity deficit cannot. Separate background traffic, reconnects, scheduled jobs, and viewer demand when they coincide. The question is whether the whole arriving workload fits through the path while its deadlines remain useful.

THE SAME AVERAGE HIDES DIFFERENT WINDOWSsecondsrequests/scombined: 10,000 / 20 s = 500 req/s300 req/s700 req/s2,000 requests above 500/s0 s10 s20 s3,000 requests in 10 s = 300/s7,000 requests in 10 s = 700/s
Figure 2.3Illustrative window counts produce rates of 300 and 700 requests/s, with a combined rate of 500 requests/s.

#Section 4Concurrency and Little's law

A viewer request remains inside the service while it waits and runs. Count those unfinished requests as concurrency, or work in progress. Idle keep-alive sockets are connections, but they are not automatically unfinished requests. A system can have many open sockets and little request concurrency.

Little's law connects long-run mean work in progress, mean completion rate, and mean time inside the same boundary. In a stable operating interval, every completed request contributes its residence time to the total work-in-progress area. Dividing that area by the observation duration produces the mean number present.

L=λWL=\lambda W

Read this as: mean concurrent work LL equals mean throughput λ\lambda times mean residence time WW. Heron's illustrative peak of 1,000 requests per second and mean residence time of 0.2 seconds gives 200 concurrent requests. The seconds cancel, leaving requests. This uses the mean duration, not the p99.

A queue that keeps growing has no sustainable steady-state mean to size around. You can still measure finite-window quantities, but you must account for unfinished requests and changing backlog. Do not use a short observation of completions to declare a permanently overloaded system stable. Check arrivals, departures, and work in progress together.

THE UNITS CANCEL TO REQUESTSinside the service boundary: 200 requestseach stays 0.2 s on average (the mean, not the p99)1,000 requests/s arrive1,000 complete/sL = λW = 1,000 /s × 0.2 s = 200 requestsseconds cancel, leaving a count of unfinished requests
Figure 2.4Illustrative steady-state rate times mean duration gives 200 active requests.

#Section 5Concurrency budgets and connection pools

Heron can have 200 requests in flight without needing 200 database connections. Some requests wait on the client network, some read a cache, and some already released their connection. A connection pool shares a bounded set of reusable connections so opening sockets is not part of every query.

Assume each database operation occupies a connection for an illustrative 10 ms. A pool with 20 continuously busy connections has an ideal upper bound of 20/0.01=2,00020/0.01=2,000 operations per second. This is only a residence-time bound. The database might saturate its CPU, storage, or locks before reaching it.

Measure pool-acquisition duration separately from connection-hold duration. If acquisition grows while query time stays flat, callers wait before the database timer starts. Adding pool slots may move that wait into the database instead. It can also make memory use and lock competition worse without producing more useful completions.

Set a pool budget across the fleet. Five application instances with 20 slots each can offer 100 simultaneous database operations. A per-instance limit that looks small can become a large shared load after horizontal scaling. Bound acquisition by the request deadline, release connections on cancellation, and reserve capacity only when the workload requires it.

CONNECTION HOLD TIME SETS AN OCCUPANCY BOUNDapp instancedatabase20 pooled connectionsone slot0 ms10 ms20 ms30 ms40 ms50 ms1 / 0.01 s = 100 ops/s20 slots / 0.01 s = 2,000 ops/s, an ideal ceilingthe database maylimit it first
Figure 2.5Illustrative 20-slot pool and 10 ms hold time imply an ideal 2,000 operations/s ceiling.