Académique Documents
Professionnel Documents
Culture Documents
Marty Weiner
Yashh Nelapati
Grayskull, Eternia
Gotham City
Pinterest is . . .
An online pinboard to organize and
share what inspires you.
Scaling Pinterest
Relationships
Marty Weiner
Grayskull, Eternia
Yashh Nelapati
Gotham City
Scaling Pinterest
Mar 2010
Mar 2010
Scaling Pinterest
RackSpace
1 small Web Engine
Jan 2011
Jan 2012
1 small MySQL DB
Jan 2011
Jan 2012
Mar 2010
Scaling Pinterest
Jan 2012
Mar 2010
Mar 2010
Scaling Pinterest
Jan 2012
Jan 2012
Lesson Learned #1
It will fail. Keep it simple.
Scaling Pinterest
Mar 2010
Scaling Pinterest
Jan 2011
Jan 2012
Scaling Pinterest
Why MySQL?
Scaling Pinterest
Extremely mature
Well known and well liked
Rarely catastrophic loss of data
Response time to request rate increases linearly
Very good software support - XtraBackup, Innotop, Maatkit
Solid active community
Very good support from Percona
Free
Why Memcache?
Scaling Pinterest
Extremely mature
Very good performance
Well known and well liked
Never crashes, and few failure modes
Free
Why Redis?
Scaling Pinterest
Scaling Pinterest
Clustering
vs
Sharding
Scaling Pinterest
Clustering vs Sharding
Distributes data across
nodes automatically
Scaling Pinterest
Why Clustering?
Scaling Pinterest
source: thereifixedit.com
Scaling Pinterest
Scaling Pinterest
Scaling Pinterest
Cluster Manager
Scaling Pinterest
Lesson Learned #2
Clustering is scary.
Scaling Pinterest
Why Sharding?
Scaling Pinterest
When to shard?
Scaling Pinterest
Our Transition
1 DB + Foreign Keys + Joins
1 DB + Denormalized + Cache
1 DB + Read slaves + Cache
Several functionally sharded DBs + Read slaves + Cache
ID sharded DBs + Backup slaves + Cache
Scaling Pinterest
Scaling Pinterest
How we sharded
Scaling Pinterest
db00001
db00002
.......
db00512
db00513
db00514
.......
db01024
db03072
db03073
.......
db03583
db03584
db03585
.......
db04096
High Availability
db00001
db00002
.......
db00512
db00513
db00514
.......
db01024
db03072
db03073
.......
db03583
db03584
db03585
.......
db04096
db00001
db00002
.......
db00256
db00001
db00002
.......
db00512
db00257
db00258
.......
db00512
ID Structure
64 bits
Shard ID
Type
Local ID
Scaling Pinterest
Scaling Pinterest
Lookup Structure
{sharddb001a: ( 1, 512),
sharddb002b: ( 513, 1024),
sharddb003a: (1025, 1536),
...
sharddb008b: (3585, 4096)}
sharddb003a
Scaling Pinterest
DB01025
users
users
ser-data
user_has_boards
ser-data
boards
ser-data
ID Structure
Scaling Pinterest
Local ID
Scaling Pinterest
Full ID
Full ID (+ timestamp)
Scaling Pinterest
Loading a Page
Scaling Pinterest
Scripting
Scaling Pinterest
Future problems
Connection limits
Isolation of functionality
Scaling Pinterest
Interesting Tidbits
Scaling Pinterest
Lesson Learned #3
Working at Pinterest is AWESOME
Scaling Pinterest
We are Hiring!
jobs@pinterest.com
Scaling Pinterest
Questions?
marty@pinterest.com
Scaling Pinterest
yashh@pinterest.com