MongoDB Basic Concepts
Transcript of MongoDB Basic Concepts
![Page 1: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/1.jpg)
MongoDB Basic Concepts
Senior Solutions Architect, 10gen
Norberto Leite
![Page 2: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/2.jpg)
2
Agenda
• Overview
• Replication
• Scalability
• Consistency & Durability
• Flexibility / Developer Experience
![Page 3: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/3.jpg)
But first ...
![Page 4: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/4.jpg)
HappyHanukkah!!!
![Page 5: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/5.jpg)
Who’s this guy?
![Page 7: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/7.jpg)
7
Norberto Leite
BarcelonaBarcelona
Senior Solutions Senior Solutions ArchitectArchitect
@nleite / [email protected]
![Page 8: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/8.jpg)
8
Norberto Leite
BarcelonaBarcelona
Love MongoDBLove MongoDB
Senior Solutions Senior Solutions ArchitectArchitect
@nleite / [email protected]
![Page 9: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/9.jpg)
9
Norberto Leite
BarcelonaBarcelona
Love MongoDBLove MongoDB
and others ...and others ...
Senior Solutions Senior Solutions ArchitectArchitect
@nleite / [email protected]
![Page 10: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/10.jpg)
Your Data
![Page 11: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/11.jpg)
![Page 12: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/12.jpg)
![Page 13: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/13.jpg)
13
Fundamentals
mongomongoDBDB
High Performance
ApplicationApplication
mongomongoDBDBmongomongoDBDB mongomongoDBDB
Horizontal Scalability
FullyConsistent
DocumentOriented{{ name: ‘Norberto Leite’,name: ‘Norberto Leite’, position: ‘SA’,position: ‘SA’, nick: ‘WingMan’,nick: ‘WingMan’, based: [‘Barcelona’, ‘London’]based: [‘Barcelona’, ‘London’]}}
![Page 14: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/14.jpg)
Replication
![Page 15: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/15.jpg)
15
Why do we need Replication?
• Failover
• Backups
• Secondary Batch Jobs
• High Availability
![Page 16: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/16.jpg)
16
Outages
• Planned – Hardware upgrade– OS or file-system tuning– Software upgrade– Relocation of data to new file-system / storage
• Un-planed– Human Error– Hardware Failure– Data Center / Region Outage– Application Corruption
![Page 17: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/17.jpg)
17
Replica Sets
• Data Protection– Multiple copies of data– Data spread across data centers, AZ’s etc
• High Availability– Automated Failover– Automated Recovery
![Page 18: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/18.jpg)
AppPrimary
Secondary
Secondary
Asynchronous Replication
Read(default)
Write
Read(optional)
Read(optional)
![Page 19: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/19.jpg)
AppPrimary
Secondary
Secondary
Failover
Read(default)
Write
Read(optional)
Read(optional)
![Page 20: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/20.jpg)
AppPrimary
Secondary
Automatic Failover
Read(default)
Write
Read(optional)
Primary
Primary Election
![Page 21: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/21.jpg)
AppRecovery
Secondary
Automatic Recovery
Read(default)
Write
Read(optional)
Primary
SecondaryRead(optional)
![Page 22: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/22.jpg)
Sharding
![Page 23: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/23.jpg)
23
Sharding
• Data Location Transparent to Code
• Data Distribution is Automatic– as well as re-distribution
• Aggregation System resources Horizontally
• No CODE Changes!!!
![Page 24: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/24.jpg)
shard01 shard02 shard03
sh.shardCollection("test.tweets", {_id: 1} , false)Range Distribution
a-i j-m n-z
![Page 25: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/25.jpg)
shard01 shard02 shard03
Chunk Split
a-i j-m n-zk-mja-jz
ki-mka-kj
![Page 26: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/26.jpg)
shard01 shard02 shard03
Auto Balancing
a-i j-m n-zja-jz
ki-mka-kjka-kjki-m
![Page 27: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/27.jpg)
shard01 shard02 shard03
Routed Queries
a-i j-m n-zja-jz
ki-m
ka-kj
db.tweets.find( {_id: ‘norberto’})
![Page 28: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/28.jpg)
shard01 shard02 shard03
Scatter Gather
a-i j-m n-zja-jz
ki-m
ka-kj
db.tweets.find( {email: ‘norberto@10gen’})
![Page 29: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/29.jpg)
shard01
a-i
j-r
n-z
300 G
B D
ata
300 GB
96 GB Mem3:1 Data/Mem
Caching
![Page 30: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/30.jpg)
shard01
a-i
300 G
B D
ata
100 GB
96 GB Mem1:1 Data/Mem
Horizontal Distribution
shard02
a-ij-r
100 GB
96 GB Mem1:1 Data/Mem
shard03
n-z
100 GB
96 GB Mem1:1 Data/Mem
![Page 31: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/31.jpg)
Consistency and Durability
![Page 32: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/32.jpg)
32
Consistency
• Eventual Consistency– Allow updates when a system as been
partitioned– Resolve conflicts later– Ex: Cassandra, CouchDB
• Immediate Consistency– Single Master– Avoids conflicts– Example: MongoDB
![Page 33: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/33.jpg)
33
Durability
• For how long is my data available?
• When do I know my data is safe?!
• Where is it safe?
• MongoDB style:– Fire and Forget– Get Last Error– Journal Sync– Replica Safe
![Page 34: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/34.jpg)
34
Durability
Memory Journal Secondary NodesMultiple Data
Centers
RDMS
j=true
Async
w=1(default)
w=majority
w=”tag”
![Page 35: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/35.jpg)
Flexibility
![Page 36: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/36.jpg)
36
Data Model
• Why Json?
– Well understood data format
– Maps simply to objects
– Linking & Embedding to describe relationships
![Page 37: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/37.jpg)
JSON
place1 = { name : "10gen HQ",address : "578 Broadway 7th Floor", city : "New York", zip : "10011", tags : [ "business", "tech" ]}
![Page 38: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/38.jpg)
Relational Way
![Page 39: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/39.jpg)
MongoDB Wayembedding
linking
![Page 40: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/40.jpg)
40
JSON & Scale Out
• Embedding removes the need for:
– Distributed Joins
– Two Phase Commit
• Enables data to be distributed across many nodes without penalty
![Page 41: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/41.jpg)
![Page 42: MongoDB Basic Concepts](https://reader036.fdocuments.in/reader036/viewer/2022070319/5583ddd6d8b42a4c3f8b4a46/html5/thumbnails/42.jpg)