Building a Social Network with MongoDB
-
Upload
fred-chu -
Category
Technology
-
view
844 -
download
2
description
Transcript of Building a Social Network with MongoDB
![Page 1: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/1.jpg)
Building a Social Network with MongoDBBrian Zambrano
MongoSVDecember 3, 2010
1
Friday, December 3, 2010
![Page 2: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/2.jpg)
Eventbrite Brand Tenets
2
Friday, December 3, 2010
![Page 3: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/3.jpg)
Eventbrite Brand Tenets
3
Friday, December 3, 2010
![Page 4: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/4.jpg)
Social Recommendations
4
Friday, December 3, 2010
![Page 5: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/5.jpg)
Eventbriteʼs Social Graph
5
Friday, December 3, 2010
![Page 6: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/6.jpg)
Eventbriteʼs Social Graph
6
Friday, December 3, 2010
![Page 7: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/7.jpg)
Neighbors
7
Friday, December 3, 2010
![Page 8: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/8.jpg)
Challenges
• Dynamic • Neighbors change often• Neighborsʼ events change often
• Flexibility• Want to incorporate other social graphs• Product may evolve quickly
• Performance• We need really fast reads• Frequent writes
8
Friday, December 3, 2010
![Page 9: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/9.jpg)
Why MongoDB?
• Performance• Flexible schema design• Easy to work with• We felt comfortable MongoDB would mature as
our needs became more demanding
9
Friday, December 3, 2010
![Page 10: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/10.jpg)
Providing Recommendations
1. User visits http://eventbrite.com/mytickets/2. Fetch neighbors3. Fetch neighborsʼ events4. Score each possible event5. Return recommendations
10
Friday, December 3, 2010
![Page 11: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/11.jpg)
MongoDB setup
• One non-sharded replica set• Two DBs on Large EC2 instances• One arbiter
• Three collections• Users• Events• Orders
11
Friday, December 3, 2010
![Page 12: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/12.jpg)
User Data in MongoDB
12
{ "_id": 4558992,}
Unique User Id
Friday, December 3, 2010
![Page 13: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/13.jpg)
User Data in MongoDB
13
{ "_id": 4558992, "events" : { "all_ids": [ 116706, 179487, 16389, 827496 ], "curr_ids": [ 827496 ], },}
Past and currentattendance
Friday, December 3, 2010
![Page 14: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/14.jpg)
User Data in MongoDB
14
{ "_id": 4558992, "events" : { "all_ids": [ 116706, 179487, 16389, 827496 ], "curr_ids": [ 827496 ], }, "nns" : [ [ 2816442, 0.2 ], [ 1615962, 0.047619047619047616 ], ],} Nearest neighbors
(user_id, score)
Friday, December 3, 2010
![Page 15: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/15.jpg)
User Data in MongoDB
15
{ "_id": 4558992, "events" : { "all_ids": [ 116706, 179487, 16389, 827496 ], "curr_ids": [ 827496 ], }, "nns" : [ [ 2816442, 0.2 ], [ 1615962, 0.047619047619047616 ], ], "fb" : { "_id" : 4808871, "name" : "Brian Zambrano", "location" : "San Francisco, California", "friends" : [ 568876525, 569507467, 569559792 ], },}
Facebook data
Friday, December 3, 2010
![Page 16: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/16.jpg)
MongoDB Indexes
16
{ "_id": 4558992, "events" : { "all_ids": [ 116706, 179487, 16389, 827496 ], "curr_ids": [ 827496 ], }, "nns" : [ [ 2816442, 0.2 ], [ 1615962, 0.047619047619047616 ], ], "fb" : { "_id" : 4808871, "name" : "Brian Zambrano", "location" : "San Francisco, California", "friends" : [ 568876525, 569507467, 569559792], },}
Friday, December 3, 2010
![Page 17: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/17.jpg)
Events Collection> db.events.findOne({_id: 799177}) { "_id" : 799177, "uid" : 2989008, "title" : "MongoSV", "venue" : { "loc" : [ 37.413042, -122.071106 ], "state" : "CA", "id" : 508093, "city" : "Mountain View" }, "logo" : "758915938.png", "shortname" : "mongosv", "start_date" : "Fri Dec 03 2010 01:00:00 GMT-0800 (PST)"}
17
Friday, December 3, 2010
![Page 18: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/18.jpg)
Orders Collection> db.orders.find({_eid: 799177}) { "_id" : 17464215, "_uid" : 1111195, "_eid" : 799177 }{ "_id" : 17575729, "_uid" : 6970539, "_eid" : 799177 }{ "_id" : 17582343, "_uid" : 3092687, "_eid" : 799177 }{ "_id" : 17588693, "_uid" : 2255017, "_eid" : 799177 }{ "_id" : 17589589, "_uid" : 6976917, "_eid" : 799177 }{ "_id" : 17601979, "_uid" : 885441, "_eid" : 799177 }{ "_id" : 17603085, "_uid" : 2500199, "_eid" : 799177 }{ "_id" : 17608289, "_uid" : 6984367, "_eid" : 799177 }{ "_id" : 17681965, "_uid" : 628459, "_eid" : 799177 }{ "_id" : 17684489, "_uid" : 7017999, "_eid" : 799177 }{ "_id" : 17689673, "_uid" : 7020133, "_eid" : 799177 }{ "_id" : 17728267, "_uid" : 7036607, "_eid" : 799177 }has more
18
Friday, December 3, 2010
![Page 19: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/19.jpg)
Recommended Events Query
Two + n queries1. Get neighbors
nns = db.users.find({_id : {$in : user.nn_ids}})
2. Get possible event recommendations: db.events.find({_id : {$in : nns.events.all}})
n.For each event, get total attendee countdb.orders.find({_eid : event_id})
19
Friday, December 3, 2010
![Page 20: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/20.jpg)
Recommended Events Query
Two + n queries1. Get neighbors
nns = db.users.find({_id : {$in : user.nn_ids}})
2. Get possible event recommendations: db.events.find({_id : {$in : nns.events.all}})
n.For each event, get total attendee countdb.orders.find({_eid : event_id})
20
Optimization opportunity: Embed orders in Event records
Friday, December 3, 2010
![Page 21: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/21.jpg)
Updating Neighbors
Two queries, one update1. Get all orders for a userʼs past events:
uids = db.orders.find({_id : {$in : user.events.all}})
2. Get all neighbors: nns = db.users.find({_id : {$in : uids}})
➡Score neighbors3. Update nn_ids
db.users.update({_id : uid}, {$set : {nn_ids: nn}})
21
Friday, December 3, 2010
![Page 22: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/22.jpg)
Facebook Friendʼs Events
Two queries1. Get FB friends
db.users.find({fb._id : {$in : fb.friends}})
2. Get events FB friends are attendingdb.events.find({_id : {$in : fb_friends_events}})
22
Friday, December 3, 2010
![Page 23: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/23.jpg)
The Future
• Incorporate other social networks• Iterate scoring algorithm• Count recommendation impressions
23
Friday, December 3, 2010
![Page 24: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/24.jpg)
Weʼre hiring!
http://www.eventbrite.com/jobs/
24
Friday, December 3, 2010
![Page 25: Building a Social Network with MongoDB](https://reader033.fdocuments.us/reader033/viewer/2022051412/549a5535b479593d6a8b4b8f/html5/thumbnails/25.jpg)
Thanks!
Brian Zambrano <[email protected]>
Eventbriteʼs new Facebook recommendations power social event discovery: http://bit.ly/gRVS7I
Social Commerce: A First Look at the Numbers: http://bit.ly/gXeg9Q
25
Friday, December 3, 2010