One slow backend call in a hundred sounds rare. A page that waits for 20 calls meets a slow one on 18.2% of loads, and the average page time never shows it.
Drag the number of backend calls each page makes, and watch the red dots: pages slower than the 100 ms target. Then we turn "fast", "reliable", "scalable" and "maintainable" into numbers, one at a time.
You need a little Python and what a probability is. We build the rest from zero.
Illustrative model. A normal call takes about 10 ms; a slow call takes 120 ms or more. A page waits for its slowest call. The share of slow pages comes from Chapter 3's formula; the mean, median and p99 come from this run of 400 pages.
Chapter 0
Put a number on "fast" and "reliable", and the right design falls out
A manager asks for a checkout service that is "fast and reliable". One engineer proposes one big server. Another proposes twenty servers in two data centres. Who is right? Nobody can say, because nobody said how fast, how reliable, or for how many customers.
A functional requirement says what the system does: take an order, show a timeline. A nonfunctional requirement says how well it does it: how quickly, how often it is up, how much load it carries, how easy it is to run and change. "Fast" is a wish. "99% of checkouts answer in under 200 ms at 5,000 requests a second" is a requirement.
Each square is one server. Warm is busy, pink is paid for but idle, and a red bar is requests dropped. Drag the real peak load.
Illustrative: each server handles 1,000 requests a second. "Sized to a number" buys enough servers to stay 70% busy at the stated peak; Chapter 7 derives that rule.
At a peak of 5,000 requests a second, the one big server handles 2,000 and drops 3,000: 60% of customers fail. The fleet of 20 is 25% busy, so 15 servers' worth of capacity is paid for and idle. The design sized to the number needs 8 servers, each 62.5% busy. Only the number could tell you that.
This lesson follows Chapter 2 of Designing Data-Intensive Applications, 2nd edition, by Martin Kleppmann and Chris Riccomini (O'Reilly, 2026). The chapter opens with a social network's home timeline, then defines performance, reliability, scalability and maintainability. We explain the ideas in our own words, with our own examples and numbers. Chapter 1 covered the big architecture trades.
Failure. Symptom: the launch goes down at the first traffic spike. Measure: the peak load nobody wrote down, against the capacity nobody tested. Cause: the requirement was "it should scale". Fix: write the peak request rate, the latency target and the uptime target before any design.
Chapter 1
Count the work behind one home timeline, and see where a celebrity breaks the plan
A social network shows each user a home timeline: the recent posts of everyone they follow. One post fans out to many readers, and one timeline gathers posts from many authors. Someone must do that gathering. The question is when.
Fan-out on read (pull) builds the timeline when the user opens it: look up the latest posts of each account they follow and merge them. Fan-out on write (push) does the work when someone posts: insert the post into a stored timeline for each follower. Reading is then one lookup. Each stored timeline is derived data, a cache of the merge.
Both cost the same shape of work. Call the rate of events that trigger it R, and the number of items each event touches k, the fan-out. The work per second is C.
C equals R times k.
Take how often the work is triggered, R. Multiply by how many items each trigger touches, k. That is C. Choose the side where R is smaller.
With made-up numbers: 300,000 timeline views a second, 6,000 posts a second, and k = 200 on average. Pull: C = 300,000 × 200 = 60 million lookups a second. Push: C = 6,000 × 200 = 1.2 million inserts a second, 50 times less.
Blue dots are posts in flight, teal boxes are stored timelines, and the bars use a log scale. Pick a strategy, change how often people read, then let a celebrity post.
Illustrative network: 6,000 posts a second, 200 follows each, and in hybrid each user follows 2 celebrity accounts that are pulled at read time. Write capacity is sized to 1.2 million inserts a second.
Push wins while views outnumber posts, which is the common case. Its weak point is the celebrity: one post from an account with 50 million followers is 50 million inserts, about 42 seconds of the whole write capacity. The hybrid answer pushes normal accounts and pulls the few huge ones when a reader opens the page.
Failure. Symptom: followers see a celebrity's post minutes late, and other posts queue behind it. Measure: the insert backlog right after one large account posts. Cause: push fan-out of one post to tens of millions of timelines. Fix: pull accounts above a follower threshold at read time.
Chapter 2
Sort the samples, read the value at a rank, and stop trusting the mean
Response time is what the client measures: from sending a request to getting the answer. Service time is the part the server spends working on it. The rest is waiting, in queues and on the network. Throughput is how many requests the system finishes each second.
Send the same request a thousand times and you get a thousand response times. A garbage-collection pause or a lost packet makes some slow. So one number must say which part of the spread you mean.
The mean is a poor choice. Take 1,000 requests: 950 take 5 ms, 49 take 50 ms and 1 takes 5,000 ms. The mean is 12.2 ms, a time that no request had.
A percentile says instead: p percent of requests were at least this fast. The median is p50. The tail is p99 and above.
To find it, sort the N samples from fastest to slowest. Call the percentage you want p. The rank you read is r, and the value there is the percentile.
r equals the ceiling of p over 100 times N, and the percentile is x-sub-r, the r-th smallest sample.
Sort the N response times. Multiply N by p over 100 and round up to get the rank r. Read the sample at rank r. This is the nearest-rank method; every value it gives is a real sample.
The 1,000 requests above. For p50, r = 500, so 5 ms. For p99, r = 990, so 50 ms. For p99.9, r = 999, and sample 999 is still 50 ms: the 50 ms group ends there. Only the maximum, rank 1,000, is 5,000 ms.
The line is all 1,000 samples sorted, on a log scale; the last 100 ranks are stretched so you can see the tail. The marker is the rank you read. The dashed line is the mean. Pick a sample and move the percentile.
The first sample is the worked example above. The long-tailed sample is drawn from a lognormal plus rare pauses, made up for this page. Values use the nearest-rank method.
Tools disagree in the tail. NumPy's default interpolates between neighbours, so it reports p99.9 of the same sample as 54.95 ms. Name your method.
Failure. Symptom: a load test reports p99 = 20 ms, and production shows 400 ms. Measure: did the test tool wait for each answer before sending the next request? Cause: while one request was stuck, the tool sent nothing, so the slow period produced few samples. This is called coordinated omission. Fix: send at a fixed rate and time each request from when it should have been sent.
Chapter 3
Multiply the chances that every call is fast, and watch the page's tail grow
One page often calls many backend services in parallel: the cart, the prices, the stock, the recommendations. The page is ready only when the slowest call returns. So each extra call is one more chance to wait.
Call the chance that one call is slow p, for example 1% if "slow" means slower than that service's p99. Call the number of parallel calls n. The chance that the page waits for at least one slow call is Pslow.
P-slow equals one minus, one minus p, to the n.
The chance one call is fast is 1 minus p. The chance all n are fast is that, n times over. One minus that is P-slow. For small n, P-slow is close to n times p.
With p = 1%: n = 5 gives 4.9%, n = 20 gives 18.2%, and n = 100 gives 63.4%. The services each meet their own p99, yet at 100 calls most pages are slow.
Jeffrey Dean and Luiz André Barroso made this point in "The Tail at Scale" (Communications of the ACM, 2013). With 1 slow server in 100, requests that touch 100 servers are slow 63% of the time. Their fix is the hedged request. If a call has not answered by its usual p95 time, send a copy to another replica and take the first answer. A page is then slow only if both copies are slow, so p becomes about p squared.
Each cell is one page; red cells waited for a slow call. The curve is the formula, and the dot is your setting. Drag the fan-out, then turn on hedging.
Illustrative: each call is slow with p = 1%, calls are independent, and a hedge is slow only if the backup is slow too. Real slow calls are often correlated, which makes hedging help less.
Hedging costs extra load: up to 5% more requests if you hedge at the p95 time. Dean and Barroso report one test where a 10 ms hedge cut the 99.9th percentile from 1,800 ms to 74 ms for 2% more requests.
Failure. Symptom: every service meets its p99 target, but the page misses its own. Measure: the number of calls per page, and the share of pages with at least one slow call. Cause: tail amplification across fan-out. Fix: fewer calls on the critical path, hedged requests, or a per-page time budget that drops optional parts.
Chapter 4
Turn an uptime target into minutes of failure you may spend each month
A target needs three parts. A service level indicator (SLI) is what you measure: say, the share of requests answered within 200 ms. A service level objective (SLO) is its target: say, 99.9% over 30 days. A service level agreement (SLA) is a contract that says what the customer gets back if you miss. Keep the SLO stricter than the SLA, so you notice before the contract bites.
An availability target sounds like "almost always". It is a count of minutes that may go wrong. Call the target availability A and the length of the window T. The downtime you may spend is the error budget, B.
B equals one minus A, times T.
Subtract the target A from 1 to get the share of time that may fail. Multiply by the window T. That is the budget B.
A = 0.999 and T = 43,200 minutes: B = 0.001 × 43,200 = 43.2 minutes a month. Over a 365-day year it is 525.6 minutes, 8.76 hours.
| Target | Per 30-day month | Per 365-day year |
|---|---|---|
| 99% (two nines) | 432 min (7.2 h) | 87.6 h (3.65 days) |
| 99.9% (three nines) | 43.2 min | 8.76 h |
| 99.95% | 21.6 min | 4.38 h |
| 99.99% (four nines) | 4.32 min | 52.6 min |
| 99.999% (five nines) | 25.9 s | 5.26 min |
Yellow marks are incidents on the month's timeline; the bar below is the budget. Choose a target, then add an incident or a risky deploy.
Illustrative month: incidents of 8 and 10 minutes on days 4 and 12, and today is day 20. Budgets use a 30-day month.
The budget makes risk a shared decision. At 99.95%, the month allows 21.6 minutes. After 18 minutes of incidents, 3.6 remain, so a deploy that might cost 5 minutes waits. Google's SRE book describes this way of setting targets in detail.
Failure. Symptom: the team meets its internal target and still owes customers credits. Measure: compare the SLO with the SLA and the window each uses. Cause: the SLO equals the SLA, or uses a different month length. Fix: set the SLO stricter than the SLA and state one window for both.
Chapter 5
Divide a fleet by each part's lifetime, and plan for a death every day
Two words first. A fault is one part going wrong: a dead disk, a crashed process. A failure is the whole system no longer giving the service users need. A fault-tolerant system stops faults from turning into failures. A part whose fault alone causes a failure is a single point of failure.
One disk rarely dies. A fleet of disks dies all the time. Call the number of disks N, and the mean time one disk runs before it fails MTTF, in hours. The expected failures per hour across the fleet are F.
F equals N divided by M-T-T-F.
Each disk fails about once per MTTF hours. N disks fail N times as often. Divide N by MTTF to get F, the failures per hour.
A datasheet MTTF of 1,000,000 hours and N = 10,000: F = 0.01 an hour, 0.24 a day, about 88 a year. At a 3% yearly failure rate, MTTF is about 292,000 hours, and the fleet loses 0.82 disks a day, 300 a year.
Each cell is a group of purple disks; it flashes red when one of its disks dies, then turns purple again once the disk is replaced. Choose the fleet size and the failure rate, then run a year.
Failures are drawn at random at the chosen rate (a Poisson process). The 3% rate sits inside the 2 to 4% field range that Schroeder and Gibson measured.
Datasheets are optimistic. Bianca Schroeder and Garth Gibson studied about 100,000 drives at large sites (FAST 2007). The datasheets implied at most 0.88% a year. In the field, yearly replacement rates of 2 to 4% were common, and some sites reached 13%. So plan with field rates. Keep each piece of data on several disks, and replace dead ones fast.
Failure. Symptom: data is lost after "only" two disk deaths. Measure: the time from a disk's death to its data being copied again. Cause: the second copy died before anyone replaced the first. Fix: three copies on different machines and racks, and automatic re-copying within hours.
Chapter 6
Multiply the chances that all copies are down, then see a shared bug break the sum
Run two copies of a service behind a load balancer, and it is down only when both are down. Call one copy's availability A, and the number of copies r. The availability of the group is Ar.
A-r equals one minus, one minus A, to the r.
Take the share of time one copy is down, 1 minus A. Raise it to the power r for all copies down together. Subtract from 1 to get A-r.
A = 0.999. One copy is down 43.2 minutes a month. Two copies: A-r = 1 − 0.001² = 0.999999, about 2.6 seconds a month. Three copies: 0.999999999.
The word "independently" carries the whole result. Hardware faults are mostly independent. Software faults are not: one bad release, one input that crashes the parser, or one expired certificate takes down every copy at once. Call the share of time such a shared fault is active q. Then all copies fall together.
Warm boxes are copies; the bar is downtime a month on a log scale against the 43.2-minute budget of 99.9%. Add copies, then turn on the shared bug.
Illustrative: copies fail independently except for the shared bug. Downtime uses a 30-day month.
People cause shared faults too. David Oppenheimer, Archana Ganapathi and David Patterson studied failures at three large Internet services (USITS 2003). Operator error was the largest single cause in two of the three, and configuration errors were its largest kind. The fixes are design, not blame: roll out changes to a few machines first, make rollback one step, and test with injected faults. Failure Modes, Resiliency Patterns and Testing and Deployment show how.
Failure. Symptom: three replicas, and all three crash within a minute. Measure: did they run the same release and receive the same input? Cause: a correlated software fault. Fix: staged rollouts with automatic halt, and limits on bad input.
Chapter 7
Use Little's law to count requests in flight, and a queue model to choose the workers
Scalability is a question, not a label: if the load grows this way, what happens? Describe the load with load parameters: requests a second, read-to-write ratio, fan-out, data size. Then ask what keeps performance when they grow.
A useful first law links three numbers. Call the arrival rate λ (lambda), in requests a second, and the mean time each request spends in the system W. The mean number of requests in flight is L.
L equals lambda times W.
Multiply how many requests arrive each second, lambda, by how long each stays, W. That is how many are inside at once, L. This is Little's law, and it needs no assumptions about the arrival pattern.
With made-up numbers: lambda = 2,000 a second and W = 50 ms, so L = 100 requests in flight. If a slow database makes W 500 ms, L becomes 1,000. A thread pool of 200 is full, and new requests are refused.
Now size the workers. Call one request's service time s, and the busiest share of time you allow each worker ρmax (rho-max). The workers needed are c.
c equals the ceiling of lambda times s, over rho-max.
Multiply the rate lambda by the service time s to get the workers that would be busy all the time. Divide by rho-max for headroom, and round up. That is c.
lambda = 3,000 a second and s = 0.02 s: 60 workers' worth of work. Divided by 0.7 that is 85.7, so c = 86.
Warm cells are busy workers, pink cells are idle. The curve is the p99 queue wait for each worker count; the dashed line is the 70% rule. Drag both sliders.
Model: random arrivals, random service times with a 20 ms mean, one shared queue (the M/M/c queue, solved with the Erlang C formula). Illustrative numbers.
At 64 workers the pool is 94% busy, yet the p99 wait is 19.6 ms. One server at 94% busy would make the mean response 16 times its service time. A shared pool absorbs bursts far better.
Past one machine, you buy a bigger one (scaling up) or add machines that share nothing and split the work (scaling out). Load Balancing and Sharding cover scaling out.
Failure. Symptom: one slow dependency, and the whole service stops answering. Measure: requests in flight against the pool size. Cause: by Little's law, W went up 10 times, so L did too, and the pool filled. Fix: timeouts on every call, and a separate pool per dependency.
Chapter 8
Shorten the time to repair, and watch availability climb without one extra machine
Most of a system's cost comes after launch: running it, fixing it and changing it. Maintainability has three parts. Operability means the people on call can see what the system does and act fast. Simplicity means newcomers can understand it, because good abstractions hide the accidental complexity. Evolvability means it can change as needs change.
Operability shows up in a number. Call the mean time between faults MTTF, and the mean time to notice and repair one MTTR. The share of time the service is up is A.
A equals M-T-T-F divided by M-T-T-F plus M-T-T-R.
Each cycle is MTTF hours up, then MTTR hours down. Divide the up part by the whole cycle to get A.
MTTF = 720 h and MTTR = 4 h: A = 720 / 724 = 99.45%, about 239 minutes down a month. Cut MTTR to 15 minutes: A = 99.965%, 15 minutes a month. The same faults, 16 times less downtime.
Each row is a month. Each red bar is one outage, as wide as its repair. The faults stay the same; drag the repair time.
Illustrative: faults arrive at random with an MTTF of 720 hours, the same seed at every repair time. Bars narrower than a pixel are drawn at 2 px so you can see them.
What cuts MTTR? Seeing the problem: dashboards and alerts on what users feel, latency, traffic, errors and saturation (Observability). Undoing a change in one step. Runbooks that say what to do. Simplicity cuts it too: a system people understand gets fixed faster.
Failure. Symptom: a bad deploy takes four hours to fix, though rolling back takes two minutes. Measure: split MTTR into time to notice, time to diagnose and time to fix. Cause: no alert on user-facing errors, and nobody could tell which change broke it. Fix: alert on symptoms, link each alert to a runbook, and record every deploy where the dashboard shows it.
Chapter 9
Set six dials for one service and watch each target turn green or red
Here is a requirement sheet for a page served at 3,000 requests a second. 99% of pages finish within 100 ms. The service is up 99.9% of a 30-day month, so 43.2 minutes of budget. The p99 queue wait at peak stays under 10 ms. Each row below uses one equation from this lesson.
The dials map to chapters: the calls per page and hedging to Chapter 3, copies and the shared bug to Chapter 6, workers to Chapter 7, and repair time to Chapter 8. Start from the defaults: three rows are red. Fix them for the fewest machines.
Each bar is one requirement. Green meets the target, red misses it. The last row counts machines. Change one dial at a time.
Copies of each tier
Mean time to repair
Illustrative model from Chapters 3 to 8. Calls are slow 1% of the time; a hedge makes that 0.01% for 5% more calls. Three tiers in series, each copy with an MTTF of 720 h. A shared bad release hits a tier once in 90 days and lasts one repair time. Each machine runs 16 workers.
Two lessons fall out. Copies fix independent faults but not shared ones; with shared bad releases on, only a shorter repair brings downtime under budget. And the latency row ignores machines entirely: no hardware fixes a page that makes 60 calls.
Failure. Symptom: the team adds machines and the p99 does not move. Measure: which row is red, and which dial moves it. Cause: the tail comes from fan-out, not from load. Fix: change the dial that moves the red row: fewer calls or hedging.
Chapter 10
Keep the numbers, the checklist and the code for your next requirement sheet
Write every quality as a number with a window. Describe load by its rate and its spread, including the fan-out. Describe response time by percentiles, and expect fan-out to amplify the tail. Turn uptime into minutes of budget. Count hardware faults by fleet size, and remember that shared software and human faults defeat copies. Size workers from the load, and cut repair time as hard as you cut faults.
| Term | What it is | This lesson's number |
|---|---|---|
| Fan-out work | C = R · k | pull 60 M lookups/s, push 1.2 M inserts/s |
| Percentile rank | r = ⌈p/100 · N⌉ | p99 of 1,000: rank 990, 50 ms; p99.9: rank 999, 50 ms |
| Tail amplification | Pslow = 1 − (1 − p)n | p 1%: 18.2% at n 20, 63.4% at n 100 |
| Error budget | B = (1 − A) · T | 99.9%: 43.2 min per 30-day month |
| Fleet failures | F = N / MTTF | 10,000 disks: 0.24 a day (datasheet), 0.82 (3% a year) |
| Redundancy | Ar = 1 − (1 − A)r | 0.999, two copies: 0.999999; shared fault 0.05%: 21.6 min/month |
| Little's law | L = λ · W | 2,000/s × 50 ms = 100 in flight |
| Workers | c = ⌈λ · s / ρmax⌉ | 3,000/s × 20 ms / 0.7 = 86 |
| Repair and uptime | A = MTTF / (MTTF + MTTR) | 720 h, 4 h: 99.45%; 15 min: 99.965% |
pythonimport math # the lesson's requirements as functions you can call with your own numbers def fanout(R, k): return R * k # C = R·k def pct(xs, p): return sorted(xs)[math.ceil(p / 100 * len(xs)) - 1] # nearest rank def slow_share(p, n): return 1 - (1 - p) ** n def budget_min(A, T=43200): return (1 - A) * T # 30-day month def fails_per_day(N, mttf_h): return N * 24 / mttf_h def copies(A, r, q=0): return (1 - q) * (1 - (1 - A) ** r) def in_flight(lam, W): return lam * W # Little's law def workers(lam, s, rho=0.7): return math.ceil(lam * s / rho) def uptime(mttf, mttr): return mttf / (mttf + mttr) xs = [5] * 950 + [50] * 49 + [5000] print(sum(xs) / 1000, pct(xs, 99), pct(xs, 99.9)) # 12.2 50 50 print(slow_share(0.01, 20)) # 0.182 print(budget_min(0.999)) # 43.2 minutes print(fails_per_day(10_000, 1_000_000)) # 0.24 print(copies(0.999, 2, q=0.0005)) # 0.9995 print(in_flight(2000, 0.05), workers(3000, 0.02)) # 100.0 86 print(uptime(720, 4)) # 0.99448
Now press Present or Teach and explain four things from memory: why the mean hides the tail, why fan-out amplifies it, why copies do not stop a shared bug, and why repair time matters. Then go back to the hero and find the fan-out where half the pages are slow.