Module 1 / What is system design? / Latency numbers every designer should know

Lesson9 minModule 1 · lesson 6 of 9

Latency numbers every designer should know

Memory, disk and network differ by orders of magnitude.

Every design choice moves work between places that are fast and places that are slow, and the gap between them is enormous. Reading something from memory takes about a hundred nanoseconds. Reading it from a disk or across the network takes thousands to millions of times longer. If you know these rough sizes, you can sense at a glance why one design is fast and another is not.

The figures below are orders of magnitude, not exact values. Real hardware varies by year and vendor, but the ratios stay similar enough to reason with. A nanosecond (ns) is a billionth of a second, a microsecond (us) a millionth, a millisecond (ms) a thousandth.

Operation                                  Approx. time
Read from CPU cache / main memory          1 - 100 ns
Read 1 MB sequentially from memory         ~ 0.1 - 0.3 ms
Random read from an SSD                    ~ 0.1 ms   (100 us)
Round trip inside one data center          ~ 0.5 ms
Random read from a spinning disk (seek)    ~ 5 - 10 ms
Round trip between continents              ~ 100 - 200 ms
Rough orders of magnitude. Treat them as ratios, not facts about your machine.

Now put them to work. Say a page needs 5 database lookups. If the database is in the same data center and each takes about 1 ms including the trip, that is roughly 5 ms. If the database sits on another continent, each trip costs 150 ms and the page needs 750 ms for data alone, before any rendering. The network distance, not the query, dominates. That is why companies place servers near users and why chatty designs, which make many small calls, are slow.

UserApp serverCache in memoryDatabase on diskrequestcheck first(~0.5 ms)on a miss(~5 ms)
A cache turns the slow path into a fast one.

The same arithmetic explains caching. A memory-based cache answers in well under a millisecond including the network hop, while a disk-heavy database might take several. If 90 percent of reads hit the cache, the average falls from about 5 ms to roughly 0.9 x 0.5 + 0.1 x 5.5 = 1.0 ms: five times faster, and the database sees one tenth of the traffic.

Question 1

Which is the slowest?

Question 2

A page makes 20 sequential calls to a service 100 ms away. What is the main fix?

Your turn

Estimate the time for a request that does one cache hit (0.5 ms) and one database read (5 ms) in the same data center, then say what happens if the database moves to another continent.

Stuck? Add the pieces; the second case adds a long trip.

What to remember

  1. Memory is nanoseconds, SSD is about 0.1 ms, a data-center trip about 0.5 ms, disk seeks several ms.

  2. Cross-continent round trips take 100 to 200 ms.

  3. Network distance and round trips usually dominate.

  4. Caches win by replacing slow reads with fast ones.

  5. Latencies grow under load, so leave headroom.