Module 2 · Thinking in Numbers First · Lesson 6 of 35
Latency vs throughput: how fast, and for how many
12 minFree System design course · Beginner to intermediateLesson 2.2By Saket Bhatnagar
Researched and drafted with AI, reviewed and edited by Saket Bhatnagar.
In short
- Latency vs throughput: latency is how long one request takes, and throughput is how many requests finish each second.
- An average hides the few very slow requests, the ones people remember.
- Memory, disk and network times differ a thousand times or more, so learn them as rough amounts.
Video lesson · coming soon
Latency vs throughput: how fast, and for how many
Lala, your AI mentor, will walk you through this lesson in a short animated video. Until then, everything is here to read and try.
- 01 Fine on the chart, broken for users
- 02 The expressway picture
- 03 Build the budget, then meet the tail
- 04 The latency chain with a slow box
- 05 One page, 100 servers
- 06 How many at noon?
“Which two words did we mix up on the list?” Meera Kulkarni asks. Arjun Nair has looked them up: “fast” is latency, and the crowd has a word of its own. Then he proudly shows his new chart: the average booking tap takes about 210 milliseconds.
Meera opens her phone. Two club members say the app “spins for three seconds, then says try again”. The chart says fine; the members say broken.
They pull up the saved timings of the last 100 taps on the ₹1,200-a-month server. 98 are quick. 2 took 3 seconds, and those are the messages. Arjun adds a goal to the wall list: “99 out of 100 taps should finish in under 2 seconds.” Today, only 98 do.
Meera frowns. The list has a speed line for one person, and nothing for many people at once. “How many people will tap at noon?” Arjun does not know.
Latency vs throughput: what is the difference?
Latency is how long one request takes, and throughput is how many requests finish each second.
People often count throughput in QPS.
- Latency is one request’s wait, adding up hop by hop, the legs of the round trip from lesson 2.
- Throughput is how many finish each second, across everyone.
- The slowest 1 in 100 is what people remember, so watch it.
Here is a different, later SeatJaldi tap as a chain of hops, timed in ms. Hover each box; the times are made up for teaching and differ from lesson 2’s.
Latency budget, hop by hop
Drag to exploreFour hops add up to 285 ms on a first visit (assumed times), then the reply reaches the phone. A few taps take far longer.
Diagram connections:
- Phone taps Book to DNS look-up (First)
- DNS look-up to Connect and TLS (Then)
- Connect and TLS to Server work (Then)
- Server work to Database read (Then)
- Database read to Reply reaches phone (Reply)
- Reply reaches phone to A few slow taps (Rarely 3 s)
- Phone taps Book: The clock starts here.
- DNS look-up: About 30 ms to find the address.
- Connect and TLS: About 100 ms to open a secure line.
- Server work: About 150 ms to check the seat.
- Database read: About 5 ms to fetch the seat rows.
- Reply reaches phone: Server → Phone: the clock stops, 285 ms on a first visit.
- A few slow taps: 2 taps in 100 took 3 seconds; the cause is a story for late…
You have seen this when a news app opens in a blink on home Wi-Fi but spins on the train. The same hops ran, but each took longer.
A ticket app is quick nearly every time, yet you call it slow after one tap hangs. That rare tap is the one you remember.
On match night, a food app feels slow at every step. Orders arrived faster than it could finish them, like cars at the toll on a festival Friday.
What is p99 latency, and why not use the average?
p99 latency is the time that 99 out of 100 requests finish within, so it shows how bad the slowest few are. Line up 100 request times from fastest to slowest; p99 is the 99th one.
Engineers usually watch three percentiles: p50, the middle request; p95, the time 95 in 100 finish within; and p99. The slow few at the far end have a name.
What are the latency numbers every programmer should know?
Memory is a thousand or more times faster than a disk or a network trip, and these numbers are orders of magnitude, not exact facts. Memory is the fast working space a running program uses; a disk keeps data when the power is off. An order of magnitude is a rough size, to the nearest power of ten.
A nanosecond (ns) is a billionth of a second, and a microsecond (µs) is a millionth. An SSD is the storage chip inside most laptops. Big apps keep their servers together in one building.
| What happens | About how long | Compared with memory |
|---|---|---|
| Read from memory | 100 ns | 1 time |
| Read a small block of data from an SSD | Tens to hundreds of µs | Hundreds to a thousand times |
| Round trip in one data centre | 0.5 ms | About 5,000 times |
| Find a spot on a spinning hard disk | A few ms to 10 ms | Tens of thousands to a hundred thousand times |
| Round trip between continents | 150 ms | About 1.5 million times |
Two well-known tables disagree on the SSD row by about ten times, 150 µs against 16 µs. Picture each row as a longer road. Memory is a walk across the room; a trip between continents is the Bengaluru to Mysuru drive, many times over.
How do latency and throughput connect?
Little’s law ties them together: on average, the number of requests in progress equals how many arrive each second times how long each one takes.
On the expressway, cars on the road equal cars entering each hour times the hours each one drives. At 1,000 cars an hour and 3 hours each, about 3,000 are on the road. If an accident makes every trip 6 hours, 6,000 are, and the jam feeds itself. Requests pile up the same way.
Try it yourself
Find what is in flight
A site gets 1,000 requests a second, each taking 0.2 seconds (both assumed). How many are in progress at once?
Slow it down
Now each request takes 0.4 seconds. How many are in progress?
Count the servers
Assume one server holds 50 requests at once. How many servers in each case?
Check your answers
You got it if you have 200, then 400, then 4 and 8 servers. When each request takes twice as long, twice as many are held at once.
Measure p99 from the phone’s side, over every request. To find it cheaply, count requests into time buckets, such as under 100 ms, 100 to 300 ms and 300 ms to 1 second. Then find the bucket where the 99th request in 100 lands. It is only as exact as the bucket edges, so let buckets grow about three times each, as the SRE book suggests.
The 0.8-second guide for time to first byte from lesson 2 is the yardstick here. SeatJaldi’s made-up 285 ms fits well inside.
Lesson 2’s curl command also prints the DNS time if you add %{time_namelookup}. Run it 20 times and sort the totals to see your own tail.
Arjun’s chart now shows p99 beside the average, and the angry messages make sense. They were the tail, the two cars behind the accident. Why those two were slow is still open, and a tail needs a cause as well as a number.
“So fast is latency, and the crowd is throughput,” Meera says. “One is a person’s wait. The other is the crowd’s count. Staying up through it is still the availability line we wrote.”
But the wall still has no number for the crowd. Meera can describe speed now. How many requests per second will the noon sale bring?
Check yourself
Check yourself
The average is about 210 ms, yet 2 in 100 users wait 3 seconds. Which number should Arjun watch?
Pick an answer to see why it is right or wrong.
Check yourself
A page waits on 100 other servers, each slow 1 time in 100. About how often is the page slow?
Pick an answer to see why it is right or wrong.
Check yourself
Meera doubles the servers. On a quiet afternoon, how long does one member’s tap take?
Pick an answer to see why it is right or wrong.
Remember these three
- Latency adds up along the path, and the slowest 1 in 100 is what people remember.
- Throughput counts requests finished each second; more of it means more finish, not that each finishes sooner.
- Memory, disk and network times differ a thousand times or more; learn them as rough amounts.
Questions people ask
- What is the difference between latency and throughput?
- Latency is how long one request takes, and throughput is how many requests finish each second. More servers can raise throughput without making one request faster.
- What is p99 latency?
- p99 latency is the time that 99 out of 100 requests finish within. It shows how slow the slowest 1 in 100 are, which an average hides.
- Why not use average latency?
- An average blends a few very slow requests into many quick ones. It can look fine while some users wait seconds, so engineers also watch p95 and p99.
- What are the latency numbers every programmer should know?
- Memory takes about 100 nanoseconds and an SSD read tens to hundreds of microseconds. A trip inside a data centre takes about half a millisecond, and one across continents about 150 milliseconds.