Scaling Memcache at Facebook - Slides
Scaling Memcache at Facebook - Slides
at Facebook
Storage Replication
2. Multiple front-end clusters
FE FE
• Controlling data replication Memcache Memcache
• Data consistency
Storage Cluster Storage Cluster
(Master) (Replica)
3. Multiple Regions
• Data consistency
Pre-memcache
Just a few databases are enough to support the load
Interstitial slide
0 No memcache servers
2
Interstitial slide
Many memcache servers in one cluster
• Memcache needs to be
invalidated after DB write Web Server
• Prefer deletes to sets
1. Database 2. Delete
• Idempotent update
• Demand filled
• Up to web application
to specify which keys Memcache
• Extend memcache
Web Server Web Server protocol with leases
A B
• Return and attach a
1. Read (A) lease-id with every miss
3. Read (B) 4. Set (B) • Lease-id is invalidated
inside server on a delete
5. Set (A)
• Disallow set if the
lease-id is
Database Memcache invalid at the server
A
B A
B
2. Updated to (B)
MC & DB Inconsistent
Problems with look-aside caching
Thundering Herds
0 No memcache servers
2
Interstitial slide
Many memcache servers in one cluster
Get key1
10kB val Get
10kBkey2
val Getval
5kB key3 Get keyN
7kB val
0 No memcache servers
2
Interstitial slide
Many memcache servers in one cluster
horizontal scaling
Web Server Web Server
• Multiple memcache
clusters front one FE FE
Memcache Memcache
DB installation
• Have to keep the caches
consistent
Storage Cluster (Master)
• Have to manage
over-replication of data
Databases invalidate caches
Front-End Cluster #1 Front-End Cluster #2 Front-End Cluster #3
MC MC MC MC MC MC MC MC MC MC MC
MySQL McSqueal
Storage Server Commit Log
MC MC MC MC MC MC MC MC MC MC MC
Memcache Routers
• Aggregating deletes reduces
packet rate by 18x
• Makes configuration
McSqueal McSqueal McSqueal
management easier
DB DB DB • Each stage buffers deletes in
case downstream component is
down
Scaling memcache in 4 easy steps
1000s of servers & > 1 billion operations per second
0 No memcache servers
Replica Master
Writes in non-master
Database update directly in master
Web Web
Server Server
3. Read from DB
(get missed)
2. Delete from mc
1. Write to master 4. Set potentially
state value to
memcache
Race!
Master Replica Memcache
DB 3. MySQL replication DB
Remote markers
Set a special flag that indicates whether a race is likely
Read miss path:
If marker set
read from master DB
else
read from replica DB
Web Server
1. Set remote
marker
2. Write to master
3. Delete from
memcache
Storage Replication
2. Multiple front-end clusters
FE FE
• Controlling data replication Memcache Memcache
• Data consistency
Storage Cluster Storage Cluster
(Master) (Replica)
3. Multiple Regions
• Data consistency
Lessons Learned
• Push complexity into the client whenever possible
• Operational efficiency is as important
as performance
• Separating cache and persistent store allows them
to be scaled independently
Thanks! Questions?
http://www.facebook.com/careers