SlideShare a Scribd company logo
Building a Mobile App!
Part 1
{ name: ‘Bryan Reinero’,
title: ‘Developer Advocate’,
twitter: ‘@blimpyacht’,
code: ‘github.com/breinero’
email: ‘bryan@mongdb.com’ }
2
Track Agenda
• Part 1: Architecture and Application Design
• Part 2: Geo-Spatial Indexing and Queries
• Part 3:Deployment Readiness
3
Mobile Applications
• Location based data
• User relevance
• Context Rich
• Social Engagement
4
The Scavenger Hunt App
Users create
scavenger hunts by
“pinning” waypoints
5
The Scavenger Hunt App
Players search for a
scavenger hunt
near their current
position
6
The Scavenger Hunt App
Basic Requirements
7
The Scavenger Hunt App
Basic Requirements
• Mark target points
8
The Scavenger Hunt App
Basic Requirements
• Mark target points
• Identify our users
9
The Scavenger Hunt App
Basic Requirements
• Mark target points
• Identify our users
• Mark users’ progress
during hunts
Schema Design
11
The Scavenger Hunt App
Users create
scavenger hunts by
“pinning” waypoints
12
Waypoint
{ _id: ObjectId(),
user: UUID,
tour: UUDI
name: "Doug's Dogs",
desc: "The best hot-dog",
clues: [
"Hungry for a Coney Island?",
"Ask for Dr. Frankenfurter",
"Look for the hot dog stand"
],
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1] }
};
13
Waypoint
{ _id: ObjectId(),
user: UUID,
tour: UUDI
name: "Doug's Dogs",
desc: "The best hot-dog",
clues: [
"Hungry for a Coney Island?",
"Ask for Dr. Frankenfurter",
"Look for the hot dog stand"
],
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1] }
};
14
Waypoint
{ _id: ObjectId(),
user: UUID,
tour: UUDI
name: "Doug's Dogs",
desc: "The best hot-dog",
clues: [
"Hungry for a Coney Island?",
"Ask for Dr. Frankenfurter",
"Look for the hot dog stand"
],
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1] }
};
Geospacial Index:
ensureIndex(
{ geometry: “2dsphere” }
)
15
Waypoint
Mobile Client
16
Waypoint
Application ServerMobile Client
RESTful Service
scavenger.com/waypoints?lat=40.87&lon=-73.87&max=100
HTTP GET
17
Waypoint
Application Server DatabaseMobile Client
RESTful Service
scavenger.com/waypoints?lat=40.87&lon=-73.87&max=100
HTTP GET
18
Waypoint
Application Server DatabaseMobile Client
RESTful Service
scavenger.com/waypoints?lat=40.87&lon=-73.87&max=100
HTTP GET
Query
{ ‘$geoNear’: {
‘$geometry’: {
type: "Point",
coordinates: [ -174.9559, 40.6544 ]
},
‘maxDistance’: 100
}
19
The Scavenger Hunt App
Basic Requirements
• Mark target points
• Identify our users
• Mark users’ progress
during hunts
20
The Checkpoint Document
{
_id: ObjectId(),
user: UUID,
huntId: UUID,
timestamp: ISODate(),
geometry: {
type: "Point",
coordinates: [ long, lat ]
}
}
21
The Scavenger Hunt App
Social Requirements
• Allow users to follow one
another
• Allow users to exchange
messages
• Send users notifications
22
Social Interactions
Eratosthenes
Democritus
Hypatia
Shemp
Euripides
23
User Collection
{
_id: UUID,
name: “Bryan Reinero’,
email: “bryan@mongodb.com”,
pass: “dontyouwishyouknew”,
description: “I am just a guy”,
followers: [
“Achille”,
“Jason”,
“Steffan”,
“Norm”
]
}
24
Social Interactions
Followers Collection
{ follower: ‘Shemp’, followed: ‘Euripides’},
{ follower:‘Shemp’, followed: ’Eratosthenes”},
{ follower: “Eratosthenes’, followed: ‘Shemp’ },
…
Eratosthenes
Democritus
Hypatia
Shemp
Euripides
25
Social Interactions
Eratosthenes
Democritus
Hypatia
Shemp
Euripides
Followers Collection
{ follower: ‘Shemp’, followed: ‘Euripides’},
{ follower:‘Shemp’, followed: ’Eratosthenes”},
{ follower: “Eratosthenes’, followed: ‘Shemp’ },
…
! (Euripides -> Shemp )
26
Social Interactions
db.followers.find( { follower:‘Shemp’ } );
Followers Collection
{ follower: ‘Shemp’, followed: ‘Euripides’},
{ follower:‘Shemp’, followed: ’Eratosthenes”},
{ follower: “Eratosthenes’, followed: ‘Shemp’ },
…
27
Notifications / Messaging
Message
{
sender: “Hypatia”,
recipients: [
“Democritus”,
“Euripides”,
“Eratosthenes”
]
date: ISODate(),
message: “truth is a point of view, and
so is changeable”
}
28
Notifications / Messaging
Message
{
sender: “Hypatia”,
recipients: [
“Democritus”,
“Euripides”,
“Eratosthenes”
]
date: ISODate(),
message: “truth is a point of view, and
so is changeable”
}
db.messages.find(
{ recipients: “Democritus”}
);
29
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
Notifications / Messaging
db.messages.find( ‘outbox.user’: ‘Hypatia’ );
db.messages.find( ‘outbox.user’: ‘Euripides’);
db.messages.find( ‘outbox.user’: ‘Democritus’);
db.messages.find( ‘outbox.user’: ‘Shemp’);
Read
30
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
Notifications / Messaging
db.messages.find( ‘outbox.user’: ‘Hypatia’ );
db.messages.find( ‘outbox.user’: ‘Euripides’);
db.messages.find( ‘outbox.user’: ‘Democritus’);
db.messages.find( ‘outbox.user’: ‘Shemp’);
Read
31
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
Notifications / Messaging
db.messages.find( ‘outbox.user’: ‘Hypatia’ );
db.messages.find( ‘outbox.user’: ‘Euripides’);
db.messages.find( ‘outbox.user’: ‘Democritus’);
db.messages.find( ‘outbox.user’: ‘Shemp’);
Read
32
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
OUTBOX
Notifications / Messaging
db.messages.find( ‘outbox.user’: ‘Hypatia’ );
db.messages.find( ‘outbox.user’: ‘Euripides’);
db.messages.find( ‘outbox.user’: ‘Democritus’);
db.messages.find( ‘outbox.user’: ‘Shemp’);
Read
33
One Document per Message per Recipient
{
sender: “Hypatia”,
recipient: “Democritus”,
date: ISODate(),
message: “truth is a point of view, and so is changeable”
}
{
sender: “Hypatia”,
recipient: “Euripides”,
date: ISODate(),
message: “truth is a point of view, and so is changeable”
}
{
sender: “Hypatia”,
recipient: “Eratosthenes”,
date: ISODate(),
message: “truth is a point of view, and so is changeable”
}
34
Inbox Buckets
Hypatia
Message
Message
Message
Hypatia
Message
Message
Message
Hypatia
Message
Message
Message
…
35
Notifications / Messaging
{user: “Hypatia”,
ctime: ISODate(),
mtime: ISODate(),
count: 10,
inbox: [
<message>,
<message>,
<message>,
…
]
}
36
Write to Bucket
function addToBucket( user, item,bucketSize )
{
var query = {
user: user,
count: { $lt: bucketSize }
};
db.notifications.update(
query,
{
$push: { messages: item },
$set: { mtime: ISODate() },
$inc: { count: 1 },
$setOnInsert: {
startDate: ISODate() }
},
{ upsert: true }
);
}
37
Write to Bucket
Parameters
• user bucket owner
• item notification message
• bucketSize limits number of messages / document
function addToBucket( user, item, bucketSize )
{
var query = {
user: user,
count: { $lt: bucketSize }
};
db.notifications.update(
query,
{
$push: { messages: item },
$set: { mtime: ISODate() },
$inc: { count: 1 },
$setOnInsert: {
startDate: ISODate() }
},
{ upsert: true }
);
}
38
Write to Bucket
Parameters
• user bucket owner
• item notification message
• bucketSize limits number of messages / document
Query
Don’t update full bucket
function addToBucket( user, item,bucketSize )
{
var query = {
user: user,
count: { $lt: bucketSize }
};
db.notifications.update(
query,
{
$push: { messages: item },
$set: { mtime: ISODate() },
$inc: { count: 1 },
$setOnInsert: {
startDate: ISODate() }
},
{ upsert: true }
);
}
39
Write to Bucket
Parameters
• user bucket owner
• item notification message
• bucketSize limits number of messages / document
Query
Don’t update full bucket
Update
• Append item to message array,
• Update the mtime with current timestamp
• Increment the size of the bucket
function addToBucket( user, item,bucketSize )
{
var query = {
user: user,
count: { $lt: bucketSize }
};
db.notifications.update(
query,
{
$push: { messages: item },
$set: { mtime: ISODate() },
$inc: { count: 1 },
$setOnInsert: {
startDate: ISODate() }
},
{ upsert: true }
);
}
40
Write to Bucket
Parameters
• user bucket owner
• item notification message
• bucketSize limits number of messages / document
Query
Don’t update full bucket
Update
• Append item to message array,
• Update the mtime with current timestamp
• Increment the size of the bucket
Upsert
Create a new bucket
function addToBucket( user, item,bucketSize )
{
var query = {
user: user,
count: { $lt: bucketSize }
};
db.notifications.update(
query,
{
$push: { messages: item },
$set: { mtime: ISODate() },
$inc: { count: 1 },
$setOnInsert: {
startDate: ISODate() }
},
{ upsert: true }
);
}
41
Personal Timeline / Hotlist
{
_id: UUID,
user: ”Democritus",
hotList" : [
{
message: "New scavenger hunt tomorrow!",
url: "http://bit.ly/1hKn9ff",
date" : ISODate()
},
{
message: "Get 50% off at Toga City",
url: "http://bit.ly/1KnlFHQ",
date: ISODate()
}
],
atime: ISODate("20150313T04:38:43.606Z")
}
42
Personal Timeline / Hotlist
Notifications of highest
user relevance
{
_id: UUID,
user: ”Democritus",
hotList" : [
{
message: "New scavenger hunt tomorrow!",
url: "http://bit.ly/1hKn9ff",
date" : ISODate()
},
{
message: "Get 50% off at Toga City",
url: "http://bit.ly/1KnlFHQ",
date: ISODate()
}
],
atime: ISODate("20150313T04:38:43.606Z")
}
43
Personal Timeline / Hotlist
db.user.update(
{"user" : "Democritus"},
{$push : { ”hotList” : {
$each : [ { <MESSAGE> } ],
$slice : -50 }
}},
false, false)
44
Production Ready Architecture
Application Servers Replica SetMobile Client
L.B.
Thanks!
{ name: ‘Bryan Reinero’,
title: ‘Developer Advocate’,
twitter: ‘@blimpyacht’,
code: ‘github.com/breinero’
email: ‘bryan@mongdb.com’ }

More Related Content

POTX
1140 p2 p04_and_1350_p2p05_and_1440_p2p06
PPTX
Powering Systems of Engagement
PPTX
Advanced Document Modeling Techniques from a High-Scale Commerce Platform
PPTX
Dev Jumpstart: Schema Design Best Practices
PPTX
MongoDB - Back to Basics - La tua prima Applicazione
PPTX
MongoDB 3.2 - Analytics
KEY
How Signpost uses MongoDB for Tracking and Analytics
PDF
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
1140 p2 p04_and_1350_p2p05_and_1440_p2p06
Powering Systems of Engagement
Advanced Document Modeling Techniques from a High-Scale Commerce Platform
Dev Jumpstart: Schema Design Best Practices
MongoDB - Back to Basics - La tua prima Applicazione
MongoDB 3.2 - Analytics
How Signpost uses MongoDB for Tracking and Analytics
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2

Similar to Mobile 1: Mobile Apps with MongoDB (20)

PPTX
Systems of engagement
PPTX
Internet of things
PPTX
Context Information Management in IoT enabled smart systems - the basics
PPTX
User Data Management with MongoDB
PDF
Montreal Elasticsearch Meetup
PPTX
Practical MongoDB
PDF
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
PPTX
Redis data modeling examples
PPTX
Building a Scalable Inbox System with MongoDB and Java
PDF
API-Entwicklung bei XING
PPTX
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
PPTX
Marc s01 e02-crud-database
PPTX
Crafting Evolvable Api Responses
PPTX
Operational Intelligence with MongoDB Webinar
PDF
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
PDF
Extensible RESTful Applications with Apache TinkerPop
PPTX
How to leverage what's new in MongoDB 3.6
KEY
Schema design
PPTX
Orion Context Broker
PPTX
S01 e01 schema-design
Systems of engagement
Internet of things
Context Information Management in IoT enabled smart systems - the basics
User Data Management with MongoDB
Montreal Elasticsearch Meetup
Practical MongoDB
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
Redis data modeling examples
Building a Scalable Inbox System with MongoDB and Java
API-Entwicklung bei XING
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Marc s01 e02-crud-database
Crafting Evolvable Api Responses
Operational Intelligence with MongoDB Webinar
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
Extensible RESTful Applications with Apache TinkerPop
How to leverage what's new in MongoDB 3.6
Schema design
Orion Context Broker
S01 e01 schema-design
Ad

More from MongoDB (20)

PDF
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
PDF
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
PDF
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
PDF
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
PDF
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
PDF
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
PDF
MongoDB SoCal 2020: MongoDB Atlas Jump Start
PDF
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
PDF
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
PDF
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
PDF
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
PDF
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
PDF
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
PDF
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
PDF
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
PDF
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
PDF
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
PDF
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
Ad

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
cuic standard and advanced reporting.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Machine Learning_overview_presentation.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Spectroscopy.pptx food analysis technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
cuic standard and advanced reporting.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine Learning_overview_presentation.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Spectral efficient network and resource selection model in 5G networks
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The AUB Centre for AI in Media Proposal.docx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Programs and apps: productivity, graphics, security and other tools
Advanced methodologies resolving dimensionality complications for autism neur...
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Assigned Numbers - 2025 - Bluetooth® Document
MYSQL Presentation for SQL database connectivity
sap open course for s4hana steps from ECC to s4
Spectroscopy.pptx food analysis technology
Building Integrated photovoltaic BIPV_UPV.pdf

Mobile 1: Mobile Apps with MongoDB

  • 1. Building a Mobile App! Part 1 { name: ‘Bryan Reinero’, title: ‘Developer Advocate’, twitter: ‘@blimpyacht’, code: ‘github.com/breinero’ email: ‘bryan@mongdb.com’ }
  • 2. 2 Track Agenda • Part 1: Architecture and Application Design • Part 2: Geo-Spatial Indexing and Queries • Part 3:Deployment Readiness
  • 3. 3 Mobile Applications • Location based data • User relevance • Context Rich • Social Engagement
  • 4. 4 The Scavenger Hunt App Users create scavenger hunts by “pinning” waypoints
  • 5. 5 The Scavenger Hunt App Players search for a scavenger hunt near their current position
  • 6. 6 The Scavenger Hunt App Basic Requirements
  • 7. 7 The Scavenger Hunt App Basic Requirements • Mark target points
  • 8. 8 The Scavenger Hunt App Basic Requirements • Mark target points • Identify our users
  • 9. 9 The Scavenger Hunt App Basic Requirements • Mark target points • Identify our users • Mark users’ progress during hunts
  • 11. 11 The Scavenger Hunt App Users create scavenger hunts by “pinning” waypoints
  • 12. 12 Waypoint { _id: ObjectId(), user: UUID, tour: UUDI name: "Doug's Dogs", desc: "The best hot-dog", clues: [ "Hungry for a Coney Island?", "Ask for Dr. Frankenfurter", "Look for the hot dog stand" ], "geometry": { "type": "Point", "coordinates": [125.6, 10.1] } };
  • 13. 13 Waypoint { _id: ObjectId(), user: UUID, tour: UUDI name: "Doug's Dogs", desc: "The best hot-dog", clues: [ "Hungry for a Coney Island?", "Ask for Dr. Frankenfurter", "Look for the hot dog stand" ], "geometry": { "type": "Point", "coordinates": [125.6, 10.1] } };
  • 14. 14 Waypoint { _id: ObjectId(), user: UUID, tour: UUDI name: "Doug's Dogs", desc: "The best hot-dog", clues: [ "Hungry for a Coney Island?", "Ask for Dr. Frankenfurter", "Look for the hot dog stand" ], "geometry": { "type": "Point", "coordinates": [125.6, 10.1] } }; Geospacial Index: ensureIndex( { geometry: “2dsphere” } )
  • 16. 16 Waypoint Application ServerMobile Client RESTful Service scavenger.com/waypoints?lat=40.87&lon=-73.87&max=100 HTTP GET
  • 17. 17 Waypoint Application Server DatabaseMobile Client RESTful Service scavenger.com/waypoints?lat=40.87&lon=-73.87&max=100 HTTP GET
  • 18. 18 Waypoint Application Server DatabaseMobile Client RESTful Service scavenger.com/waypoints?lat=40.87&lon=-73.87&max=100 HTTP GET Query { ‘$geoNear’: { ‘$geometry’: { type: "Point", coordinates: [ -174.9559, 40.6544 ] }, ‘maxDistance’: 100 }
  • 19. 19 The Scavenger Hunt App Basic Requirements • Mark target points • Identify our users • Mark users’ progress during hunts
  • 20. 20 The Checkpoint Document { _id: ObjectId(), user: UUID, huntId: UUID, timestamp: ISODate(), geometry: { type: "Point", coordinates: [ long, lat ] } }
  • 21. 21 The Scavenger Hunt App Social Requirements • Allow users to follow one another • Allow users to exchange messages • Send users notifications
  • 23. 23 User Collection { _id: UUID, name: “Bryan Reinero’, email: “bryan@mongodb.com”, pass: “dontyouwishyouknew”, description: “I am just a guy”, followers: [ “Achille”, “Jason”, “Steffan”, “Norm” ] }
  • 24. 24 Social Interactions Followers Collection { follower: ‘Shemp’, followed: ‘Euripides’}, { follower:‘Shemp’, followed: ’Eratosthenes”}, { follower: “Eratosthenes’, followed: ‘Shemp’ }, … Eratosthenes Democritus Hypatia Shemp Euripides
  • 25. 25 Social Interactions Eratosthenes Democritus Hypatia Shemp Euripides Followers Collection { follower: ‘Shemp’, followed: ‘Euripides’}, { follower:‘Shemp’, followed: ’Eratosthenes”}, { follower: “Eratosthenes’, followed: ‘Shemp’ }, … ! (Euripides -> Shemp )
  • 26. 26 Social Interactions db.followers.find( { follower:‘Shemp’ } ); Followers Collection { follower: ‘Shemp’, followed: ‘Euripides’}, { follower:‘Shemp’, followed: ’Eratosthenes”}, { follower: “Eratosthenes’, followed: ‘Shemp’ }, …
  • 27. 27 Notifications / Messaging Message { sender: “Hypatia”, recipients: [ “Democritus”, “Euripides”, “Eratosthenes” ] date: ISODate(), message: “truth is a point of view, and so is changeable” }
  • 28. 28 Notifications / Messaging Message { sender: “Hypatia”, recipients: [ “Democritus”, “Euripides”, “Eratosthenes” ] date: ISODate(), message: “truth is a point of view, and so is changeable” } db.messages.find( { recipients: “Democritus”} );
  • 29. 29 OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX Notifications / Messaging db.messages.find( ‘outbox.user’: ‘Hypatia’ ); db.messages.find( ‘outbox.user’: ‘Euripides’); db.messages.find( ‘outbox.user’: ‘Democritus’); db.messages.find( ‘outbox.user’: ‘Shemp’); Read
  • 30. 30 OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX Notifications / Messaging db.messages.find( ‘outbox.user’: ‘Hypatia’ ); db.messages.find( ‘outbox.user’: ‘Euripides’); db.messages.find( ‘outbox.user’: ‘Democritus’); db.messages.find( ‘outbox.user’: ‘Shemp’); Read
  • 31. 31 OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX Notifications / Messaging db.messages.find( ‘outbox.user’: ‘Hypatia’ ); db.messages.find( ‘outbox.user’: ‘Euripides’); db.messages.find( ‘outbox.user’: ‘Democritus’); db.messages.find( ‘outbox.user’: ‘Shemp’); Read
  • 32. 32 OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX OUTBOX Notifications / Messaging db.messages.find( ‘outbox.user’: ‘Hypatia’ ); db.messages.find( ‘outbox.user’: ‘Euripides’); db.messages.find( ‘outbox.user’: ‘Democritus’); db.messages.find( ‘outbox.user’: ‘Shemp’); Read
  • 33. 33 One Document per Message per Recipient { sender: “Hypatia”, recipient: “Democritus”, date: ISODate(), message: “truth is a point of view, and so is changeable” } { sender: “Hypatia”, recipient: “Euripides”, date: ISODate(), message: “truth is a point of view, and so is changeable” } { sender: “Hypatia”, recipient: “Eratosthenes”, date: ISODate(), message: “truth is a point of view, and so is changeable” }
  • 35. 35 Notifications / Messaging {user: “Hypatia”, ctime: ISODate(), mtime: ISODate(), count: 10, inbox: [ <message>, <message>, <message>, … ] }
  • 36. 36 Write to Bucket function addToBucket( user, item,bucketSize ) { var query = { user: user, count: { $lt: bucketSize } }; db.notifications.update( query, { $push: { messages: item }, $set: { mtime: ISODate() }, $inc: { count: 1 }, $setOnInsert: { startDate: ISODate() } }, { upsert: true } ); }
  • 37. 37 Write to Bucket Parameters • user bucket owner • item notification message • bucketSize limits number of messages / document function addToBucket( user, item, bucketSize ) { var query = { user: user, count: { $lt: bucketSize } }; db.notifications.update( query, { $push: { messages: item }, $set: { mtime: ISODate() }, $inc: { count: 1 }, $setOnInsert: { startDate: ISODate() } }, { upsert: true } ); }
  • 38. 38 Write to Bucket Parameters • user bucket owner • item notification message • bucketSize limits number of messages / document Query Don’t update full bucket function addToBucket( user, item,bucketSize ) { var query = { user: user, count: { $lt: bucketSize } }; db.notifications.update( query, { $push: { messages: item }, $set: { mtime: ISODate() }, $inc: { count: 1 }, $setOnInsert: { startDate: ISODate() } }, { upsert: true } ); }
  • 39. 39 Write to Bucket Parameters • user bucket owner • item notification message • bucketSize limits number of messages / document Query Don’t update full bucket Update • Append item to message array, • Update the mtime with current timestamp • Increment the size of the bucket function addToBucket( user, item,bucketSize ) { var query = { user: user, count: { $lt: bucketSize } }; db.notifications.update( query, { $push: { messages: item }, $set: { mtime: ISODate() }, $inc: { count: 1 }, $setOnInsert: { startDate: ISODate() } }, { upsert: true } ); }
  • 40. 40 Write to Bucket Parameters • user bucket owner • item notification message • bucketSize limits number of messages / document Query Don’t update full bucket Update • Append item to message array, • Update the mtime with current timestamp • Increment the size of the bucket Upsert Create a new bucket function addToBucket( user, item,bucketSize ) { var query = { user: user, count: { $lt: bucketSize } }; db.notifications.update( query, { $push: { messages: item }, $set: { mtime: ISODate() }, $inc: { count: 1 }, $setOnInsert: { startDate: ISODate() } }, { upsert: true } ); }
  • 41. 41 Personal Timeline / Hotlist { _id: UUID, user: ”Democritus", hotList" : [ { message: "New scavenger hunt tomorrow!", url: "http://bit.ly/1hKn9ff", date" : ISODate() }, { message: "Get 50% off at Toga City", url: "http://bit.ly/1KnlFHQ", date: ISODate() } ], atime: ISODate("20150313T04:38:43.606Z") }
  • 42. 42 Personal Timeline / Hotlist Notifications of highest user relevance { _id: UUID, user: ”Democritus", hotList" : [ { message: "New scavenger hunt tomorrow!", url: "http://bit.ly/1hKn9ff", date" : ISODate() }, { message: "Get 50% off at Toga City", url: "http://bit.ly/1KnlFHQ", date: ISODate() } ], atime: ISODate("20150313T04:38:43.606Z") }
  • 43. 43 Personal Timeline / Hotlist db.user.update( {"user" : "Democritus"}, {$push : { ”hotList” : { $each : [ { <MESSAGE> } ], $slice : -50 } }}, false, false)
  • 44. 44 Production Ready Architecture Application Servers Replica SetMobile Client L.B.
  • 45. Thanks! { name: ‘Bryan Reinero’, title: ‘Developer Advocate’, twitter: ‘@blimpyacht’, code: ‘github.com/breinero’ email: ‘bryan@mongdb.com’ }