mongodb basic concepts

42
MongoDB Basic Concepts Senior Solutions Architect, 10gen Norberto Leite

Upload: mongodb

Post on 19-Jun-2015

7.023 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MongoDB Basic Concepts

MongoDB Basic Concepts

Senior Solutions Architect, 10gen

Norberto Leite

Page 2: MongoDB Basic Concepts

2

Agenda

• Overview

• Replication

• Scalability

• Consistency & Durability

• Flexibility / Developer Experience

Page 3: MongoDB Basic Concepts

But first ...

Page 4: MongoDB Basic Concepts

HappyHanukkah!!!

Page 5: MongoDB Basic Concepts

Who’s this guy?

Page 6: MongoDB Basic Concepts

6

Norberto Leite

Senior Solutions ArchitectSenior Solutions Architect

@nleite / [email protected]

Page 7: MongoDB Basic Concepts

7

Norberto Leite

BarcelonaBarcelona

Senior Solutions Senior Solutions ArchitectArchitect

@nleite / [email protected]

Page 8: MongoDB Basic Concepts

8

Norberto Leite

BarcelonaBarcelona

Love MongoDBLove MongoDB

Senior Solutions Senior Solutions ArchitectArchitect

@nleite / [email protected]

Page 9: MongoDB Basic Concepts

9

Norberto Leite

BarcelonaBarcelona

Love MongoDBLove MongoDB

and others ...and others ...

Senior Solutions Senior Solutions ArchitectArchitect

@nleite / [email protected]

Page 10: MongoDB Basic Concepts

Your Data

Page 11: MongoDB Basic Concepts
Page 12: MongoDB Basic Concepts
Page 13: MongoDB Basic Concepts

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

Replication

Page 15: MongoDB Basic Concepts

15

Why do we need Replication?

• Failover

• Backups

• Secondary Batch Jobs

• High Availability

Page 16: MongoDB Basic Concepts

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

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

AppPrimary

Secondary

Secondary

Asynchronous Replication

Read(default)

Write

Read(optional)

Read(optional)

Page 19: MongoDB Basic Concepts

AppPrimary

Secondary

Secondary

Failover

Read(default)

Write

Read(optional)

Read(optional)

Page 20: MongoDB Basic Concepts

AppPrimary

Secondary

Automatic Failover

Read(default)

Write

Read(optional)

Primary

Primary Election

Page 21: MongoDB Basic Concepts

AppRecovery

Secondary

Automatic Recovery

Read(default)

Write

Read(optional)

Primary

SecondaryRead(optional)

Page 22: MongoDB Basic Concepts

Sharding

Page 23: MongoDB Basic Concepts

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

shard01 shard02 shard03

sh.shardCollection("test.tweets", {_id: 1} , false)Range Distribution

a-i j-m n-z

Page 25: MongoDB Basic Concepts

shard01 shard02 shard03

Chunk Split

a-i j-m n-zk-mja-jz

ki-mka-kj

Page 26: MongoDB Basic Concepts

shard01 shard02 shard03

Auto Balancing

a-i j-m n-zja-jz

ki-mka-kjka-kjki-m

Page 27: MongoDB Basic Concepts

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

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

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

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

Consistency and Durability

Page 32: MongoDB Basic Concepts

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

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

34

Durability

Memory Journal Secondary NodesMultiple Data

Centers

RDMS

j=true

Async

w=1(default)

w=majority

w=”tag”

Page 35: MongoDB Basic Concepts

Flexibility

Page 36: MongoDB Basic Concepts

36

Data Model

• Why Json?

– Well understood data format

– Maps simply to objects

– Linking & Embedding to describe relationships

Page 37: MongoDB Basic Concepts

JSON

place1 = { name : "10gen HQ",address : "578 Broadway 7th Floor", city : "New York", zip : "10011", tags : [ "business", "tech" ]}

Page 38: MongoDB Basic Concepts

Relational Way

Page 39: MongoDB Basic Concepts

MongoDB Wayembedding

linking

Page 40: MongoDB Basic Concepts

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
Page 42: MongoDB Basic Concepts