SlideShare a Scribd company logo
MongoDB Basic Concepts

                                    Norberto Leite

                            Senior Solutions Architect, EMEA
                                 norberto@10gen.com
                                         @nleite




Thursday, 25 October 12
Agenda

        •Overview
        •Replication
        •Scalability
        •Consistency & Durability
        •Flexibility, Developer Experienc




Thursday, 25 October 12
Your data needs started here...




                                   http://bit.ly/OT71M4
Thursday, 25 October 12
...but soon you had to be here




                                   http://bit.ly/Oxcsis

Thursday, 25 October 12
Basic Concepts
                            Application    Document
                                           Oriented
         High                              { author : “steve”,
                                             date : new Date(),
                                             text : “About MongoDB...”,
     Performance                             tags : [“tech”, “database”]}




                                             Fully
                                           Consistent

                   Horizontally Scalable

Thursday, 25 October 12
Tradeoff: Scale vs Functionality

                                    • memcached
        scalability & performance




                                       •key/value



                                                                     • RDBMS



                                            depth of functionality
Thursday, 25 October 12
Replication




Thursday, 25 October 12
Why do we need replication

        •Failover
        •Backups
        •Secondary batch jobs
        •High availability




Thursday, 25 October 12
Replica Sets
        Data Availability across nodes
        • Data Protection
          • Multiple copies of the data
          • Spread across Data Centers, AZs
        • High Availability
          • Automated Failover
          • Automated Recovery




Thursday, 25 October 12
Replica Sets


                 App      Write
                                   Primary
                                              Asynchronous
                          Read                 Replication

                                  Secondary
                          Read


                                  Secondary
                          Read




Thursday, 25 October 12
Replica Sets


                 App      Write
                                   Primary
                          Read

                                  Secondary
                          Read


                                  Secondary
                          Read




Thursday, 25 October 12
Replica Sets


                 App
                                   Primary

                          Write
                                   Primary    Automatic Election of
                                                  new Primary
                          Read

                                  Secondary
                          Read




Thursday, 25 October 12
Replica Sets


                 App
                                  Recovering

                          Write                New primary serves
                                   Primary            data
                          Read

                                  Secondary
                          Read




Thursday, 25 October 12
Replica Sets


                 App
                                  Secondary
                          Read

                          Write
                                   Primary
                          Read

                                  Secondary
                          Read




Thursday, 25 October 12
Scalability




Thursday, 25 October 12
Horizontal Scalability




Thursday, 25 October 12
Sharding
        Data Distribution across nodes
        • Data location transparent to your code
        • Data distribution is automatic
        • Data re-distribution is automatic
        • Aggregate system resources horizontally
        • No code changes




Thursday, 25 October 12
Sharding - Range distribution

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


                          shard01                     shard02                   shard03




Thursday, 25 October 12
Sharding - Range distribution


                          shard01   shard02   shard03

                           a-i        j-r      s-z




Thursday, 25 October 12
Sharding - Splits


                          shard01   shard02   shard03

                           a-i      ja-jz      s-z
                                     k-r




Thursday, 25 October 12
Sharding - Splits


                          shard01   shard02   shard03

                           a-i       ja-ji     s-z
                                     ji-js
                                    js-jw
                                     jz-r

Thursday, 25 October 12
Sharding - Auto Balancing


                          shard01   shard02   shard03

                           a-i       ja-ji     s-z
                                     ji-js
                          js-jw     js-jw
                                     jz-r      jz-r

Thursday, 25 October 12
Sharding - Auto Balancing


                          shard01   shard02   shard03

                           a-i       ja-ji     n-z
                                     ji-js
                          js-jw
                                               jz-r

Thursday, 25 October 12
Sharding - Routed Query
                                              find({_id: "norberto"})




                          shard01   shard02                  shard03

                           a-i       ja-ji                     n-z
                                     ji-js
                          js-jw
                                                               jz-r

Thursday, 25 October 12
Sharding - Routed Query
                                              find({_id: "norberto"})




                          shard01   shard02                  shard03

                           a-i       ja-ji                     n-z
                                     ji-js
                          js-jw
                                                               jz-r

Thursday, 25 October 12
Sharding - Scatter Gather
                                         find({email: "norberto@10gen.com"})




                          shard01   shard02                shard03

                           a-i       ja-ji                  n-z
                                     ji-js
                          js-jw
                                                            jz-r

Thursday, 25 October 12
Sharding - Scatter Gather
                                         find({email: "norberto@10gen.com"})




                          shard01   shard02                shard03

                           a-i       ja-ji                  n-z
                                     ji-js
                          js-jw
                                                            jz-r

Thursday, 25 October 12
Sharding - Caching
                       96 GB Mem
                      3:1 Data/Mem


                          shard01

                           a-i
     300 GB Data




                           j-r
                           n-z

                           300 GB



Thursday, 25 October 12
Aggregate Horizontal Resources
                       96 GB Mem      96 GB Mem      96 GB Mem
                      1:1 Data/Mem   1:1 Data/Mem   1:1 Data/Mem


                          shard01    shard02        shard03

                           a-i          j-r           n-z
     300 GB Data




                           100 GB      100 GB        100 GB


Thursday, 25 October 12
Consistency & Durability




Thursday, 25 October 12
Two choices for consistency

        •Eventual consistency
                •Allow updates when a system has been partitioned
                •Resolve conflicts later
                •Example: CouchDB, Cassandra

        •Immediate consistency
                •Limit the application of updates to a single master
                node for a given slice of data
                          •Another node can take over after a failure is detected
                •Avoids the possibility of conflicts
                •Example: MongoDB



Thursday, 25 October 12
Durability

        •For how long is my data available?
        •When do I now that my data is safe?
        •Where?
        •Mongodb style
                •Fire and Forget
                •Get Last Error
                •Journal Sync
                •Replica Safe



Thursday, 25 October 12
Data Durability




Thursday, 25 October 12
Flexibility




Thursday, 25 October 12
Data Model

        • Why JSON?
                • Provides a simple, well understood
                encapsulation of data
                • Maps simply to the object in your OO language
                • Linking & Embedding to describe relationships




Thursday, 25 October 12
Json




        place1 = {
        
 name : "10gen HQ",
        
 address : "578 Broadway 7th Floor",
        
 city : "New York",
        
   zip : "10011",
           tags : [ "business", "tech" ]
        }
Thursday, 25 October 12
Schema Design
        Relational Database




Thursday, 25 October 12
Schema Design
        MongoDB                     embedding




                          linking
Thursday, 25 October 12
Schemas in MongoDB

     Design documents that simply map to
     your application
     post = {author: "Hergé",
          date: new Date(),
          text: "Destination Moon",
          tags: ["comic", "adventure"]}

     > db.posts.save(post)


Thursday, 25 October 12
Embedding
       > db.blogs.find( { author: "Hergé"} )

         { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
           author : "Hergé",
           date : ISODate("2011-09-18T09:56:06.298Z"),
           text : "Destination Moon",
           tags : [ "comic", "adventure" ],
           comments : [
   !         {
   !       !    author : "Kyle",
   !       !    date : ISODate("2011-09-19T09:56:06.298Z"),
   !       !    text : "great book"
   !         }
           ]
         }




Thursday, 25 October 12
JSON & Scaleout

        • Embedding removes need for
                • Distributed Joins
                • Two Phase commit
        • Enables data to be distributed across many nodes
        without penalty




Thursday, 25 October 12
http://bit.ly/UmUnsU
Thursday, 25 October 12
http://bit.ly/cnP77L
Thursday, 25 October 12
http://bit.ly/ODoMhh
Thursday, 25 October 12
http://bit.ly/uW2nk
Thursday, 25 October 12
download at mongodb.org!

                                     norberto@10gen.com

                          Support, Training, Consulting, Events, Meetups
                                     http://www.10gen.com



        Facebook!                            Twitter!                     LinkedIn!
  http://bit.ly/mongofb!              http://twitter.com/mongodb!   http://linkd.in/joinmongo!




Thursday, 25 October 12

More Related Content

PPTX
Mongo db
PPT
Introduction to mongodb
PPTX
Introduction to MongoDB
PPTX
An Introduction To NoSQL & MongoDB
PPTX
Basics of MongoDB
PDF
An introduction to MongoDB
DOCX
Mongo db report
Mongo db
Introduction to mongodb
Introduction to MongoDB
An Introduction To NoSQL & MongoDB
Basics of MongoDB
An introduction to MongoDB
Mongo db report

What's hot (20)

PDF
Introduction to MongoDB
PPTX
Apache Spark Architecture
PDF
Introduction to Redis
PDF
Cassandra Introduction & Features
PDF
Get to know PostgreSQL!
PPTX
Introduction to Storm
PPTX
The Basics of MongoDB
PDF
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
PDF
RocksDB Performance and Reliability Practices
PPTX
Introduction to Redis
PPTX
NOSQL vs SQL
PPTX
Sharding Methods for MongoDB
KEY
Introduction to memcached
PPTX
Mongo DB Presentation
PDF
Linux tuning to improve PostgreSQL performance
PDF
More mastering the art of indexing
PPTX
Introduction to NoSQL Databases
PDF
Intro to HBase
PDF
Redis cluster
PDF
Introduction to MongoDB
Apache Spark Architecture
Introduction to Redis
Cassandra Introduction & Features
Get to know PostgreSQL!
Introduction to Storm
The Basics of MongoDB
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
RocksDB Performance and Reliability Practices
Introduction to Redis
NOSQL vs SQL
Sharding Methods for MongoDB
Introduction to memcached
Mongo DB Presentation
Linux tuning to improve PostgreSQL performance
More mastering the art of indexing
Introduction to NoSQL Databases
Intro to HBase
Redis cluster
Ad

Similar to MongoDB Fundamentals (20)

PDF
Morning with MongoDB Paris 2012 - MongoDB Basic Concepts
PDF
A Morning with MongoDB Barcelona: MongoDB Basic Concepts
PDF
Cloud Tech III: Actionable Metrics
PDF
Hadoop: A Hands-on Introduction
PDF
Falling in Love with Frontend Exception | Devon 2012
PPT
MongoDB Basic Concepts
PDF
Social Gaming & Gambling Summit - London Chris Anderson
PDF
Webinar: MongoDB on the JVM
PDF
Municipal Government Meets NoSQL
PDF
JavaScript: The prototype Property
PDF
Data Grids and Data Caching
PDF
Tackling Big Data with Hadoop
PDF
Distribute the workload, PHP Barcelona 2011
PDF
Dynamo concepts in depth (@pavlobaron)
PDF
Intro to NoSQL and MongoDB
PDF
Building Data Driven Products With Ruby - RubyConf 2012
PDF
GoLightly: Building VM-based language runtimes in Go
PDF
Data Grids vs Databases
PDF
Erlang for video delivery
PDF
soft-shake.ch - Data grids and Data Grids
Morning with MongoDB Paris 2012 - MongoDB Basic Concepts
A Morning with MongoDB Barcelona: MongoDB Basic Concepts
Cloud Tech III: Actionable Metrics
Hadoop: A Hands-on Introduction
Falling in Love with Frontend Exception | Devon 2012
MongoDB Basic Concepts
Social Gaming & Gambling Summit - London Chris Anderson
Webinar: MongoDB on the JVM
Municipal Government Meets NoSQL
JavaScript: The prototype Property
Data Grids and Data Caching
Tackling Big Data with Hadoop
Distribute the workload, PHP Barcelona 2011
Dynamo concepts in depth (@pavlobaron)
Intro to NoSQL and MongoDB
Building Data Driven Products With Ruby - RubyConf 2012
GoLightly: Building VM-based language runtimes in Go
Data Grids vs Databases
Erlang for video delivery
soft-shake.ch - Data grids and Data Grids
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 Client Side Encryption in MongoDB 4.2
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...
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 Client Side Encryption in MongoDB 4.2
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 Fundamentals

  • 1. MongoDB Basic Concepts Norberto Leite Senior Solutions Architect, EMEA [email protected] @nleite Thursday, 25 October 12
  • 2. Agenda •Overview •Replication •Scalability •Consistency & Durability •Flexibility, Developer Experienc Thursday, 25 October 12
  • 3. Your data needs started here... http://bit.ly/OT71M4 Thursday, 25 October 12
  • 4. ...but soon you had to be here http://bit.ly/Oxcsis Thursday, 25 October 12
  • 5. Basic Concepts Application Document Oriented High { author : “steve”, date : new Date(), text : “About MongoDB...”, Performance tags : [“tech”, “database”]} Fully Consistent Horizontally Scalable Thursday, 25 October 12
  • 6. Tradeoff: Scale vs Functionality • memcached scalability & performance •key/value • RDBMS depth of functionality Thursday, 25 October 12
  • 8. Why do we need replication •Failover •Backups •Secondary batch jobs •High availability Thursday, 25 October 12
  • 9. Replica Sets Data Availability across nodes • Data Protection • Multiple copies of the data • Spread across Data Centers, AZs • High Availability • Automated Failover • Automated Recovery Thursday, 25 October 12
  • 10. Replica Sets App Write Primary Asynchronous Read Replication Secondary Read Secondary Read Thursday, 25 October 12
  • 11. Replica Sets App Write Primary Read Secondary Read Secondary Read Thursday, 25 October 12
  • 12. Replica Sets App Primary Write Primary Automatic Election of new Primary Read Secondary Read Thursday, 25 October 12
  • 13. Replica Sets App Recovering Write New primary serves Primary data Read Secondary Read Thursday, 25 October 12
  • 14. Replica Sets App Secondary Read Write Primary Read Secondary Read Thursday, 25 October 12
  • 17. Sharding Data Distribution across nodes • Data location transparent to your code • Data distribution is automatic • Data re-distribution is automatic • Aggregate system resources horizontally • No code changes Thursday, 25 October 12
  • 18. Sharding - Range distribution sh.shardCollection("test.tweets", {_id: 1} , false) shard01 shard02 shard03 Thursday, 25 October 12
  • 19. Sharding - Range distribution shard01 shard02 shard03 a-i j-r s-z Thursday, 25 October 12
  • 20. Sharding - Splits shard01 shard02 shard03 a-i ja-jz s-z k-r Thursday, 25 October 12
  • 21. Sharding - Splits shard01 shard02 shard03 a-i ja-ji s-z ji-js js-jw jz-r Thursday, 25 October 12
  • 22. Sharding - Auto Balancing shard01 shard02 shard03 a-i ja-ji s-z ji-js js-jw js-jw jz-r jz-r Thursday, 25 October 12
  • 23. Sharding - Auto Balancing shard01 shard02 shard03 a-i ja-ji n-z ji-js js-jw jz-r Thursday, 25 October 12
  • 24. Sharding - Routed Query find({_id: "norberto"}) shard01 shard02 shard03 a-i ja-ji n-z ji-js js-jw jz-r Thursday, 25 October 12
  • 25. Sharding - Routed Query find({_id: "norberto"}) shard01 shard02 shard03 a-i ja-ji n-z ji-js js-jw jz-r Thursday, 25 October 12
  • 26. Sharding - Scatter Gather find({email: "[email protected]"}) shard01 shard02 shard03 a-i ja-ji n-z ji-js js-jw jz-r Thursday, 25 October 12
  • 27. Sharding - Scatter Gather find({email: "[email protected]"}) shard01 shard02 shard03 a-i ja-ji n-z ji-js js-jw jz-r Thursday, 25 October 12
  • 28. Sharding - Caching 96 GB Mem 3:1 Data/Mem shard01 a-i 300 GB Data j-r n-z 300 GB Thursday, 25 October 12
  • 29. Aggregate Horizontal Resources 96 GB Mem 96 GB Mem 96 GB Mem 1:1 Data/Mem 1:1 Data/Mem 1:1 Data/Mem shard01 shard02 shard03 a-i j-r n-z 300 GB Data 100 GB 100 GB 100 GB Thursday, 25 October 12
  • 31. Two choices for consistency •Eventual consistency •Allow updates when a system has been partitioned •Resolve conflicts later •Example: CouchDB, Cassandra •Immediate consistency •Limit the application of updates to a single master node for a given slice of data •Another node can take over after a failure is detected •Avoids the possibility of conflicts •Example: MongoDB Thursday, 25 October 12
  • 32. Durability •For how long is my data available? •When do I now that my data is safe? •Where? •Mongodb style •Fire and Forget •Get Last Error •Journal Sync •Replica Safe Thursday, 25 October 12
  • 35. Data Model • Why JSON? • Provides a simple, well understood encapsulation of data • Maps simply to the object in your OO language • Linking & Embedding to describe relationships Thursday, 25 October 12
  • 36. Json place1 = { name : "10gen HQ", address : "578 Broadway 7th Floor", city : "New York", zip : "10011", tags : [ "business", "tech" ] } Thursday, 25 October 12
  • 37. Schema Design Relational Database Thursday, 25 October 12
  • 38. Schema Design MongoDB embedding linking Thursday, 25 October 12
  • 39. Schemas in MongoDB Design documents that simply map to your application post = {author: "Hergé", date: new Date(), text: "Destination Moon", tags: ["comic", "adventure"]} > db.posts.save(post) Thursday, 25 October 12
  • 40. Embedding > db.blogs.find( { author: "Hergé"} ) { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "Hergé", date : ISODate("2011-09-18T09:56:06.298Z"), text : "Destination Moon", tags : [ "comic", "adventure" ], comments : [ ! { ! ! author : "Kyle", ! ! date : ISODate("2011-09-19T09:56:06.298Z"), ! ! text : "great book" ! } ] } Thursday, 25 October 12
  • 41. JSON & Scaleout • Embedding removes need for • Distributed Joins • Two Phase commit • Enables data to be distributed across many nodes without penalty Thursday, 25 October 12
  • 46. download at mongodb.org! [email protected] Support, Training, Consulting, Events, Meetups http://www.10gen.com Facebook! Twitter! LinkedIn! http://bit.ly/mongofb! http://twitter.com/mongodb! http://linkd.in/joinmongo! Thursday, 25 October 12