Cache
A fast place, in memory, where results are kept so you don't fetch them from the database again.
Analogy
Like keeping the books you use most at hand instead of going to the library every time.
Test yourself: Cache
Cache
What is a cache for?
The database takes 50 ms and the cache 1 ms. If 9 of every 10 reads come from the cache, the average drops a lot.
Evicting and spreading the cache
In which of these cases does a cache barely help?
If the data changes every 1 second, what's stored goes stale right away and almost everything ends up going to the database.
Evicting and spreading the cache
If 9 of every 10 reads come from the cache, the database gets ___ times fewer reads.
Of 1,000 reads, 900 come from the cache and 100 reach the database: 10 times fewer.
0/3
â–¶ PlayLessons that use it
How DNS works
The internet's phone book
DNS records
Each domain's instructions
Cache
What's asked often, close at hand
Evicting and spreading the cache
The cache fills up
CDN
Content close to every user
Proxies
A middleman in between
Scaling
Bigger or more machines
Arrays
Adjacent cells
Linked lists
Links of a chain
Memory and cache
Close is fast
Hash tables
From key to slot in 1 calculation
Hash collisions
When 2 keys want the same spot
Trees in an array
No references, just math
Quick sort
A pivot and 2 sides
Heap sort
Take the maximum and leave it at the end
NoSQL databases
Beyond tables
Measure and optimize
Measure first
Consistent hashing
A ring to split the load
API Gateway
1 single front door
REST APIs
Resources and verbs
GraphQL and gRPC
Other ways to talk to an API
Requirements and estimates
Ask before you draw
The design steps
From data to bottlenecks
Designing a URL shortener
A long link in 7 characters
Generating unique keys
Where 3I71d3o comes from
Designing WhatsApp
2 billion messages a day
Designing Twitter
1 billion tweets a day
Designing Uber
10 million rides a day
