SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
  • What is System Design?
  • High-Level Design (HLD)
  • Low-Level Design (LLD)
  • Functional vs Non-Functional Requirements
  • Back-of-the-Envelope Estimation
  • Numbers Every Engineer Should Know
  • SLA, SLO and SLI
  • Basic OS: Process, Thread, Memory
  • 30 Must-Know Concepts
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Foundations/Introduction

Numbers Every Engineer Should Know

How fast memory, disk and network really are, and why those gaps shape every design.

โฑ 12 min readBeginnerMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Some numbers are worth remembering, because they tell you which design ideas are cheap and which are costly.

  • Reading from memory is about 1,000 times faster than reading from an SSD, and about 100,000 times faster than a long network trip.
  • Each step down the ladder (cache, memory, SSD, disk, network) is much slower than the one before.
  • That is why we use caches, avoid extra network calls and prefer sequential reads over random ones.
  • The exact values change with hardware. What matters is the size of the gaps.

02Concept: What is it?

Every request in your system touches some mix of CPU caches, memory, disk and network. Each is fast or slow in a different way, so knowing the rough cost of each helps you guess where a design will be slow, before you build it.

The latency ladder (approximate)

OperationAbout how longIf 1 ns were 1 second
Read from L1 cache1 ns1 second
Read from L2 cache5 ns5 seconds
Read from main memory (RAM)100 nsAbout 2 minutes
Random read from an SSD100 ยตsAbout 28 hours
Round trip inside a data centre500 ยตsAbout 6 days
Disk seek (spinning drive)10 msAbout 4 months
Round trip across a continent or ocean150 msAbout 5 years
๐Ÿ“Approximate on purpose
These are round numbers, widely used to get a feel for the scale. They shift with hardware and over the years: SSDs and networks have become faster. The huge gaps between the rungs stay.
Each step is much slower
Memory read~100 ns
SSD read~100 ยตs
Same data centre round trip~500 ยตs
Disk seek~10 ms
Across the ocean~150 ms
Bars show a log scale: every step to the right is about 10 times longer.
๐Ÿง Two more facts to keep
Reading data in a straight line (sequentially) is far faster than jumping around (randomly), on both disks and memory. And compressing data before sending it often costs less than sending it raw over a long network.

03Real-Life Example

๐ŸตGetting a Cup of Sugar
Imagine you are cooking. Sugar in your hand takes a second. Sugar in a cupboard in the same kitchen takes a couple of minutes. Sugar in the shop on your street takes a day if you count the walk and the queue. Sugar from a factory in another country takes weeks. A good cook keeps the sugar they use all the time within reach. A bad cook walks to the shop for every spoonful. Software is the same: keep the hot data near, and avoid long trips.
Kitchen
Computer
Sugar in your hand
L1 or L2 cache
Sugar in the cupboard
Main memory (RAM)
Sugar in the next room
SSD
A trip to the shop on your street
Another machine in the same data centre
A trip to the old stockroom
Spinning hard disk
Ordering from overseas
A request across the world
Keeping sugar near the stove
Caching hot data
Keep hot data close
โšกCachenanoseconds
โ†’โ†“
๐Ÿง Memory100 ns
โ†’โ†“
๐Ÿ’พSSD100 ยตs
โ†’โ†“
๐ŸŒNetworkms
โ†’โ†“
๐ŸŒFar away100+ ms
Fast and small Slow and big

04Why Do We Need It?

๐ŸงฐExplains caching
Memory is thousands of times faster than disk or a database call, so a cache pays off fast.
๐ŸŒWarns about network trips
One call to another service can cost more than millions of memory reads.
๐Ÿ“Explains regions and CDNs
Distance has a floor set by the speed of light, so we put servers and content near users.
โžก๏ธShapes storage design
Sequential reads and writes are fast, which is why logs and LSM trees work well.
๐ŸงฎMakes estimates possible
You need these numbers for back-of-the-envelope maths.
๐ŸŽคHelps in interviews
You can say why a design is slow, with real orders of magnitude.
Memory is fast, the network is slow, and distance is slower still. Good designs touch the slow things as rarely as possible.

05Where Do We Use It?

๐Ÿง Choosing where to store data
Hot data in memory, warm data on SSD, cold data on cheap disk or object storage.
๐ŸงฐCache design
A cache is worth it when a hit is far cheaper than a miss.
๐Ÿ”—Service design
Each extra network hop adds latency. Avoid long chains of calls.
๐Ÿ—„๏ธDatabase design
Indexes avoid random disk reads. Sequential writes make logs fast.
๐ŸŒMulti-region design
A cross-ocean round trip puts a floor under latency. Replicate data near users.
๐Ÿ“ˆCapacity planning
The speeds set how much one machine can do.

06Types / Parts / How It Works

The numbers, grouped

GroupWhat to rememberWhat it means for design
CPU cachesNanosecondsKeep small, hot data together so it stays in cache
Memory (RAM)About 100 ns, fast but costly and limitedHold the working set here (caches, session data)
SSDAbout 100 ยตs, roughly 1,000 times slower than RAMGood for databases and warm data
Spinning diskA seek costs about 10 ms. Sequential reads are fastUse for cheap, big, mostly sequential data
Same data centre networkAbout half a millisecond per round tripCheap, but calls add up in a long chain
Cross-region networkOften 50 to 150 ms or moreAvoid on the main request path

Useful sizes and rates (very rough)

ItemRough value
A seek-free sequential read from memoryMany GB per second
A sequential read from an SSDHundreds of MB to several GB per second
A network link in a data centreFrom 1 to 100 Gbps (125 MB/s to 12.5 GB/s)
A typical web page request over the internetTens to hundreds of ms, mostly network
A mobile network round tripTens to hundreds of ms, and it varies a lot
โš ๏ธDo not memorise exact digits
Use these to judge "nanoseconds, microseconds, milliseconds or seconds?" If a design does thousands of network calls on one user request, it is slow no matter how exact your table is.
VisualizerThe latency ladder, and what a few misses costSwitch to 'Human time' to feel the gaps (a memory read is minutes, a cross-ocean trip is years). Then lower the share of reads served from memory and watch the average blow up.
Show the times as
Bar length uses a log scale: every step to the right is about 10 times longer. Times are approximate.
โšก Read from L1 cache1 ns
โšก Read from L2 cache5 ns
๐Ÿง  Read from main memory (RAM)100 ns
๐Ÿ’พ Random read from an SSD100 ยตs
๐ŸŒ Round trip inside one data centre500 ยตs
๐Ÿ’ฟ Disk seek (spinning hard drive)10 ms
๐ŸŒ Round trip across a continent or ocean150 ms

Round numbers for a feel of the size, not exact facts. Real values depend on the hardware and change over the years (SSDs and networks keep getting faster). The gaps between the rungs stay huge.

What a few misses do to the average
The rest of the reads go to
Average read
5.1 ยตs
per read
Slower than all-memory
51ร—
memory read = 100 ns
Only 5% of reads miss, yet the average is 51 times slower than all-memory. A few slow reads dominate the average, so aim for a very high hit rate.

07How to Use It / Steps / Implementation

Using the numbers when you design

  1. 1
    Count the slow steps on one request
    List each disk read, database call and network hop. These dominate the time, not the CPU work.
  2. 2
    Add them up
    Ten calls to a service 1 ms away is already 10 ms. Chains of calls add up quickly.
  3. 3
    Move work closer
    Cache hot data in memory. Put content on a CDN. Run servers near users.
  4. 4
    Do work in parallel
    Call independent services at the same time, so the cost is the slowest call, not the sum.
  5. 5
    Batch the small calls
    One call for 100 items beats 100 calls for one item each.
  6. 6
    Prefer sequential access
    Append to a log. Scan in order. Avoid many random reads on disk.
  7. 7
    Compress when sending far
    Fewer bytes over a slow link often saves more time than the compression costs.
  8. 8
    Measure
    Use real timings from your own system. The table tells you where to look, not the final answer.
๐Ÿ’กThe hit-rate rule
If a cache hit costs 100 ns and a miss costs 100 ยตs (1,000 times more), then even 1 miss in 100 makes the average about 10 times slower than all hits. A very high hit rate matters.

08Key Terms to Know

TermMeaning in easy words
LatencyThe time one operation takes from start to finish
Nanosecond (ns)One billionth of a second
Microsecond (ยตs)One millionth of a second (1,000 ns)
Millisecond (ms)One thousandth of a second (1,000 ยตs)
Round trip (RTT)The time for a message to go to a machine and come back
CacheSmall, fast storage that keeps copies of hot data
Cache hit / missThe data was found in the cache, or it was not
Sequential vs random accessReading in order versus jumping around. Sequential is much faster
Disk seekMoving the read head of a spinning drive to a new place
Order of magnitudeA factor of 10. The gaps in this topic span many orders
Working setThe data a program uses often, which should fit in fast memory

09Pros, Cons and Trade-offs

โœ… Pros
  • Explains many design habits with real numbers
  • Quick way to find the slow part of a design
  • Makes estimates and interview answers concrete
  • Reminds you why caches and CDNs exist
  • Simple to remember once you see the gaps
โš ๏ธ Cons
  • Exact values change with hardware and over time
  • Averages hide wide variation (tail latency)
  • Easy to over-trust round numbers
  • Real systems add software overhead
  • Does not replace measuring your own system

Trade-offs

ChoiceWe gainWe lose
Keep data in memoryVery fast readsCost per GB, and data may be lost on a crash unless saved
Use SSD instead of memoryLarger and cheaper storageAbout 1,000 times slower reads
Call another serviceClear separation of workA network hop on every request
Cache at many levelsFewer slow tripsStale data and invalidation work
Replicate across regionsLow latency for far usersCost and consistency work
Compress dataFewer bytes over the networkCPU time to compress and decompress

10Common Problems and Mistakes

Common mistakes

  1. Treating the network as free. A call to another machine is not like a function call. It can fail and it costs time.
  2. Chatty services. A page that needs 50 sequential service calls will feel slow whatever you do.
  3. Ignoring the tail. The average can look fine while 1 request in 100 is very slow.
  4. Random disk access on hot paths. Without an index, a query can turn into thousands of random reads.
  5. Over-trusting the table. Your hardware and software differ. Measure.
  6. Mixing up units. ยตs versus ms is a factor of 1,000.

Things to watch

๐Ÿ“‰Tail latency
The slowest few percent often decide how a product feels. Look at p95 and p99.
๐ŸงŠCold caches
After a restart every read is a miss, and the system may be slow for a while.
๐Ÿ“Distance
Light in fibre cannot beat physics. A far-away region always costs tens of ms.
๐Ÿ”ŒContention
Under load, queues form and real times grow beyond the table.

11Real-World Examples

๐ŸงฐIn-memory caches
Tools like Redis and Memcached keep hot data in memory, to avoid slower database reads.
๐ŸŒCDNs
Content is copied near users to avoid slow long-distance trips.
๐Ÿ—„๏ธDatabases
Indexes and write-ahead logs are designed around the cost of disk access.
๐ŸงฑSearch and feeds
Results are pre-computed and cached, since computing them on demand is too slow.
๐ŸŽฎOnline games
Players are matched to a nearby server, because a long round trip shows as lag.
๐ŸงฎTrading systems
Some firms place machines next to the exchange to save milliseconds.
๐Ÿ“Note
The values here are rounded teaching numbers. Check current figures for your own hardware and cloud when it matters.
Mini case: one page, two designs
50 calls one after another
๐Ÿ”—50 ร— 0.5 ms
โฑ๏ธAbout 25 msjust in network
5 calls in parallel + cache
๐Ÿ”—One round, plus a cache hit
โฑ๏ธAbout 1 ms
Counting only the network time, using a rounded 500 ยตs per call in the data centre.

12Related Topics to Read Next

Back-of-the-Envelope Estimationโ†’

Uses these numbers to size a system.

Latency vs Throughput vs Bandwidthโ†’

Clear meanings for speed words.

What is Caching?โ†’

The main answer to slow storage.

CDNโ†’

Beats distance by moving content near the user.

Indexingโ†’

Avoids slow random reads in a database.

LSM Treesโ†’

A design built on fast sequential writes.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • โœ”Ladder: cache (ns) โ†’ memory (~100 ns) โ†’ SSD (~100 ยตs) โ†’ network in a data centre (~0.5 ms) โ†’ disk seek (~10 ms) โ†’ across the ocean (~150 ms).
  • โœ”Gaps: memory to SSD is about 1,000 ร—. Memory to a far network trip is over a million ร—.
  • โœ”Rule 1: keep hot data in memory. Cache it.
  • โœ”Rule 2: cut network hops. Parallelise and batch the rest.
  • โœ”Rule 3: prefer sequential access over random access.
  • โœ”Rule 4: put data and servers near the users.
  • โœ”Careful: values are approximate and change with hardware. Measure your own.
  • โœ”One line: "Memory is fast, disks and networks are slow, and distance is slowest. Touch the slow things rarely."
โ† Previous
Back-of-the-Envelope Estimation
Next โ†’
SLA, SLO and SLI