SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
Real-time Location Based Social
  Discovery using MongoDB




         Fredrik Björk
       Director of Engineering
           MongoSV, Dec 4th 2012
What is Banjo?
• The most powerful location based mobile
  technology that brings you the moments
  you would otherwise miss
• Aggregates geo tagged posts from
  Facebook, Twitter, Instagram and
  Foursquare in real-time
3
Stats
•   Launched June 2011
•   3 million users
•   Social graph of 400 million profiles
•   50 billion connections
•   ~200 geo posts created per second




                                          4
Why MongoDB?
• Developer friendly
• Easy to maintain and scale
• Automatic failover
• Rapid prototyping of features
• Good fit for consuming, storing and
  presenting JSON data
• Geospatial features out of the box


                                       5
Infrastructure
• ~160 EC2 instances (75% MongoDB, 25%
  Redis)
• SSD drives for low latency
• App servers (Sinatra & Rails) hosted on
  Heroku
• Mongos with authentication running on
  dedicated servers



                                            6
Geo tagged posts
• Consumed as JSON from social network
  APIs - streaming, polling & real-time
  callbacks
• Exposed via REST APIs as JSON to the
  Banjo iOS and Android apps




                                          7
Schema design




https://twitter.com/fbjork/status/262989592561606656




                                                       8
• _id is composed of provider (Facebook:
  1, Twitter: 2 etc.) and post id for
  uniqueness

          https://twitter.com/fbjork/status/262989592561606656


> db.posts.find({ _id: ‘2:262989592561606656’ })

{
    _id: “2:262989592561606656”,
    username: “fbjork”,
    text: “Will give a presentation at #MongoSV on how we use @MongoDB for
    real-time location based social discovery at @Banjo http://www.10gen.com/
    events/mongosv”,
    ...
}
                                                                                9
• Coordinates are stored inside an array
  with latitude, longitude


{
    _id: “2:262989592561606656”,
    username: “fbjork”,
    text: “Will give a presentation at #MongoSV on how we use @MongoDB for
    real-time location based social discovery at @Banjo http://www.10gen.com/
    events/mongosv”,
    coordinates: [37.784234,-122.438212],
    ...
}




                                                                            10
• Friends are stored inside an array



{
    _id: “2:262989592561606656”,
    username: “fbjork”,
    text: “Will give a presentation at #MongoSV on how we use @MongoDB for
    real-time location based social discovery at @Banjo http://www.10gen.com/
    events/mongosv”,
    coordinates: [37.784234,-122.438212],
    friend_ids: [8816792, 10324882, 2006261, ...]
}




                                                                            11
12
Geospatial Indexing
• Create the geo index:


> db.posts.ensureIndex( { coordinates: ‘2d’ } )




                                                  13
Find nearby posts in Miami:



> db.posts.find( { coordinates: { $near: [25.792627,-80.226142] } } )


{ _id: “2:809438082”, coordinates: [25.792610,-80.226100], username:
“Rebecca_Boorsma”, text: “I love Miami!”, ... }


{ _id: “2:1234567”, coordinates: [25.781324,-80.431423], username:
“foo”, text: “Another day, another dollar”, ... }




                                                                       14
15
Find friend posts globally:



> db.posts.find({ friend_ids: { $in: [2006261] })


{
    _id: “2:10248172”,
    username: “fbjork”,
    friend_ids: [8816792, 10324882, 2006261, ...],
    ...
}




                                                     16
Find friend posts in a location:



> db.posts.find({ coordinates: { $near: [25.792627,-80.226142] },
friend_ids: { $in: [2006261] })


{
    _id: “2:10248172”,
    username: “fbjork”,
    friend_ids: [8816792, 10324882, 2006261, ...],
    ...
}



                                                                   17
Compound geo indexes
• Create a compound index on coordinates
  and friend_ids:

> db.posts.ensureIndex( { coordinates: ‘2d’, friend_ids: 1 } )




                                                                 18
• Fails for compound indexes with large
   arrays
 • Geospatial indexes have a size limit of
   1000 bytes

> db.posts.ensureIndex( { coordinates: ‘2d’, friend_ids: 1 } )


Error: Key too large to index




                                                                 19
Geospatial query performance
• Do we need a compound index at all?
• Geospatial index is usually restrictive
  enough
• Problem: Array traversal (using $in) is
  CPU hungry for large arrays
• Solution: Pre-sharded array fields




                                            20
Pre-sharded array fields
• When dealing with large arrays, i.e
  @BarackObama follower ids
• Partition fields using pre-sharding
• shard = Hash(key) MOD shard_count
• Keep array sizes in the low hundreds




                                         21
# shard_example.rb

SHARDS = 3
friend_ids = [1000 , 1001, 1002, 1003, 1004, 1005, 1006]
friend_ids.each { |f| puts Zlib.crc32(f.to_s) % SHARDS }
0
2
0
2
1
2
0


{
    friends_0: [1000, 1002, 1006],
    friends_1: [1004],
    friends_2: [1001, 1003, 1005]
}

                                                           22
Find friend posts using pre-sharding
of the friend arrays:




> db.posts.find({ coordinates: { $near: [25.792627,-80.226142] },
friend_0: { $in: [1000] })

{
    friends_0: [1000, 1002, 1006],
    friends_1: [1004],
    friends_2: [1001, 1003, 1005]
}




                                                                   23
Capped collections
• Good fit for storing a feed of posts for a
  period of time
• Eliminates need to expire old posts
• Documents can’t grow
• Documents can’t be deleted
• Resizing collections is painful
• Can’t be sharded


                                              24
TTL collections
• We switched to TTL collections with
  MongoDB 2.2
• Deleting and growing documents is now
  possible
• Easier to change expiration times
• Can be sharded (not by geo)




                                          25
Questions




            26
Thank you!


     Available:                   fredrik@teambanjo.com
iPhone and Android                        @fbjork

Contenu connexe

Tendances

Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsMongoDB
 
Webinar: Schema Design
Webinar: Schema DesignWebinar: Schema Design
Webinar: Schema DesignMongoDB
 
MongoDB Schema Design
MongoDB Schema DesignMongoDB Schema Design
MongoDB Schema DesignMongoDB
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDBrogerbodamer
 
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...MongoDB
 
Schema Design by Example ~ MongoSF 2012
Schema Design by Example ~ MongoSF 2012Schema Design by Example ~ MongoSF 2012
Schema Design by Example ~ MongoSF 2012hungarianhc
 
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesBack to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesMongoDB
 
Data Modeling for the Real World
Data Modeling for the Real WorldData Modeling for the Real World
Data Modeling for the Real WorldMike Friedman
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMike Friedman
 
Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentationMurat Çakal
 
Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.Ravi Teja
 
Building a Social Network with MongoDB
  Building a Social Network with MongoDB  Building a Social Network with MongoDB
Building a Social Network with MongoDBFred Chu
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsMongoDB
 
MongoDB Advanced Schema Design - Inboxes
MongoDB Advanced Schema Design - InboxesMongoDB Advanced Schema Design - Inboxes
MongoDB Advanced Schema Design - InboxesJared Rosoff
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Javaantoinegirbal
 
Agile Schema Design: An introduction to MongoDB
Agile Schema Design: An introduction to MongoDBAgile Schema Design: An introduction to MongoDB
Agile Schema Design: An introduction to MongoDBStennie Steneker
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDBNate Abele
 
Building your first app with mongo db
Building your first app with mongo dbBuilding your first app with mongo db
Building your first app with mongo dbMongoDB
 

Tendances (19)

Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
 
Webinar: Schema Design
Webinar: Schema DesignWebinar: Schema Design
Webinar: Schema Design
 
MongoDB Schema Design
MongoDB Schema DesignMongoDB Schema Design
MongoDB Schema Design
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDB
 
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
 
Schema Design by Example ~ MongoSF 2012
Schema Design by Example ~ MongoSF 2012Schema Design by Example ~ MongoSF 2012
Schema Design by Example ~ MongoSF 2012
 
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesBack to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
 
Data Modeling for the Real World
Data Modeling for the Real WorldData Modeling for the Real World
Data Modeling for the Real World
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World Examples
 
Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentation
 
Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.
 
Building a Social Network with MongoDB
  Building a Social Network with MongoDB  Building a Social Network with MongoDB
Building a Social Network with MongoDB
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
 
MongoDB Advanced Schema Design - Inboxes
MongoDB Advanced Schema Design - InboxesMongoDB Advanced Schema Design - Inboxes
MongoDB Advanced Schema Design - Inboxes
 
MongoDB dessi-codemotion
MongoDB dessi-codemotionMongoDB dessi-codemotion
MongoDB dessi-codemotion
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Java
 
Agile Schema Design: An introduction to MongoDB
Agile Schema Design: An introduction to MongoDBAgile Schema Design: An introduction to MongoDB
Agile Schema Design: An introduction to MongoDB
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDB
 
Building your first app with mongo db
Building your first app with mongo dbBuilding your first app with mongo db
Building your first app with mongo db
 

En vedette

茨城県、医療・福祉で活性化
茨城県、医療・福祉で活性化茨城県、医療・福祉で活性化
茨城県、医療・福祉で活性化Nobuyuki Kawagashira
 
ヤマトメール便が廃止に 4月以降の代替サービスは?
ヤマトメール便が廃止に 4月以降の代替サービスは?ヤマトメール便が廃止に 4月以降の代替サービスは?
ヤマトメール便が廃止に 4月以降の代替サービスは?節約 社長
 
政府債務の償還と財源の通貨発行権(借換債と交付債)について2015.11.20
政府債務の償還と財源の通貨発行権(借換債と交付債)について2015.11.20政府債務の償還と財源の通貨発行権(借換債と交付債)について2015.11.20
政府債務の償還と財源の通貨発行権(借換債と交付債)について2015.11.20Kenji Katsuragi
 
20140529毎日新聞社メディアカフェ講演「インターネットは政治を変えるか?―立命館大、毎日新聞共同研究が明らかにした可能性」
20140529毎日新聞社メディアカフェ講演「インターネットは政治を変えるか?―立命館大、毎日新聞共同研究が明らかにした可能性」20140529毎日新聞社メディアカフェ講演「インターネットは政治を変えるか?―立命館大、毎日新聞共同研究が明らかにした可能性」
20140529毎日新聞社メディアカフェ講演「インターネットは政治を変えるか?―立命館大、毎日新聞共同研究が明らかにした可能性」亮介 西田
 
Strum To a New Market
Strum To a New MarketStrum To a New Market
Strum To a New MarketKelly Ihme
 
被災者の行政手続きにおける地図情報の活用とAPIの利用
被災者の行政手続きにおける地図情報の活用とAPIの利用被災者の行政手続きにおける地図情報の活用とAPIの利用
被災者の行政手続きにおける地図情報の活用とAPIの利用Yoichi Kayama
 
ARtoolkitを用いた漢字学習
ARtoolkitを用いた漢字学習ARtoolkitを用いた漢字学習
ARtoolkitを用いた漢字学習yuuki oonaka
 
Editing tips
Editing tipsEditing tips
Editing tipsron mader
 
地域経済に対する自治体財政の影響に関する研究
地域経済に対する自治体財政の影響に関する研究地域経済に対する自治体財政の影響に関する研究
地域経済に対する自治体財政の影響に関する研究Yutaka ENARI
 
研究内容プレゼンテーション(リサーチデザイン)
研究内容プレゼンテーション(リサーチデザイン)研究内容プレゼンテーション(リサーチデザイン)
研究内容プレゼンテーション(リサーチデザイン)眞嶌 名奈
 
Glimpse Inside the 2016 Digital Storytelling Toolkit
Glimpse Inside the 2016 Digital Storytelling ToolkitGlimpse Inside the 2016 Digital Storytelling Toolkit
Glimpse Inside the 2016 Digital Storytelling ToolkitVictor Hernandez
 
政府の人工知能研究の取組と産業界への期待
政府の人工知能研究の取組と産業界への期待政府の人工知能研究の取組と産業界への期待
政府の人工知能研究の取組と産業界への期待NVIDIA Japan
 
政府債務の償還と財源の通貨発行権(借換債と交付債)
政府債務の償還と財源の通貨発行権(借換債と交付債)政府債務の償還と財源の通貨発行権(借換債と交付債)
政府債務の償還と財源の通貨発行権(借換債と交付債)Kenji Katsuragi
 

En vedette (15)

夕会3
夕会3夕会3
夕会3
 
茨城県、医療・福祉で活性化
茨城県、医療・福祉で活性化茨城県、医療・福祉で活性化
茨城県、医療・福祉で活性化
 
ヤマトメール便が廃止に 4月以降の代替サービスは?
ヤマトメール便が廃止に 4月以降の代替サービスは?ヤマトメール便が廃止に 4月以降の代替サービスは?
ヤマトメール便が廃止に 4月以降の代替サービスは?
 
政府債務の償還と財源の通貨発行権(借換債と交付債)について2015.11.20
政府債務の償還と財源の通貨発行権(借換債と交付債)について2015.11.20政府債務の償還と財源の通貨発行権(借換債と交付債)について2015.11.20
政府債務の償還と財源の通貨発行権(借換債と交付債)について2015.11.20
 
20140529毎日新聞社メディアカフェ講演「インターネットは政治を変えるか?―立命館大、毎日新聞共同研究が明らかにした可能性」
20140529毎日新聞社メディアカフェ講演「インターネットは政治を変えるか?―立命館大、毎日新聞共同研究が明らかにした可能性」20140529毎日新聞社メディアカフェ講演「インターネットは政治を変えるか?―立命館大、毎日新聞共同研究が明らかにした可能性」
20140529毎日新聞社メディアカフェ講演「インターネットは政治を変えるか?―立命館大、毎日新聞共同研究が明らかにした可能性」
 
Strum To a New Market
Strum To a New MarketStrum To a New Market
Strum To a New Market
 
被災者の行政手続きにおける地図情報の活用とAPIの利用
被災者の行政手続きにおける地図情報の活用とAPIの利用被災者の行政手続きにおける地図情報の活用とAPIの利用
被災者の行政手続きにおける地図情報の活用とAPIの利用
 
ARtoolkitを用いた漢字学習
ARtoolkitを用いた漢字学習ARtoolkitを用いた漢字学習
ARtoolkitを用いた漢字学習
 
Editing tips
Editing tipsEditing tips
Editing tips
 
地域経済に対する自治体財政の影響に関する研究
地域経済に対する自治体財政の影響に関する研究地域経済に対する自治体財政の影響に関する研究
地域経済に対する自治体財政の影響に関する研究
 
研究内容プレゼンテーション(リサーチデザイン)
研究内容プレゼンテーション(リサーチデザイン)研究内容プレゼンテーション(リサーチデザイン)
研究内容プレゼンテーション(リサーチデザイン)
 
Glimpse Inside the 2016 Digital Storytelling Toolkit
Glimpse Inside the 2016 Digital Storytelling ToolkitGlimpse Inside the 2016 Digital Storytelling Toolkit
Glimpse Inside the 2016 Digital Storytelling Toolkit
 
yukai2
yukai2yukai2
yukai2
 
政府の人工知能研究の取組と産業界への期待
政府の人工知能研究の取組と産業界への期待政府の人工知能研究の取組と産業界への期待
政府の人工知能研究の取組と産業界への期待
 
政府債務の償還と財源の通貨発行権(借換債と交付債)
政府債務の償還と財源の通貨発行権(借換債と交付債)政府債務の償還と財源の通貨発行権(借換債と交付債)
政府債務の償還と財源の通貨発行権(借換債と交付債)
 

Similaire à Real-time Location Based Social Discovery using MongoDB

Geoindexing with MongoDB
Geoindexing with MongoDBGeoindexing with MongoDB
Geoindexing with MongoDBleafnode
 
Mongodb intro
Mongodb introMongodb intro
Mongodb introchristkv
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHPichikaway
 
Getting Started with Geospatial Data in MongoDB
Getting Started with Geospatial Data in MongoDBGetting Started with Geospatial Data in MongoDB
Getting Started with Geospatial Data in MongoDBMongoDB
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyOSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyNETWAYS
 
Learn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBLearn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBMarakana Inc.
 
First app online conf
First app   online confFirst app   online conf
First app online confMongoDB
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDBMongoDB
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)Uwe Printz
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Railsrfischer20
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling rogerbodamer
 
Starting with MongoDB
Starting with MongoDBStarting with MongoDB
Starting with MongoDBDoThinger
 
Building Your First MongoDB Application
Building Your First MongoDB ApplicationBuilding Your First MongoDB Application
Building Your First MongoDB ApplicationRick Copeland
 
Schema Design (Mongo Austin)
Schema Design (Mongo Austin)Schema Design (Mongo Austin)
Schema Design (Mongo Austin)MongoDB
 
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLBack to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLMongoDB
 
MongoDB Strange Loop 2009
MongoDB Strange Loop 2009MongoDB Strange Loop 2009
MongoDB Strange Loop 2009Mike Dirolf
 
Schema design
Schema designSchema design
Schema designchristkv
 

Similaire à Real-time Location Based Social Discovery using MongoDB (20)

Geoindexing with MongoDB
Geoindexing with MongoDBGeoindexing with MongoDB
Geoindexing with MongoDB
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHP
 
Getting Started with Geospatial Data in MongoDB
Getting Started with Geospatial Data in MongoDBGetting Started with Geospatial Data in MongoDB
Getting Started with Geospatial Data in MongoDB
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyOSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
 
Learn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBLearn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDB
 
First app online conf
First app   online confFirst app   online conf
First app online conf
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
 
MongoDB at RuPy
MongoDB at RuPyMongoDB at RuPy
MongoDB at RuPy
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
MongoDB.pdf
MongoDB.pdfMongoDB.pdf
MongoDB.pdf
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling
 
Starting with MongoDB
Starting with MongoDBStarting with MongoDB
Starting with MongoDB
 
Building Your First MongoDB Application
Building Your First MongoDB ApplicationBuilding Your First MongoDB Application
Building Your First MongoDB Application
 
Schema Design (Mongo Austin)
Schema Design (Mongo Austin)Schema Design (Mongo Austin)
Schema Design (Mongo Austin)
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLBack to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQL
 
MongoDB Strange Loop 2009
MongoDB Strange Loop 2009MongoDB Strange Loop 2009
MongoDB Strange Loop 2009
 
Schema design
Schema designSchema design
Schema design
 

Dernier

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Dernier (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

Real-time Location Based Social Discovery using MongoDB

  • 1. Real-time Location Based Social Discovery using MongoDB Fredrik Björk Director of Engineering MongoSV, Dec 4th 2012
  • 2. What is Banjo? • The most powerful location based mobile technology that brings you the moments you would otherwise miss • Aggregates geo tagged posts from Facebook, Twitter, Instagram and Foursquare in real-time
  • 3. 3
  • 4. Stats • Launched June 2011 • 3 million users • Social graph of 400 million profiles • 50 billion connections • ~200 geo posts created per second 4
  • 5. Why MongoDB? • Developer friendly • Easy to maintain and scale • Automatic failover • Rapid prototyping of features • Good fit for consuming, storing and presenting JSON data • Geospatial features out of the box 5
  • 6. Infrastructure • ~160 EC2 instances (75% MongoDB, 25% Redis) • SSD drives for low latency • App servers (Sinatra & Rails) hosted on Heroku • Mongos with authentication running on dedicated servers 6
  • 7. Geo tagged posts • Consumed as JSON from social network APIs - streaming, polling & real-time callbacks • Exposed via REST APIs as JSON to the Banjo iOS and Android apps 7
  • 9. • _id is composed of provider (Facebook: 1, Twitter: 2 etc.) and post id for uniqueness https://twitter.com/fbjork/status/262989592561606656 > db.posts.find({ _id: ‘2:262989592561606656’ }) { _id: “2:262989592561606656”, username: “fbjork”, text: “Will give a presentation at #MongoSV on how we use @MongoDB for real-time location based social discovery at @Banjo http://www.10gen.com/ events/mongosv”, ... } 9
  • 10. • Coordinates are stored inside an array with latitude, longitude { _id: “2:262989592561606656”, username: “fbjork”, text: “Will give a presentation at #MongoSV on how we use @MongoDB for real-time location based social discovery at @Banjo http://www.10gen.com/ events/mongosv”, coordinates: [37.784234,-122.438212], ... } 10
  • 11. • Friends are stored inside an array { _id: “2:262989592561606656”, username: “fbjork”, text: “Will give a presentation at #MongoSV on how we use @MongoDB for real-time location based social discovery at @Banjo http://www.10gen.com/ events/mongosv”, coordinates: [37.784234,-122.438212], friend_ids: [8816792, 10324882, 2006261, ...] } 11
  • 12. 12
  • 13. Geospatial Indexing • Create the geo index: > db.posts.ensureIndex( { coordinates: ‘2d’ } ) 13
  • 14. Find nearby posts in Miami: > db.posts.find( { coordinates: { $near: [25.792627,-80.226142] } } ) { _id: “2:809438082”, coordinates: [25.792610,-80.226100], username: “Rebecca_Boorsma”, text: “I love Miami!”, ... } { _id: “2:1234567”, coordinates: [25.781324,-80.431423], username: “foo”, text: “Another day, another dollar”, ... } 14
  • 15. 15
  • 16. Find friend posts globally: > db.posts.find({ friend_ids: { $in: [2006261] }) { _id: “2:10248172”, username: “fbjork”, friend_ids: [8816792, 10324882, 2006261, ...], ... } 16
  • 17. Find friend posts in a location: > db.posts.find({ coordinates: { $near: [25.792627,-80.226142] }, friend_ids: { $in: [2006261] }) { _id: “2:10248172”, username: “fbjork”, friend_ids: [8816792, 10324882, 2006261, ...], ... } 17
  • 18. Compound geo indexes • Create a compound index on coordinates and friend_ids: > db.posts.ensureIndex( { coordinates: ‘2d’, friend_ids: 1 } ) 18
  • 19. • Fails for compound indexes with large arrays • Geospatial indexes have a size limit of 1000 bytes > db.posts.ensureIndex( { coordinates: ‘2d’, friend_ids: 1 } ) Error: Key too large to index 19
  • 20. Geospatial query performance • Do we need a compound index at all? • Geospatial index is usually restrictive enough • Problem: Array traversal (using $in) is CPU hungry for large arrays • Solution: Pre-sharded array fields 20
  • 21. Pre-sharded array fields • When dealing with large arrays, i.e @BarackObama follower ids • Partition fields using pre-sharding • shard = Hash(key) MOD shard_count • Keep array sizes in the low hundreds 21
  • 22. # shard_example.rb SHARDS = 3 friend_ids = [1000 , 1001, 1002, 1003, 1004, 1005, 1006] friend_ids.each { |f| puts Zlib.crc32(f.to_s) % SHARDS } 0 2 0 2 1 2 0 { friends_0: [1000, 1002, 1006], friends_1: [1004], friends_2: [1001, 1003, 1005] } 22
  • 23. Find friend posts using pre-sharding of the friend arrays: > db.posts.find({ coordinates: { $near: [25.792627,-80.226142] }, friend_0: { $in: [1000] }) { friends_0: [1000, 1002, 1006], friends_1: [1004], friends_2: [1001, 1003, 1005] } 23
  • 24. Capped collections • Good fit for storing a feed of posts for a period of time • Eliminates need to expire old posts • Documents can’t grow • Documents can’t be deleted • Resizing collections is painful • Can’t be sharded 24
  • 25. TTL collections • We switched to TTL collections with MongoDB 2.2 • Deleting and growing documents is now possible • Easier to change expiration times • Can be sharded (not by geo) 25
  • 26. Questions 26
  • 27. Thank you! Available: fredrik@teambanjo.com iPhone and Android @fbjork