Schema
Design
With
MongoDB
MongoDB
Chicago Kyle
Banker
(@hwaet)
October
20,
2010 10gen
http://www.mongodb.org/
Wednesday, October 20, 2010
The
“good
kind”
of
heartbreak...
Wednesday, October 20, 2010
Wednesday, October 20, 2010
In
this
talk:
Wednesday, October 20, 2010
In
this
talk:
1.
Intro.
Principles.
Questions.
Wednesday, October 20, 2010
In
this
talk:
1.
Intro.
Principles.
Questions.
2.
Using
rich
documents
Wednesday, October 20, 2010
In
this
talk:
1.
Intro.
Principles.
Questions.
2.
Using
rich
documents
3.
Simplifying
relations
Wednesday, October 20, 2010
In
this
talk:
1.
Intro.
Principles.
Questions.
2.
Using
rich
documents
3.
Simplifying
relations
4.
Embed
vs.
Reference
Wednesday, October 20, 2010
In
this
talk:
1.
Intro.
Principles.
Questions.
2.
Using
rich
documents
3.
Simplifying
relations
4.
Embed
vs.
Reference
5.
Patterns
Wednesday, October 20, 2010
1.
MongoDB
Wednesday, October 20, 2010
Design
goals...
Wednesday, October 20, 2010
key-‐value
stores
Wednesday, October 20, 2010
key-‐value
stores
relational
databases
Wednesday, October 20, 2010
key-‐value
stores
relational
databases
Wednesday, October 20, 2010
An
analogy:
Wednesday, October 20, 2010
Raw
materials...
Wednesday, October 20, 2010
http://www.flickr.com/photos/talkephotography/3968348
Wednesday, October 20, 2010
And
our
tools...
Wednesday, October 20, 2010
http://www.flickr.com/photos/pjh/187636444/
Wednesday, October 20, 2010
And
what
we’re
building.
Wednesday, October 20, 2010
http://www.flickr.com/photos/pjh/187636444/
Wednesday, October 20, 2010
Raw
materials
Wednesday, October 20, 2010
Raw
materials
Binary
blobs
Wednesday, October 20, 2010
Raw
materials
Binary
blobs
Tables
and
rows
Wednesday, October 20, 2010
Raw
materials
Binary
blobs
Tables
and
rows
Columns
Wednesday, October 20, 2010
Raw
materials
Binary
blobs
Tables
and
rows
Columns
CSVs
Wednesday, October 20, 2010
Raw
materials
Binary
blobs
Tables
and
rows
Columns
CSVs
BSON
Documents
Wednesday, October 20, 2010
Tools
Wednesday, October 20, 2010
Tools
SQL
Wednesday, October 20, 2010
Tools
SQL
Dynamic
queries
Wednesday, October 20, 2010
Tools
SQL
Dynamic
queries
Secondary
indexes
Wednesday, October 20, 2010
Tools
SQL
Dynamic
queries
Secondary
indexes
Atomic
updates
Wednesday, October 20, 2010
Tools
SQL
Dynamic
queries
Secondary
indexes
Atomic
updates
Map-‐Reduce
Wednesday, October 20, 2010
Tools
can
change...
$or
Wednesday, October 20, 2010
What
we’re
building
Wednesday, October 20, 2010
What
we’re
building
Read-‐
or
write-‐heavy
Wednesday, October 20, 2010
What
we’re
building
Read-‐
or
write-‐heavy
Update
frequency
Wednesday, October 20, 2010
What
we’re
building
Read-‐
or
write-‐heavy
Update
frequency
Aggregation
Wednesday, October 20, 2010
2.
Rich
Documents
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
What
can
we
do
with
rich
documents?
Wednesday, October 20, 2010
Queries
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Atomic
Updates
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Map-‐Reduce
Wednesday, October 20, 2010
Rich
document
advantages:
Wednesday, October 20, 2010
Rich
document
advantages:
Holistic
representation.
Wednesday, October 20, 2010
Rich
document
advantages:
Holistic
representation.
Still
easy
to
manipulate.
Wednesday, October 20, 2010
Rich
document
advantages:
Holistic
representation.
Still
easy
to
manipulate.
Pre-‐joined
for
fast
retrieval.
Wednesday, October 20, 2010
Caveat:
Wednesday, October 20, 2010
Caveat:
Large
documents
(>
500k)
Wednesday, October 20, 2010
Caveat:
Large
documents
(>
500k)
4MB
Limit
Wednesday, October 20, 2010
3. Simplified
Relations
Wednesday, October 20, 2010
Tags
Wednesday, October 20, 2010
Tags
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Votes
Wednesday, October 20, 2010
Adding
a
vote
Wednesday, October 20, 2010
Finding
all
votes
for
a
given
user
Wednesday, October 20, 2010
4. Embed
vs.
Reference
Wednesday, October 20, 2010
1.
Embedded
Document
Wednesday, October 20, 2010
Wednesday, October 20, 2010
2.
Embedded
and
Nested
Document
Wednesday, October 20, 2010
3.
Normalized
Collection
Wednesday, October 20, 2010
Use
Cases
1.
Embedded
document
Fast
queries
Document
always
appears
w/
parent.
Wednesday, October 20, 2010
Use
Cases
1.
Embedded
document
Fast
queries
Document
always
appears
w/
parent.
2.
Embedded
&
nested
document
Complex
hierarchies
Document
appears
with
parent
Wednesday, October 20, 2010
Use
Cases
1.
Embedded
document
Fast
queries
Document
always
appears
w/
parent.
2.
Embedded
&
nested
document
Complex
hierarchies
Document
appears
with
parent
3.
Normalized
Maximum
flexibility.
Simplified
global
updates.
Wednesday, October 20, 2010
5. Patterns
Wednesday, October 20, 2010
I. Analytics
Wednesday, October 20, 2010
Use many collections
Wednesday, October 20, 2010
A pageview document
Wednesday, October 20, 2010
Upsert
Wednesday, October 20, 2010
The right index
Wednesday, October 20, 2010
Aggregate - map
Wednesday, October 20, 2010
Aggregate - reduce
Wednesday, October 20, 2010
MapReduce with filter
Wednesday, October 20, 2010
II. E-commerce
Wednesday, October 20, 2010
Products
As
rich
documents
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Products
and
Categories
Using
indexed
array
keys
Wednesday, October 20, 2010
Products
and
Categories
Wednesday, October 20, 2010
Products
and
Categories
Wednesday, October 20, 2010
Products
and
Categories
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Products
and
Categories
(Alternative)
Wednesday, October 20, 2010
Products
and
Categories
(Alternative)
Wednesday, October 20, 2010
Products
and
Categories
(Alternative)
Wednesday, October 20, 2010
Wish
lists
As
embedded
documents
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Product
reviews
Normalized,
rich
documents
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
Wednesday, October 20, 2010
6. Summary
Wednesday, October 20, 2010
Schema
Design
Wednesday, October 20, 2010
Schema
Design
1.
There’s
more
than
one
way
Wednesday, October 20, 2010
Schema
Design
1.
There’s
more
than
one
way
2.
Use
rich
documents
Wednesday, October 20, 2010
Schema
Design
1.
There’s
more
than
one
way
2.
Use
rich
documents
3.
Simplify
relations
Wednesday, October 20, 2010
Schema
Design
1.
There’s
more
than
one
way
2.
Use
rich
documents
3.
Simplify
relations
4.
Embed
vs.
Reference
Wednesday, October 20, 2010
Schema
Design
1.
There’s
more
than
one
way
2.
Use
rich
documents
3.
Simplify
relations
4.
Embed
vs.
Reference
5.
Patterns
are
emerging
Wednesday, October 20, 2010
Thank
You
http://www.mongodb.org/
Wednesday, October 20, 2010