shortcuts:
TOC
NanoTwitter
search:
Database Tuning 2
(Tue Mar 29, lect 19)
|
previous
|
next
|
slides
|
How database architecture affects performance and scale and how to improve it
Logistics
Magic code:
Scalability Pattern: Database Caching
Using caching (e.g. redis) to reduce db access
Example: Social Graph
Schema (like all of you have)
User(id, name)
Follow(id, follower_id, following_id)
Content(id, author_id)
Nicely normalized
First, Second and Third Normal form
Origins of the relational database
Queries like:
How many people are following user X?
Who is following user Y?
What are the most recent “n” posts (i.e. content) for user “u”?
What are the most recent “n” posts for users that “u” is following?
But to display each and every user, a join is needed!
Measurement
Ask database system to analyze SQL queries that are slow
Discover that the social graph access was very slow
Discussion
Have you started using redis yet in your projects?
What do your redis keys look like?
How do you compute your cache key?
DB: Caching
Use Network scale caching (Redis) to store and share across servers
count:followers:u = number
count:following:u = number
How to maintain this number?
How important is it that it is correct?
What might make it incorrect?
Add APIs
get_follower_count(user), get_following_count(user), incr_follower_count(user), decr_follower_count(user), incr_following_count(user), decr_following_count(user)
What class has those methods?
Where are they invoked?
Result of queries?
Result of search?
Creating the cache key
What do you store in the cache?
Teams
Discuss and design how you would incorporate this idea in your specific nanoTwitter
Thank you. Questions?
(random Image from picsum.photos)
Intro
Cosi105 - Scalability 2022 Syllabus
List of lectures
nanoTwitter
Homeworks
Lectures
Web Apps + Sinatra
Welcome
What is Scalability?
Cosi166 Quick Bullets
Intro to Sinatra
Sinatra and Twitter
NanoTwitter introduced
nano Twitter
Starting to think about scaling
Scaling at Hubspot
Service Oriented Architecture
Deploying to the Cloud
Scalable Service design
Scalability, continued
Testing in the world of SOA
Scaling Patterns
Testing Scalability
Tuning for Scale
Logging
Caching
Database Tuning 1
Database Tuning 2
Concurrency 1
Concurrency 2
Queueing
SOA + µservices
Software Engineering
Scalability Runoff 1
Last class!
Background
Technical Presentations
Misc Links and Resources