SlideShare a Scribd company logo
Building a Social Network with MongoDB
                                                   Brian Zambrano

                                                       MongoSV
                                                 December 3, 2010




                                                              1

Friday, December 3, 2010
Eventbrite Brand Tenets




                            2

Friday, December 3, 2010
Eventbrite Brand Tenets




                            3

Friday, December 3, 2010
Social Recommendations




                           4

Friday, December 3, 2010
Eventbriteʼs Social Graph




                              5

Friday, December 3, 2010
Eventbriteʼs Social Graph




                              6

Friday, December 3, 2010
Neighbors




                           7

Friday, December 3, 2010
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
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
Providing Recommendations

        1. User visits http://eventbrite.com/mytickets/
        2. Fetch neighbors
        3. Fetch neighborsʼ events
        4. Score each possible event
        5. Return recommendations




                                                          10

Friday, December 3, 2010
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
User Data in MongoDB

                { "_id": 4558992,   Unique User Id
                }




                                                     12

Friday, December 3, 2010
User Data in MongoDB

                { "_id": 4558992,
                  "events" : {
                      "all_ids": [ 116706, 179487, 16389, 827496 ],
                      "curr_ids": [ 827496 ],

                }
                  },
                                                     Past and current
                                                     attendance




                                                                        13

Friday, December 3, 2010
User Data in MongoDB

                { "_id": 4558992,
                   "events" : {
                        "all_ids": [ 116706, 179487, 16389, 827496 ],
                        "curr_ids": [ 827496 ],
                   },
                  "nns" : [
                      [ 2816442, 0.2 ],
                      [ 1615962, 0.047619047619047616 ],
                    ],
                }                                    Nearest neighbors
                                                     (user_id, score)



                                                                         14

Friday, December 3, 2010
User Data in MongoDB

                { "_id": 4558992,
                   "events" : {
                        "all_ids": [ 116706, 179487, 16389, 827496 ],
                        "curr_ids": [ 827496 ],
                   },
                  "nns" : [
                      [ 2816442, 0.2 ],
                      [ 1615962, 0.047619047619047616 ],
                     ],
                  "fb" : {
                        "_id" : 4808871,          Facebook data
                        "name" : "Brian Zambrano",
                        "location" : "San Francisco, California",
                        "friends" : [ 568876525, 569507467, 569559792 ],
                  },
                }

                                                                           15

Friday, December 3, 2010
MongoDB Indexes

                { "_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],
                  },
                }

                                                                          16

Friday, December 3, 2010
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
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
Recommended Events Query

               Two + n queries
                  1. 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 count
                           db.orders.find({_eid : event_id})




                                                                              19

Friday, December 3, 2010
Recommended Events Query

               Two + n queries
                  1. 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 count
                           db.orders.find({_eid : event_id})


                                      Optimization opportunity:
                                       Embed orders in Event records


                                                                              20

Friday, December 3, 2010
Updating Neighbors
               Two queries, one update
                  1. 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 neighbors
                  3. Update nn_ids
                           db.users.update({_id : uid},
                                           {$set : {nn_ids: nn}})



                                                                                    21

Friday, December 3, 2010
Facebook Friendʼs Events
               Two queries
                  1. Get FB friends
                           db.users.find({fb._id : {$in : fb.friends}})

                  2. Get events FB friends are attending
                           db.events.find({_id : {$in : fb_friends_events}})




                                                                               22

Friday, December 3, 2010
The Future

        • Incorporate other social networks
        • Iterate scoring algorithm
        • Count recommendation impressions




                                              23

Friday, December 3, 2010
Weʼre hiring!
                           http://www.eventbrite.com/jobs/




                                                             24

Friday, December 3, 2010
Thanks!

        Brian Zambrano <brianz@eventbrite.com>

        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

More Related Content

What's hot (19)

PPT
Building web applications with mongo db presentation
Murat Çakal
 
KEY
Schema Design with MongoDB
rogerbodamer
 
PDF
MongoDB Schema Design
Alex Litvinok
 
KEY
Schema Design by Example ~ MongoSF 2012
hungarianhc
 
PPTX
Socialite, the Open Source Status Feed Part 2: Managing the Social Graph
MongoDB
 
PPTX
Back to Basics 1: Thinking in documents
MongoDB
 
PPTX
Socialite, the Open Source Status Feed Part 3: Scaling the Data Feed
MongoDB
 
PDF
Building your first app with mongo db
MongoDB
 
PPTX
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB
 
PPTX
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
MongoDB
 
PPTX
Data Modeling for the Real World
Mike Friedman
 
PDF
Agile Schema Design: An introduction to MongoDB
Stennie Steneker
 
PPTX
Back to Basics Webinar 3 - Thinking in Documents
Joe Drumgoole
 
PDF
Real-time Location Based Social Discovery using MongoDB
Fredrik Björk
 
PPTX
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
MongoDB
 
PDF
Building Apps with MongoDB
Nate Abele
 
PPT
Building Your First MongoDB App ~ Metadata Catalog
hungarianhc
 
PPTX
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
MongoDB
 
PPTX
Back to Basics Webinar 2: Your First MongoDB Application
MongoDB
 
Building web applications with mongo db presentation
Murat Çakal
 
Schema Design with MongoDB
rogerbodamer
 
MongoDB Schema Design
Alex Litvinok
 
Schema Design by Example ~ MongoSF 2012
hungarianhc
 
Socialite, the Open Source Status Feed Part 2: Managing the Social Graph
MongoDB
 
Back to Basics 1: Thinking in documents
MongoDB
 
Socialite, the Open Source Status Feed Part 3: Scaling the Data Feed
MongoDB
 
Building your first app with mongo db
MongoDB
 
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB
 
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
MongoDB
 
Data Modeling for the Real World
Mike Friedman
 
Agile Schema Design: An introduction to MongoDB
Stennie Steneker
 
Back to Basics Webinar 3 - Thinking in Documents
Joe Drumgoole
 
Real-time Location Based Social Discovery using MongoDB
Fredrik Björk
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
MongoDB
 
Building Apps with MongoDB
Nate Abele
 
Building Your First MongoDB App ~ Metadata Catalog
hungarianhc
 
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
MongoDB
 
Back to Basics Webinar 2: Your First MongoDB Application
MongoDB
 

Similar to Building a Social Network with MongoDB (20)

PDF
Building a Social Network with MongoDB
Lewis Lin 🦊
 
KEY
Building your first application w/mongoDB MongoSV2011
Steven Francia
 
PPTX
First app online conf
MongoDB
 
PPTX
Building a Location-based platform with MongoDB from Zero.
Ravi Teja
 
PDF
1 24 - user data management
MongoDB
 
PDF
Webinar: User Data Management with MongoDB
MongoDB
 
KEY
Building a Cross Channel Content Delivery Platform with MongoDB
MongoDB
 
PDF
Starting with MongoDB
DoThinger
 
PPTX
Webinar: Building Your First Application with MongoDB
MongoDB
 
KEY
Flexible Event Tracking (Paul Gebheim)
MongoSF
 
PDF
De normalised london aggregation framework overview
Chris Harris
 
PPTX
MediaGlu and Mongo DB
Sundar Nathikudi
 
PPTX
User Data Management with MongoDB
MongoDB
 
KEY
Building Your First MongoDB Application
Rick Copeland
 
PDF
Intro To MongoDB
Alex Sharp
 
PDF
Geolocation in MongoDB
Shashank Tiwari
 
PDF
ConFoo - Migrating To Mongo Db
Context.IO
 
PPTX
Operational Intelligence with MongoDB Webinar
MongoDB
 
PDF
Nosql hands on handout 04
Krishna Sankar
 
PPTX
Taming Social Media with MongoDB
HumanGeo Group
 
Building a Social Network with MongoDB
Lewis Lin 🦊
 
Building your first application w/mongoDB MongoSV2011
Steven Francia
 
First app online conf
MongoDB
 
Building a Location-based platform with MongoDB from Zero.
Ravi Teja
 
1 24 - user data management
MongoDB
 
Webinar: User Data Management with MongoDB
MongoDB
 
Building a Cross Channel Content Delivery Platform with MongoDB
MongoDB
 
Starting with MongoDB
DoThinger
 
Webinar: Building Your First Application with MongoDB
MongoDB
 
Flexible Event Tracking (Paul Gebheim)
MongoSF
 
De normalised london aggregation framework overview
Chris Harris
 
MediaGlu and Mongo DB
Sundar Nathikudi
 
User Data Management with MongoDB
MongoDB
 
Building Your First MongoDB Application
Rick Copeland
 
Intro To MongoDB
Alex Sharp
 
Geolocation in MongoDB
Shashank Tiwari
 
ConFoo - Migrating To Mongo Db
Context.IO
 
Operational Intelligence with MongoDB Webinar
MongoDB
 
Nosql hands on handout 04
Krishna Sankar
 
Taming Social Media with MongoDB
HumanGeo Group
 
Ad

Recently uploaded (20)

PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Ad

Building a Social Network with MongoDB

  • 1. Building a Social Network with MongoDB Brian Zambrano MongoSV December 3, 2010 1 Friday, December 3, 2010
  • 2. Eventbrite Brand Tenets 2 Friday, December 3, 2010
  • 3. Eventbrite Brand Tenets 3 Friday, December 3, 2010
  • 4. Social Recommendations 4 Friday, December 3, 2010
  • 5. Eventbriteʼs Social Graph 5 Friday, December 3, 2010
  • 6. Eventbriteʼs Social Graph 6 Friday, December 3, 2010
  • 7. Neighbors 7 Friday, December 3, 2010
  • 8. 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
  • 9. 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
  • 10. Providing Recommendations 1. User visits http://eventbrite.com/mytickets/ 2. Fetch neighbors 3. Fetch neighborsʼ events 4. Score each possible event 5. Return recommendations 10 Friday, December 3, 2010
  • 11. 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
  • 12. User Data in MongoDB { "_id": 4558992, Unique User Id } 12 Friday, December 3, 2010
  • 13. User Data in MongoDB { "_id": 4558992, "events" : { "all_ids": [ 116706, 179487, 16389, 827496 ], "curr_ids": [ 827496 ], } }, Past and current attendance 13 Friday, December 3, 2010
  • 14. User Data in MongoDB { "_id": 4558992, "events" : { "all_ids": [ 116706, 179487, 16389, 827496 ], "curr_ids": [ 827496 ], }, "nns" : [ [ 2816442, 0.2 ], [ 1615962, 0.047619047619047616 ], ], } Nearest neighbors (user_id, score) 14 Friday, December 3, 2010
  • 15. User Data in MongoDB { "_id": 4558992, "events" : { "all_ids": [ 116706, 179487, 16389, 827496 ], "curr_ids": [ 827496 ], }, "nns" : [ [ 2816442, 0.2 ], [ 1615962, 0.047619047619047616 ], ], "fb" : { "_id" : 4808871, Facebook data "name" : "Brian Zambrano", "location" : "San Francisco, California", "friends" : [ 568876525, 569507467, 569559792 ], }, } 15 Friday, December 3, 2010
  • 16. MongoDB Indexes { "_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], }, } 16 Friday, December 3, 2010
  • 17. 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
  • 18. 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
  • 19. Recommended Events Query Two + n queries 1. 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 count db.orders.find({_eid : event_id}) 19 Friday, December 3, 2010
  • 20. Recommended Events Query Two + n queries 1. 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 count db.orders.find({_eid : event_id}) Optimization opportunity: Embed orders in Event records 20 Friday, December 3, 2010
  • 21. Updating Neighbors Two queries, one update 1. 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 neighbors 3. Update nn_ids db.users.update({_id : uid}, {$set : {nn_ids: nn}}) 21 Friday, December 3, 2010
  • 22. Facebook Friendʼs Events Two queries 1. Get FB friends db.users.find({fb._id : {$in : fb.friends}}) 2. Get events FB friends are attending db.events.find({_id : {$in : fb_friends_events}}) 22 Friday, December 3, 2010
  • 23. The Future • Incorporate other social networks • Iterate scoring algorithm • Count recommendation impressions 23 Friday, December 3, 2010
  • 24. Weʼre hiring! http://www.eventbrite.com/jobs/ 24 Friday, December 3, 2010
  • 25. 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