Latency, throughput and availability in a design answer
Latency is how long one request takes, throughput is how many requests get done in a second, and availability is the share of time the service answers at all. A design answer names a target for each, says what limits it and gives one lever to improve it. The nines table, the two combining rules and four checked problems below turn the three words into numbers.
Your first hour with George Li (60 minutes by video, $250) ends with a written plan within one working day.
Book your first hour ($250)Three words, three questions
Designers use these three terms for the first questions anyone should ask of a service. They are related, but each can be good while another is poor, and a design answer is stronger when it says which one it is optimizing and by how much.
| Measure | The question it answers | Usual unit | How it shows up when it is bad |
|---|---|---|---|
| Latency | How long does one request take? | Milliseconds | Pages feel slow and users wait |
| Throughput | How many requests does the system finish per second? | Requests per second, or bytes per second | Requests queue up or are turned away at busy times |
| Availability | What share of the time does the service answer? | Percent of a window, often written in nines | Errors or timeouts for everyone at once |
Google’s site reliability book lists latency, traffic, errors and saturation as the four golden signals of a user-facing system, and says that if you can measure only four things, measure those (Monitoring Distributed Systems). The first of them is latency, and throughput is the traffic a system carries; availability shows up as the errors signal. So the three words in this page map onto a vocabulary people use at work.
Latency: where the time goes
A request spends time in four places, and naming them is most of the answer. Distance: a signal cannot travel faster than light, so a user far from a server waits for the trip however good the code is. Computation: a query that joins many tables takes longer than a lookup by key. Queueing: when requests arrive faster than they are served, the extra ones wait in line. Hops: every machine a request passes through adds a little time and one more place to fail.
Each cause has a lever. A shorter path cuts hops and distance. A cache keeps a copy of data that is read often, so the slow source is read less. A protocol that reuses a connection avoids paying the setup again for each request; the network protocols guide works out the saving. A cache is not free, though, because a request that misses pays the cache lookup and then the slow read as well. Problem 4 below puts numbers on that.
Throughput: work finished per second
Picture water in a pipe. Bandwidth is the width of the pipe, the most it could carry. Throughput is the flow you actually get, which is lower whenever something upstream or downstream holds it back. Latency is how long a drop takes to travel the length of the pipe. A fat pipe can still be slow to deliver the first drop.
Three things hold throughput down: congestion, when more arrives than the hardware can handle; protocol overhead, when handshakes and headers use up capacity that the real data could have used; and high latency itself, because a client that waits for each reply before sending the next can finish only one request per round trip. That last point gives a formula you can use aloud: with one request in flight per connection, completions per second is the number of connections divided by the latency in seconds. Problem 3 uses it. To raise throughput you add capacity at the bottleneck, add parallelism, lower latency or cut overhead.
Availability: counting the nines
Availability is uptime divided by uptime plus downtime, over a stated window. People often write it in nines. The table turns four common targets into minutes in a 30 day month, computed here as 43,200 minutes times the unavailable share; the 99.9 and 99.99 rows match the figures in Google’s availability table.
| Availability | Unavailable share | Downtime allowed in 30 days |
|---|---|---|
| 99 percent | 1 percent | 7.2 hours |
| 99.9 percent | 0.1 percent | 43.2 minutes |
| 99.99 percent | 0.01 percent | 4.32 minutes |
| 99.999 percent | 0.001 percent | 25.8 seconds |
Two rules combine availabilities. When a request needs several services in a chain, multiply their availabilities, so the chain is weaker than its weakest link: two required services at 99 percent each give 98.01 percent. When replicas can each answer alone, multiply their unavailabilities instead: two replicas at 90 percent each, failing independently, give 99 percent. Problems 1 and 2 use both rules. The independence assumption is the weak point, since replicas that share a power supply, a network switch or a bad deployment fail together.
What lowers availability, and the matching defenses
| Cause of downtime | Defense |
|---|---|
| A server, disk or power feed fails | Redundant copies, with a standby ready to take over (warm or cold) |
| A bug or a bad release | Automated tests, staged rollouts and an automatic rollback to the last good version |
| A dependency such as DNS or a login service goes down | Fewer required dependencies, timeouts, and a fallback when one fails |
| Overload: requests exceed capacity | Headroom, load shedding and spreading load with a load balancer |
| A whole region is lost | Copies in more than one location, at a higher cost and with harder data consistency |
| Data is lost | Backups and replication, tested by restoring them |
The three pull against each other
A service with 99.999 percent availability is not good if every answer takes a minute. A fast service that is down on the busiest day is not good either. Timing matters as well as totals: ten minutes of downtime at midnight on a quiet day is a different event from ten minutes during the heaviest hour. Extra copies raise availability but add cost and make it harder to keep the copies in agreement, and a longer chain of services adds latency and multiplies availability down. A good answer states its priority for the product in question, such as latency first for a search box and availability first for a payment, and names the cost of the choice.
How to use the three words in an answer
- Say the targets with units and a window: a latency figure at a stated percentile, a requests-per-second figure at peak and an availability figure over a month.
- Name the first limit you expect, such as one database or one region.
- Give one lever for each target and one cost for each lever.
- Ask what matters most to the user of this system before you decide.
| Target | Template |
|---|---|
| Latency | I would aim for [percentile] under [number] ms, because [what the user does while waiting]. |
| Throughput | At [number] requests per second at the peak, one server handles [number], so I need [number] plus one spare. |
| Availability | I would target [number] percent over [window], which allows [minutes] of downtime, and I would get there with [lever]. |
A note on who needs this. Our system design for interns guide found no system design round named in our program records, and a first internship interview is mostly coding, your projects and behavioral questions. This page is for students who are curious, who have a design question in a course or a project, or who are looking ahead to a new-graduate loop. If a recruiter says there will be a design round, ask what scale it expects and prepare for that.
Practice problems
These problems are our own, written for this site. Every answer is recomputed when the site is built, and a wrong answer would stop the build. Try each before you open the steps. Read how the problems are checked.
Problem 1. A page works only when two independent services are both up. Each service is up 99 percent of the time. Over a 30 day window of 43,200 minutes, how many minutes is the page expected to be unusable? Give a decimal number.
Show the answer and the working
Answer: 859.68
- Both services are up with probability 0.99 x 0.99 = 0.9801.
- The page is therefore unusable with probability 1 - 0.9801 = 0.0199.
- 0.0199 x 43,200 = 859.68 minutes, close to 14 hours, though each service alone would miss only 432 minutes.
- The lesson: availability multiplies down a chain of required services, so the chain is weaker than its weakest link.
Problem 2. A service runs on two replicas. Each replica is up 90 percent of the time, independently of the other, and the service is up when at least one replica is up. What is the service availability, in percent? Give an integer.
Show the answer and the working
Answer: 99
- The service is down only when both replicas are down, which has probability 0.10 x 0.10 = 0.01.
- So it is up with probability 1 - 0.01 = 0.99, which is 99 percent.
- Redundancy raised 90 percent to 99 percent, but only because the failures are independent. Two replicas that share a power supply would not follow this arithmetic.
Problem 3. A client sends one request at a time over a connection and waits for the reply before it sends the next one. Each round trip takes 40 milliseconds. The client opens 8 such connections in parallel. At most how many requests per second do the 8 connections complete together? Give an integer.
Show the answer and the working
Answer: 200
- One connection completes 1,000 / 40 = 25 requests in a second.
- Eight independent connections complete 8 x 25 = 200 requests per second.
- Latency (40 ms) did not change, yet throughput rose eightfold because the work was done in parallel.
Problem 4. Every request first looks in a cache, which takes 2 milliseconds. A request that is not found there then reads the database, which takes another 50 milliseconds. 80 percent of requests are found in the cache. What is the mean latency of a request, in milliseconds? Give an integer.
Show the answer and the working
Answer: 12
- Every request pays the 2 ms lookup.
- The 20 percent of requests that miss also pay 50 ms, which adds 0.20 x 50 = 10 ms on average.
- Mean latency is 2 + 10 = 12 ms. Without the cache every request would take 50 ms, so the cache cut the mean by about three quarters, and a miss now costs 52 ms, slower than having no cache.
Questions
What is the difference between latency and throughput?
Latency is the time one request takes from start to finish. Throughput is how many requests finish in a given time. A system can raise throughput by doing work in parallel without making any single request faster.
What does 99.9 percent availability allow?
Google’s availability table lists 43.2 minutes of downtime in a 30 day month at 99.9 percent, and 4.32 minutes at 99.99 percent.
Do internship interviews ask about this?
Our program records name no system design round. The vocabulary is still useful in project talks, where saying how fast and how reliable your project was is a strength.
How a session helps
In a session George can work a small design question with you aloud, ask where each of your numbers came from and mark where a number or a trade-off was left unsaid. You say each design in your own words; nothing here is written for you to recite. See the packages page for the sessions and book a session when you have a date to work toward.
Want help with your own applications? See internship interview coaching, a career coach for college internships, or resume review for internships.