Courses System design · Part 1 · Lesson 3
Latency, Throughput and Availability
When we say a system “works well”, we usually mean three things: it answers fast, it handles a lot of work, and it is always there. These three measures have names, and each one can be measured with a number.
Latency and throughput
- Latency: how long one request takes to get an answer. Measured in milliseconds.
- Throughput: how many requests the system finishes per second.
They are different. Think of a highway: the speed limit sets the latency (how long each car takes to arrive). The number of lanes sets the throughput (how many cars pass per hour). Adding a lane makes no car faster, but lets more cars through.
Systems work the same way. Adding servers (a load balancer) raises throughput. To lower latency, you must make each request do less work, for example with a cache or an index.
But when a system reaches its capacity, requests wait in a queue, and latency goes up too. You see this in the message queue lab: when work arrives faster than the workers can handle, each message waits longer and longer.
Why the average misleads
Say we have 100 requests. 98 got an answer in 50 milliseconds, and 2 in 5 seconds:
- Average: (98 × 50 + 2 × 5000) ÷ 100 = 149 milliseconds.
This number describes no request. Nobody waited 149 milliseconds. Most users had a very good experience, and two had a very bad one.
So we use percentiles. Sort the times from fastest to slowest:
- p50 (the median): the time that half of the requests beat. Here, 50 milliseconds.
- p99: the time that 99% of the requests beat. Here, 5 seconds.
p99 matters because busy users hit it more than others. If one page sends 100 requests to different servers, almost surely one of them is in the slowest 1%. So the p99 of one service becomes the normal speed of that page.
Availability and “nines”
Availability is the percentage of time a system works. It is usually said as a number of nines. A 30-day month has 43,200 minutes:
| Availability | Allowed downtime per month |
|---|---|
| 99% (two nines) | 432 minutes, about 7 hours |
| 99.9% (three nines) | about 43 minutes |
| 99.99% (four nines) | about 4 minutes |
| 99.999% (five nines) | about 26 seconds |
Each extra nine cuts the allowed downtime by ten, and raises the cost by much more than ten. With four minutes of downtime per month, there is not even time for a person to wake up and look at the problem. Everything must be automatic.
Chains lower it, extra copies raise it
Two simple rules behind most availability decisions:
1. Parts in a row lower availability. If a request must pass three services, and each one is 99.9% available, the whole system is:
0.999 × 0.999 × 0.999 ≈ 0.997, so 99.7%: three times the downtime of each one.
Every new service you put in the main path pushes this number down. A circuit breaker helps stop one broken service from taking down the whole chain.
2. Parallel copies raise availability. If we have two copies of a service and each is 99% available, the system is down only when both are down at the same time:
1 − (0.01 × 0.01) = 0.9999, so 99.99%.
Two ordinary servers are more available than one very good server. This is the idea behind replication and health checks in a load balancer. (This calculation assumes the two copies fail independently. If both share one power supply, that is not true.)
Three words: SLI, SLO, SLA
- SLI: what you measure. For example, “the percentage of requests answered in under 300 milliseconds”.
- SLO: the target you set for yourself. For example, “this number is at least 99.9% each month”.
- SLA: the promise you make to a customer, usually with a penalty. It is always looser than the SLO, so you have time to fix things before you break the promise.
Summary
- Latency and throughput are different things. More servers raise throughput; less work lowers latency.
- Look at p50 and p99, not the average.
- Each nine means ten times less downtime. Chains lower availability, and extra copies raise it.
This lesson ends Part 1. From here on, you see each idea on a machine.