SlideShare une entreprise Scribd logo
1  sur  54
MongoDB at Visibiz

Why and How We’re Using MongoDB In Our Application



                  Mike Brocious
                    Tech Lead
                   Visibiz, Inc.
Why We’re Here


•   Discuss why we chose MongoDB at Visibiz

•   Show how we’re using it

•   Made mistakes Learned along the way

•   Collections

•   Schema
About Us
•   Startup

•   Founded April, 2010

•   8 employees

•   Located just outside of Philadelphia, PA

•   Social CRM

        •   ‘know your net work...sell better’

•   Currently in limited beta

    •   Sign up at www.visibiz.com
Physical
                    Apache
Components

                     Tomcat
                        -
                Grails application


                                     Elastic
      MongoDB
                                     Search


                      Unix

                Amazon EC2
How Did We Get To MongoDB?
Application Requirements


•   Application requirements for extensibility

      •   customer extensible objects

      •   customer definable objects



•   Scalability
Extensible Objects
Extensible Objects

•   We provide core objects

      •   person, company, prospect, relationship, etc.
Extensible Objects

•   We provide core objects

        •   person, company, prospect, relationship, etc.

•   Customer can add their own attributes

    •   including relationships with other objects

•   A ‘person’ object for customer #1 may not be defined like a
    ‘person’ object for customer #2
CUSTOMER #1                                CUSTOMER #2
•   Person                                          •   Person
    •   name                                            •   name
    •   address             <= Core Attributes =>       •   address
    •   date of birth                                   •   date of birth
    •   employment history                              •   gender
        •   list:           <= Customer Defined =>
                                                        •   hobbies
            •   company            Attributes               •   list:
            •   begin date                                      •   name
            •   end date
            •   job title
Customer Definable Objects



•   Give customers ability to define their own objects

      •   collection of attribute names, types

      •   relationships with other objects
Scalability

•   Will eventually have large amount of data

    •   social net works, blogs, articles, etc.

    •   email



•   Scaling should be (relatively) easy
What We Liked About MongoDB
What We Liked About MongoDB


•   Document datastore

      •   easy to understand, visualize objects

      •   cmd shell, log files, debuggers, viewers
What We Liked About MongoDB


•   Document datastore

      •   easy to understand, visualize objects

      •   cmd shell, log files, debuggers, viewers


•   Dynamic schemas (“schema-free”)

      •   fit well with our extensibility requirements
Schema Flexibility Comparison



•   Relational vs. document-based



•   Support extensible ‘person’ object
Relational Database Example

                                                                               Date of
        Person Id                     Name                Address
                                                                                Birth

             1                    Mike Brocious         Malvern, PA           6/10/1984

             2                     Doug Smith         Philadelphia, PA        2/24/1980



Person Id        User Defined 1     User Defined 2   User Defined 3   User Defined 4      ...

    1             Good Burger         3/20/1998        3/31/2010          Flipper

    1               Visibiz            4/1/2010          <null>          Tech Lead

    2                10gen             7/9/2006        3/18/2009         Engineer



    Column               Name             Type
User Defined 1         Company           String
User Defined 2        Begin Date          Date
User Defined 3         End Date           Date
User Defined 4        Job Title          String
Document Datastore Example
{
    "_id" : ObjectId("4d87a4d32739a23b3c834b67"),
    "name" : "Mike Brocious",
    "address" : "Malvern, PA",
    "dateOfBirth" : "Sun Jun 10 1984 00:00:00 GMT-0400 (EDT)",
    "employmentHistory" : [
       {
           "company" : "Good Burger",
           "beginDate" : "Sun Mar 20 1998 00:00:00 GMT-0400 (EDT)",
           "endDate" : "Thu Mar 31 2010 00:00:00 GMT-0400 (EDT)",
           "jobTitle" : "Flipper"
       },
       {
           "company" : "Visibiz",
           "beginDate" : "Fri Apr 01 2010 00:00:00 GMT-0400 (EDT)",
           "jobTitle" : "Engineer"
       }
    ]
}
Document Datastore Example
{
     "_id" : ObjectId("4d87a4d32739a23b3c834b67"),
     "name" : "Mike Brocious",
     "address" : "Malvern, PA",
     "dateOfBirth" : "Sun Jun 10 1984 00:00:00 GMT-0400 (EDT)",
     "employmentHistory" : [
        {
            "company" : "Good Burger",
            "beginDate" : "Sun Mar 20 1998 00:00:00 GMT-0400 (EDT)",
            "endDate" : "Thu Mar 31 2010 00:00:00 GMT-0400 (EDT)",
            "jobTitle" : "Flipper"
        },
        {
            "company" : "Visibiz",
            "beginDate" : "Fri Apr 01 2010 00:00:00 GMT-0400 (EDT)",
            "jobTitle" : "Engineer"
        }
     ]
}

{
    "_id": ObjectId("4d87a9732739a23b3c834b6d"),
    "name": "Julie Harper",
    "address": "Ocean City, NJ",
    "dateOfBirth": "Thu Sep 22 1994 00:00:00 GMT-0400 (EDT)",
    "gender": "F",
    "hobbies": [
        "painting",
        "skateboarding",
        "reading",
        "cooking"
    ]
}
More MongoDB Goodness
More MongoDB Goodness

•   Scalability

    •   replication - easy to setup

    •   sharding
More MongoDB Goodness

•   Scalability

    •   replication - easy to setup

    •   sharding

•   Uses JSON

    •   “the new XML”

    •   easy to build, parse and read

    •   great support from tools, languages and ser vices
JSON

•   JSON * (MongoDB + Groovy + Grails + JavaScript) == LOVE



•   MongoDB == BSON/JSON

•   Groovy == Map

•   Grails == JSON converter/builder

•   JavaScript = Well...it’s the JS in JSON
JSON-eze

•   Every layer of the application understands common format


                                                 Presentation
•   Not forced into transforming data
                                                     View
    •   DB result sets <--> DO/DTO          J
                                            S     Controller
    •   DO/DTO <--> view                    O      Services
    •   view <--> presentation              N
                                                 Data Access
•   Enables rapid development                         DB
What Else We Liked About MongoDB

•   Active product development

•   Community support

    •   plugins, drivers, viewers

•   10gen support

    •   developers very active on forum, JIRA

    •   MongoDB conferences, webcasts

•   Deep list of sites already using MongoDB
Be Aware Of...
Be Aware Of...

•   No transactions

    •   mitigation: schema design + atomic document updates



•   No really complex queries (JOINs, nested SELECTs)

    •   mitigation: schema design



•   Felt we could minimize the impact
•   OK, so that’s WHY



•   Let’s get into the HOW
Application
    Layers                      Browser



                               Controller
                      Application Svcs (bus. logic)
    Home-grown
                                                      Light weight object-
convenience wrapper   MongoService          Morphia     mapping library
 around Java driver
                         MongoDB Java driver



                               MongoDB
Our Primary Collections



•   Things



•   Rels
Things



•   Our main collection: “things”



•   Domain objects (person, company, note, event, etc.)

•   Customer-defined objects

•   Takes advantage of ‘s chema-free’ nature of MongoDB

    •   able to easily query across all types
‘Person’ Thing
{   "_id" : ObjectId("4d10f60f39fe153be3316478"),
    "thingType" : "person",
    "name" : {
         "firstName" : "Gail",
         "lastName" : "Staudt"
    },
    "owner" : ObjectId("4d10f47e39fe153b552e6478"),
    "createdDate" : "Tue Dec 21 2010 13:46:39 GMT-0500 (EST)",
    "tags" : [
         {
             "tag" : "java",
             "score" : 2
         },
         {
             "tag" : "clojure",
             "score" : 2
         }
    ],
    "addresses" : [
         {
             "addr1" : "40 Lloyd Ave",
             "city" : "Malvern",
             "state" : "PA"
         }
    ],
    "emailAddresses" : [
         {
             "type" : "work",
             "value" : "staudt@foo.com"
         }
    ]
}
‘Company’ Thing
{
    "_id" : ObjectId("4d10ffe939fe153b193b6478"),
    "thingType" : "company",
    "name" : "We Be Coders, Inc."
    "owner" : ObjectId("4d10f60e39fe153b20316478"),
    "createdDate" : "Tue Dec 21 2010 14:28:41 GMT-0500 (EST)",
    "primaryBusiness" : "Software development consulting"
    "tags" : [
         {
             "tag" : "software",
             "score" : 2
         },
         {
             "tag" : "development",
             "score" : 7
         },
         {
             "tag" : "clojure",
             "score" : 3
         },
         {
             "tag" : "java",
             "score" : 5
         }
    ]
}
‘Company’ Thing
    {
        "_id" : ObjectId("4d10ffe939fe153b193b6478"),
        "thingType" : "company",
        "name" : "We Be Coders, Inc."
        "owner" : ObjectId("4d10f60e39fe153b20316478"),
        "createdDate" : "Tue Dec 21 2010 14:28:41 GMT-0500 (EST)",
        "primaryBusiness" : "Software development consulting"
        "tags" : [
             {
                 "tag" : "software",
                 "score" : 2
             },
             {
                 "tag" : "development",
                 "score" : 7
             },
             {
                 "tag" : "clojure",
                 "score" : 3
             },
             {
                 "tag" : "java",
                 "score" : 5
             }
        ]
    }


•   Find all things I own tagged with ‘java’
> db.things.find({owner: ObjectId(“4d10f60e39fe153b20316478”),
                  tags.tag: “java”})
Relationships - Act One

•   Connections bet ween things

    •   employment history

    •   co-workers, friends
Relationships - Act One

•   Connections bet ween things

    •   employment history

    •   co-workers, friends




•   First cut: separate documents in the things collection

    •   essentially a mapping/join table
Relationships - Act One


A             rel             B
Relationships - Act One


           A                rel              B



•   Single atomic insert (good! no transaction concerns)



•   Made retrieval inefficient (no JOINs, nested SELECTs)
Relationships - Act One

Find all things I’m related to
me = ObjectId(“4d10f60e39fe153b20316478”)

// Get all the relationships I’m involved in
related = db.things.find({$or: [left.id: me,
                                right.id:me]})

// Build up a list of ids I’m related to
i = 0
relatedId = new Array()
for(relationship in related)
  if (relationship.left.id == me) {
       relatedIds[i++] = relationship.right.id
  } else {
      relatedIds[i++] = relationship.left.id
  }
)

// Now get the things
relatedThings = db.things.find({_id: { $in : relatedIds } })
Relationships - Act Two

•   Moved relationships to nested document inside thing

    •   natural approach for document-based datastores



                 A                                B
Relationships - Act Two

•   Queries easy and fast - awesome!
    // Get all the things I’m related to
    relatedThings = db.things.find({$or: [rels.left.id: me,
                                          rels.right.id:me]})
Relationships - Act Two

•   Queries easy and fast - awesome!
    // Get all the things I’m related to
    relatedThings = db.things.find({$or: [rels.left.id: me,
                                          rels.right.id:me]})



•   Two updates required to insert new relationship

    •   relationship stored in both things

    •   bad! - transaction concerns
Relationships - Act Three (final?)
•   Best of both worlds
Relationships - Act Three (final?)
•   Best of both worlds

•   Separate “rels” collection
                                                A   rel   B
    •   master source of relationship details

    •   atomic insert (good!)

    •   unique index (good!)
Relationships - Act Three (final?)
•       Best of both worlds

•       Separate “rels” collection
                                                        A   rel   B
        •       master source of relationship details

        •       atomic insert (good!)

        •       unique index (good!)

    •   Nested “rels” documents in things
                                                        A         B
            •   easy, fast queries (good!)
Relationships - Act Three (final?)
•       Best of both worlds                                 insert / delete

•       Separate “rels” collection
                                                        A        rel          B
        •       master source of relationship details

        •       atomic insert (good!)

        •       unique index (good!)

    •   Nested “rels” documents in things
                                                        A                     B
            •   easy, fast queries (good!)
Relationships - Act Three (final?)
•       Best of both worlds                                 insert / delete

•       Separate “rels” collection
                                                        A        rel          B
        •       master source of relationship details

        •       atomic insert (good!)

        •       unique index (good!)

    •   Nested “rels” documents in things
                                                        A                     B
            •   easy, fast queries (good!)
Other MongoDB Collections


•   Workflow status log

•   Query log

•   Staging area for imported data

•   Users

•   Duplicates scan log
REST

•   RESTful interface on top of ser vices

•   Expose services for internal and
    external development (API)
REST

    •       RESTful interface on top of ser vices

    •       Expose services for internal and
            external development (API)



•       MongoDB doesn’t enforce datatypes or object shape

•       Need a way to validate data to prevent “garbage in”

•       JSON schema

        •    http://json-schema.org/
person = [
                          Person Schema
    name: "person",
    type: "object",
    extends: "contact",

   properties: [
       name: [type: "object",
              title: "Name",
              properties: [
                  firstName: [type: "string",
                                title: "First Name",
                                optional:true],
                  middleName: [type: "string",
                                title: "Middle Name",
                                optional: true],
                  lastName:    [type: "string",
                                title: "Last Name",
                                optional: true],
                  suffix: [type: "string",
                            title: "Suffix",
                            optional: true]]]]]
Thing Schemas

•   Separate “schemas” MongoDB collection

•   Every “thing” passes through validation before being stored



•   Uses:

      •   validate incoming data

      •   track customer-specific schema extensions

      •   generate UI to display things
Why MongoDB Works For Us

•   Schema-free

•   Document-oriented

•   JSON

•   Scalable

•   Active product
                          “MongoDB...The Database Chuck Norris Uses”
•   Free
Questions?

Contenu connexe

Similaire à mongoDB at Visibiz

OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB Tutorial
Steven Francia
 
MongoDB in FS
MongoDB in FSMongoDB in FS
MongoDB in FS
MongoDB
 
Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentation
Murat Çakal
 

Similaire à mongoDB at Visibiz (20)

Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
MongoDB for Genealogy
MongoDB for GenealogyMongoDB for Genealogy
MongoDB for Genealogy
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB Tutorial
 
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentosConceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
Learn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBLearn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDB
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyOSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
 
Building your first app with mongo db
Building your first app with mongo dbBuilding your first app with mongo db
Building your first app with mongo db
 
MongoDB in FS
MongoDB in FSMongoDB in FS
MongoDB in FS
 
MongoDB Basics
MongoDB BasicsMongoDB Basics
MongoDB Basics
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
Webinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDBWebinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDB
 
Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentation
 
MongoDB
MongoDBMongoDB
MongoDB
 
Schema Design by Example ~ MongoSF 2012
Schema Design by Example ~ MongoSF 2012Schema Design by Example ~ MongoSF 2012
Schema Design by Example ~ MongoSF 2012
 
Using MongoDB + Hadoop Together
Using MongoDB + Hadoop TogetherUsing MongoDB + Hadoop Together
Using MongoDB + Hadoop Together
 
Crafting Evolvable Api Responses
Crafting Evolvable Api ResponsesCrafting Evolvable Api Responses
Crafting Evolvable Api Responses
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

mongoDB at Visibiz

  • 1. MongoDB at Visibiz Why and How We’re Using MongoDB In Our Application Mike Brocious Tech Lead Visibiz, Inc.
  • 2. Why We’re Here • Discuss why we chose MongoDB at Visibiz • Show how we’re using it • Made mistakes Learned along the way • Collections • Schema
  • 3. About Us • Startup • Founded April, 2010 • 8 employees • Located just outside of Philadelphia, PA • Social CRM • ‘know your net work...sell better’ • Currently in limited beta • Sign up at www.visibiz.com
  • 4. Physical Apache Components Tomcat - Grails application Elastic MongoDB Search Unix Amazon EC2
  • 5. How Did We Get To MongoDB?
  • 6. Application Requirements • Application requirements for extensibility • customer extensible objects • customer definable objects • Scalability
  • 8. Extensible Objects • We provide core objects • person, company, prospect, relationship, etc.
  • 9. Extensible Objects • We provide core objects • person, company, prospect, relationship, etc. • Customer can add their own attributes • including relationships with other objects • A ‘person’ object for customer #1 may not be defined like a ‘person’ object for customer #2
  • 10. CUSTOMER #1 CUSTOMER #2 • Person • Person • name • name • address <= Core Attributes => • address • date of birth • date of birth • employment history • gender • list: <= Customer Defined => • hobbies • company Attributes • list: • begin date • name • end date • job title
  • 11. Customer Definable Objects • Give customers ability to define their own objects • collection of attribute names, types • relationships with other objects
  • 12. Scalability • Will eventually have large amount of data • social net works, blogs, articles, etc. • email • Scaling should be (relatively) easy
  • 13. What We Liked About MongoDB
  • 14. What We Liked About MongoDB • Document datastore • easy to understand, visualize objects • cmd shell, log files, debuggers, viewers
  • 15. What We Liked About MongoDB • Document datastore • easy to understand, visualize objects • cmd shell, log files, debuggers, viewers • Dynamic schemas (“schema-free”) • fit well with our extensibility requirements
  • 16. Schema Flexibility Comparison • Relational vs. document-based • Support extensible ‘person’ object
  • 17. Relational Database Example Date of Person Id Name Address Birth 1 Mike Brocious Malvern, PA 6/10/1984 2 Doug Smith Philadelphia, PA 2/24/1980 Person Id User Defined 1 User Defined 2 User Defined 3 User Defined 4 ... 1 Good Burger 3/20/1998 3/31/2010 Flipper 1 Visibiz 4/1/2010 <null> Tech Lead 2 10gen 7/9/2006 3/18/2009 Engineer Column Name Type User Defined 1 Company String User Defined 2 Begin Date Date User Defined 3 End Date Date User Defined 4 Job Title String
  • 18. Document Datastore Example { "_id" : ObjectId("4d87a4d32739a23b3c834b67"), "name" : "Mike Brocious", "address" : "Malvern, PA", "dateOfBirth" : "Sun Jun 10 1984 00:00:00 GMT-0400 (EDT)", "employmentHistory" : [ { "company" : "Good Burger", "beginDate" : "Sun Mar 20 1998 00:00:00 GMT-0400 (EDT)", "endDate" : "Thu Mar 31 2010 00:00:00 GMT-0400 (EDT)", "jobTitle" : "Flipper" }, { "company" : "Visibiz", "beginDate" : "Fri Apr 01 2010 00:00:00 GMT-0400 (EDT)", "jobTitle" : "Engineer" } ] }
  • 19. Document Datastore Example { "_id" : ObjectId("4d87a4d32739a23b3c834b67"), "name" : "Mike Brocious", "address" : "Malvern, PA", "dateOfBirth" : "Sun Jun 10 1984 00:00:00 GMT-0400 (EDT)", "employmentHistory" : [ { "company" : "Good Burger", "beginDate" : "Sun Mar 20 1998 00:00:00 GMT-0400 (EDT)", "endDate" : "Thu Mar 31 2010 00:00:00 GMT-0400 (EDT)", "jobTitle" : "Flipper" }, { "company" : "Visibiz", "beginDate" : "Fri Apr 01 2010 00:00:00 GMT-0400 (EDT)", "jobTitle" : "Engineer" } ] } { "_id": ObjectId("4d87a9732739a23b3c834b6d"), "name": "Julie Harper", "address": "Ocean City, NJ", "dateOfBirth": "Thu Sep 22 1994 00:00:00 GMT-0400 (EDT)", "gender": "F", "hobbies": [ "painting", "skateboarding", "reading", "cooking" ] }
  • 21. More MongoDB Goodness • Scalability • replication - easy to setup • sharding
  • 22. More MongoDB Goodness • Scalability • replication - easy to setup • sharding • Uses JSON • “the new XML” • easy to build, parse and read • great support from tools, languages and ser vices
  • 23. JSON • JSON * (MongoDB + Groovy + Grails + JavaScript) == LOVE • MongoDB == BSON/JSON • Groovy == Map • Grails == JSON converter/builder • JavaScript = Well...it’s the JS in JSON
  • 24. JSON-eze • Every layer of the application understands common format Presentation • Not forced into transforming data View • DB result sets <--> DO/DTO J S Controller • DO/DTO <--> view O Services • view <--> presentation N Data Access • Enables rapid development DB
  • 25. What Else We Liked About MongoDB • Active product development • Community support • plugins, drivers, viewers • 10gen support • developers very active on forum, JIRA • MongoDB conferences, webcasts • Deep list of sites already using MongoDB
  • 27. Be Aware Of... • No transactions • mitigation: schema design + atomic document updates • No really complex queries (JOINs, nested SELECTs) • mitigation: schema design • Felt we could minimize the impact
  • 28. OK, so that’s WHY • Let’s get into the HOW
  • 29. Application Layers Browser Controller Application Svcs (bus. logic) Home-grown Light weight object- convenience wrapper MongoService Morphia mapping library around Java driver MongoDB Java driver MongoDB
  • 30. Our Primary Collections • Things • Rels
  • 31. Things • Our main collection: “things” • Domain objects (person, company, note, event, etc.) • Customer-defined objects • Takes advantage of ‘s chema-free’ nature of MongoDB • able to easily query across all types
  • 32. ‘Person’ Thing { "_id" : ObjectId("4d10f60f39fe153be3316478"), "thingType" : "person", "name" : { "firstName" : "Gail", "lastName" : "Staudt" }, "owner" : ObjectId("4d10f47e39fe153b552e6478"), "createdDate" : "Tue Dec 21 2010 13:46:39 GMT-0500 (EST)", "tags" : [ { "tag" : "java", "score" : 2 }, { "tag" : "clojure", "score" : 2 } ], "addresses" : [ { "addr1" : "40 Lloyd Ave", "city" : "Malvern", "state" : "PA" } ], "emailAddresses" : [ { "type" : "work", "value" : "staudt@foo.com" } ] }
  • 33. ‘Company’ Thing { "_id" : ObjectId("4d10ffe939fe153b193b6478"), "thingType" : "company", "name" : "We Be Coders, Inc." "owner" : ObjectId("4d10f60e39fe153b20316478"), "createdDate" : "Tue Dec 21 2010 14:28:41 GMT-0500 (EST)", "primaryBusiness" : "Software development consulting" "tags" : [ { "tag" : "software", "score" : 2 }, { "tag" : "development", "score" : 7 }, { "tag" : "clojure", "score" : 3 }, { "tag" : "java", "score" : 5 } ] }
  • 34. ‘Company’ Thing { "_id" : ObjectId("4d10ffe939fe153b193b6478"), "thingType" : "company", "name" : "We Be Coders, Inc." "owner" : ObjectId("4d10f60e39fe153b20316478"), "createdDate" : "Tue Dec 21 2010 14:28:41 GMT-0500 (EST)", "primaryBusiness" : "Software development consulting" "tags" : [ { "tag" : "software", "score" : 2 }, { "tag" : "development", "score" : 7 }, { "tag" : "clojure", "score" : 3 }, { "tag" : "java", "score" : 5 } ] } • Find all things I own tagged with ‘java’ > db.things.find({owner: ObjectId(“4d10f60e39fe153b20316478”), tags.tag: “java”})
  • 35. Relationships - Act One • Connections bet ween things • employment history • co-workers, friends
  • 36. Relationships - Act One • Connections bet ween things • employment history • co-workers, friends • First cut: separate documents in the things collection • essentially a mapping/join table
  • 37. Relationships - Act One A rel B
  • 38. Relationships - Act One A rel B • Single atomic insert (good! no transaction concerns) • Made retrieval inefficient (no JOINs, nested SELECTs)
  • 39. Relationships - Act One Find all things I’m related to me = ObjectId(“4d10f60e39fe153b20316478”) // Get all the relationships I’m involved in related = db.things.find({$or: [left.id: me, right.id:me]}) // Build up a list of ids I’m related to i = 0 relatedId = new Array() for(relationship in related) if (relationship.left.id == me) { relatedIds[i++] = relationship.right.id } else { relatedIds[i++] = relationship.left.id } ) // Now get the things relatedThings = db.things.find({_id: { $in : relatedIds } })
  • 40. Relationships - Act Two • Moved relationships to nested document inside thing • natural approach for document-based datastores A B
  • 41. Relationships - Act Two • Queries easy and fast - awesome! // Get all the things I’m related to relatedThings = db.things.find({$or: [rels.left.id: me, rels.right.id:me]})
  • 42. Relationships - Act Two • Queries easy and fast - awesome! // Get all the things I’m related to relatedThings = db.things.find({$or: [rels.left.id: me, rels.right.id:me]}) • Two updates required to insert new relationship • relationship stored in both things • bad! - transaction concerns
  • 43. Relationships - Act Three (final?) • Best of both worlds
  • 44. Relationships - Act Three (final?) • Best of both worlds • Separate “rels” collection A rel B • master source of relationship details • atomic insert (good!) • unique index (good!)
  • 45. Relationships - Act Three (final?) • Best of both worlds • Separate “rels” collection A rel B • master source of relationship details • atomic insert (good!) • unique index (good!) • Nested “rels” documents in things A B • easy, fast queries (good!)
  • 46. Relationships - Act Three (final?) • Best of both worlds insert / delete • Separate “rels” collection A rel B • master source of relationship details • atomic insert (good!) • unique index (good!) • Nested “rels” documents in things A B • easy, fast queries (good!)
  • 47. Relationships - Act Three (final?) • Best of both worlds insert / delete • Separate “rels” collection A rel B • master source of relationship details • atomic insert (good!) • unique index (good!) • Nested “rels” documents in things A B • easy, fast queries (good!)
  • 48. Other MongoDB Collections • Workflow status log • Query log • Staging area for imported data • Users • Duplicates scan log
  • 49. REST • RESTful interface on top of ser vices • Expose services for internal and external development (API)
  • 50. REST • RESTful interface on top of ser vices • Expose services for internal and external development (API) • MongoDB doesn’t enforce datatypes or object shape • Need a way to validate data to prevent “garbage in” • JSON schema • http://json-schema.org/
  • 51. person = [ Person Schema name: "person", type: "object", extends: "contact", properties: [ name: [type: "object", title: "Name", properties: [ firstName: [type: "string", title: "First Name", optional:true], middleName: [type: "string", title: "Middle Name", optional: true], lastName: [type: "string", title: "Last Name", optional: true], suffix: [type: "string", title: "Suffix", optional: true]]]]]
  • 52. Thing Schemas • Separate “schemas” MongoDB collection • Every “thing” passes through validation before being stored • Uses: • validate incoming data • track customer-specific schema extensions • generate UI to display things
  • 53. Why MongoDB Works For Us • Schema-free • Document-oriented • JSON • Scalable • Active product “MongoDB...The Database Chuck Norris Uses” • Free

Notes de l'éditeur

  1. thanks for joining us today, i am mike brocious, tech lead here at visibiz, and \ni&amp;#x2019;m gonna take you through a brief discussion of why we chose mongodb and how it fits into our application\n\nTurn off all message notifications\n- tweet deck\n- gmail\n- skype\n\n
  2. why we chose mongo as primary datastore\n\nNot a sales pitch - Can&amp;#x2019;t tell you whether it&amp;#x2019;s right for you\n\nHow we&amp;#x2019;ve fit it into our architecture\n\n
  3. startup\nbeen around about a year\n\nour application is in the social CRM market space - take traditional CRM features, throw in social networks, email and some intelligence...we help you understand your network of contacts, and prospects to help you during the sales cycle\n\n\n
  4. a little more context about the application we&amp;#x2019;re developing it in the Grails framework from SpringSource\nso grails application hosted inside of tomcat, front-ended by apache with mongo, recently added elastic search as search engine\nall hosted in the amazon ec2 cloud\n
  5. a lot factors went into the decision, but there are two worth noting here\n-we want our customers to be able to extend the core domain objects\n we also want them to be able to define their own domain objects and plug them into our application\n-the other point is scalability....important to us that our datastore be prepared to scale up and scale out as necessary\n\n
  6. so lets talk a little more about extensibility\nwe provide core objects with a set of attributes\nto help customers to fit our application into their own workflow, we want customers to be able to extend those objects with their own attributes\nso what this means is that a person object ........\n
  7. C#1 is interested in tracking the employment history of people that are in the network\nC#2 need to know are they male or female and what they do in their spare time, what are their interests, what are their hobbies\n\nthose attributes add meaning for those customers based on their workflow, their marketspace, their targets\nobviously a trivial example, but it&amp;#x2019;s meant to give you a feeling for what we want to want to be able to offer in our application\n
  8. no real business logic, just the ability to store, associate and retrieve their own objects\n\n
  9. Second concern that i mentioned earlier\nWanted to make sure that the datastore that we chose was designed with scalability in mind\nI mentioned that our application is dealing with social networks. as most of you are probably a member of one or more networks, be it twitter, facebook, linkedin, there&amp;#x2019;s a ton of data out there related to social networks. but even beyond the social networks, we&amp;#x2019;re going to be getting into email, blogs, articles, and whatever else is on the web that can provide information about your network....so we&amp;#x2019;re going to be housing a lot of data...\nwe want scaling to be easy, shouldn&amp;#x2019;t be rocket science....want to focus on developing the application, and not administering/supporting db clusters\n
  10. So...given that criteria a backdrop, we looked at our options: relational, couple of NoSQL / schema-free datastores\nnot exhaustive evaluation, but enough to feel comfortable....obviously we chose mongo, or we wouldn&amp;#x2019;t be having this conversation\n\nmakes it that much easier to support extensible objects...lots of other challenges, but at least the database is not one of them\nas a developer, you deal with your domain data on a daily basis....it&amp;#x2019;s so nice to see the data presented in a way that easy for humans to understand\n
  11. So...given that criteria a backdrop, we looked at our options: relational, couple of NoSQL / schema-free datastores\nnot exhaustive evaluation, but enough to feel comfortable....obviously we chose mongo, or we wouldn&amp;#x2019;t be having this conversation\n\nmakes it that much easier to support extensible objects...lots of other challenges, but at least the database is not one of them\nas a developer, you deal with your domain data on a daily basis....it&amp;#x2019;s so nice to see the data presented in a way that easy for humans to understand\n
  12. \n
  13. Had a design roughed out in relational model\n- team member had implemented something similar in previous life\n\n\n
  14. \n
  15. of course the name &amp;#x2018;mongo&amp;#x2019; comes from humongous so that&amp;#x2019;s a pretty good indication that scalability is built-in\n\nfor us, JSON is new XML, it&amp;#x2019;s everywhere\n\nso that&amp;#x2019;s one thing that&amp;#x2019;s good about JSON, the other thing is....\n\n(drill into this a little)\n\n
  16. of course the name &amp;#x2018;mongo&amp;#x2019; comes from humongous so that&amp;#x2019;s a pretty good indication that scalability is built-in\n\nfor us, JSON is new XML, it&amp;#x2019;s everywhere\n\nso that&amp;#x2019;s one thing that&amp;#x2019;s good about JSON, the other thing is....\n\n(drill into this a little)\n\n
  17. Take a look at the major components of our application\n\nHad already chosen Grails as app framework\n\nwhat this really means....\n
  18. +Can move really fast, fewer moving parts to develop/maintain\n+Good to get application going, plan on refactoring \n\n
  19. 10gen JIRA list is active\n\nClear from mongo forums, etc. that mongo is very active product.\n- not quite as sure with some of the other projects\n\n- not alone\n\n
  20. of course, nothing is perfect, life is a bunch of trade-offs\n\nyou don&amp;#x2019;t have transactions or really complex queries....JOINs, nested SELECTs\n\nlack of transactions was the thing I was most nervous about. have to go into with your eyes wide open, have to understand how to minimize the risk, and reduce the impact.\n
  21. \n
  22. \n
  23. the name &apos;things&apos; represents that this collection will hold different object types\nhaving all Things in one collection allows us to query across all Things\ngood use of Mongo&apos;s &apos;schema free&apos; document store\n show example thing (JSON)\n\n
  24. \n
  25. \n
  26. \n
  27. first cut: id of thing on left, thing on right and label\nwe were still thinking in relational terms\n\nwill be reading relationships much more often than creating new ones, so slow queries is definitely a bad thing\n\n
  28. \n
  29. \n
  30. \n
  31. \n
  32. hybrid solution - gives us best of both worlds\n- insertion integrity\n- query performance\ndownside:\nnow inserting/updating a rel is a two-step process: update &amp;#x201C;rels&amp;#x201D; collection, then push the changes to the related things\nif that second update fails, we can always rebuild those relationships from the rels collection.\n\n
  33. hybrid solution - gives us best of both worlds\n- insertion integrity\n- query performance\ndownside:\nnow inserting/updating a rel is a two-step process: update &amp;#x201C;rels&amp;#x201D; collection, then push the changes to the related things\nif that second update fails, we can always rebuild those relationships from the rels collection.\n\n
  34. hybrid solution - gives us best of both worlds\n- insertion integrity\n- query performance\ndownside:\nnow inserting/updating a rel is a two-step process: update &amp;#x201C;rels&amp;#x201D; collection, then push the changes to the related things\nif that second update fails, we can always rebuild those relationships from the rels collection.\n\n
  35. hybrid solution - gives us best of both worlds\n- insertion integrity\n- query performance\ndownside:\nnow inserting/updating a rel is a two-step process: update &amp;#x201C;rels&amp;#x201D; collection, then push the changes to the related things\nif that second update fails, we can always rebuild those relationships from the rels collection.\n\n
  36. hybrid solution - gives us best of both worlds\n- insertion integrity\n- query performance\ndownside:\nnow inserting/updating a rel is a two-step process: update &amp;#x201C;rels&amp;#x201D; collection, then push the changes to the related things\nif that second update fails, we can always rebuild those relationships from the rels collection.\n\n
  37. hybrid solution - gives us best of both worlds\n- insertion integrity\n- query performance\ndownside:\nnow inserting/updating a rel is a two-step process: update &amp;#x201C;rels&amp;#x201D; collection, then push the changes to the related things\nif that second update fails, we can always rebuild those relationships from the rels collection.\n\n
  38. the last major thing i want to talk about came about because we&amp;#x2019;re supporting a RESTful interface and mongo doesn&amp;#x2019;t enforce datatypes.\n\nmongo is not going to stop you from storing any kind of data in any field - it&amp;#x2019;s &amp;#x2018;schema-free&amp;#x2019;.\nenter JSON schema - provides a way to describe an object using JSON syntax\n\n
  39. analogous to DTD or XML schema\n
  40. \n
  41. one last point....the ease with which you can create collections, and the fact that you can store different looking objects in the same collection opens up possibilities\n\n\n
  42. \n
  43. \n