• Share
  • Email
  • Embed
  • Like
  • Private Content
Webinar: From Relational Databases to MongoDB - What You Need to Know
 

Webinar: From Relational Databases to MongoDB - What You Need to Know

on

  • 2,998 views

Relational databases weren't designed to cope with the scale and agility challenges that face modern applications. MongoDB can offer scalability, performance and ease of use - but proper design will ...

Relational databases weren't designed to cope with the scale and agility challenges that face modern applications. MongoDB can offer scalability, performance and ease of use - but proper design will be a critical factor to that success. We'll take a dive into how MongoDB works to better understand what non-relational design is, why we might use it and what advantages it gives us. We'll develop schema designs by example, and consider strategies for scale out.

Statistics

Views

Total Views
2,998
Views on SlideShare
1,259
Embed Views
1,739

Actions

Likes
6
Downloads
137
Comments
0

5 Embeds 1,739

http://www.mongodb.com 1620
http://tediscript.wordpress.com 44
https://www.mongodb.com 36
https://twitter.com 33
http://drupal1.10gen.cc 6

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary
  • Initialize -> ElectionPrimary + data replication from primary to secondary

Webinar: From Relational Databases to MongoDB - What You Need to Know Webinar: From Relational Databases to MongoDB - What You Need to Know Presentation Transcript

  • From Relational Databases to MongoDB – What You Need to Know Bryan Reinero Consulting Engineer, MongoDB
  • Unhelpful Terms • NoSQL • Big Data • Distributed What’s the data model?
  • MongoDB • Non-relational • Scalable • Highly available • Full featured • Document database
  • Terminology RDBMS Table, View Row Index Join Foreign Key Partition ➜ ➜ ➜ ➜ ➜ ➜ MongoDB Collection Document Index Embedded Document Reference Shard
  • Sample Document { maker : ”Agusta", type : sportbike, rake : 7, trail : 3.93, engine : { type : "internal cumbustion", layout : "inline" cylinders : 4, displacement : 750, }, transmission : { type : "cassette", speeds : 6, pattern : "sequential”, ratios : [ 2.7, 1.94, 1.34, 1, 0.83, 0.64 ] } }
  • Relational DBs • Attribute columns are valid for every row • Duplicate rows are not allowed • Every column has the same type and same meaning As a document store, MongoDB supports a flexible schema
  • 1st Normal Form: No repeating groups Product_id 1234 5678 91011 • Maker Nokia Apple Samsung Name Lumia iPad Galaxy Categories “electronics,hand held, smart phone” “PDA,tablet” “smart phone,tablet” Can't use equality to match elements
  • 1st Normal Form: No repeating groups Product_id 1234 5678 91011 Maker Nokia Apple Samsung Name Lumia iPad Galaxy Categories “electronics,hand held, smart phone” “PDA,tablet” “smart phone,tablet” • Can't use equality to match elements • Must use regular expressions to find data
  • 1st Normal Form: No repeating groups Product_id 1234 5678 91011 Maker Nokia Apple Samsung Name Lumia iPad Galaxy Categories “electronics,hand held, smart phone” “PDA,tablet” “smart phone,tablet” • Can't use equality to match elements • Must use regular expressions to find data • Aggregate functions are difficult
  • 1st Normal Form: No repeating groups Product_id 1234 5678 91011 Maker Nokia Apple Samsung Name Lumia iPad Galaxy Categories “electronics,hand held, smart phone” “PDA,tablet” “smart phone,tablet” • Can't use equality to match elements • Must use regular expressions to find data • Aggregate functions are difficult • Updating a specific element is difficult
  • The Tao of MongoDB { _id : ObjectId(), maker : “Nokia” name : “Lumia”, categories : [ "electronics", "handheld", "smart phone" ] }
  • The Tao of MongoDB { _id : ObjectId(), maker : “Nokia” name : “Lumia”, categories : [ "electronics", "handheld", "smart phone" ] } // querying is easy db.products.find( { "categories": ”handheld" } );
  • The Tao of MongoDB { _id : ObjectId(), maker : “Nokia” name : “Lumia”, categories : [ "electronics", "handheld", "smart phone" ] } // querying is easy db.products.find( { "categories": ”handheld" } ); // can be indexed db.products.ensureIndex( { "categories”: 1 } );
  • The Tao of MongoDB { _id : ObjectId(), maker : “Nokia” name : “Lumia”, categories : [ "electronics", "handheld", "smart phone" ] } // Updates are easy db.products.update( { "categories": "electronics"}, { $set: { "categories.$" : "consumer electronics" } } );
  • The Tao of MongoDB { _id : ObjectId(), maker : “Nokia” name : “Lumia”, categories : [ "electronics", "handheld", "smart phone" ] } db.products.aggregate( { $unwind : "$categories" }, { $group : { "_id" : "$categories", "counts" : { "$sum" : 1 } } } );
  • The Tao of MongoDB { _id : ObjectId(), maker : “Nokia” name : “Lumia”, categories : [ "electronics", "handheld", "smart phone" ] } db.products.aggregate( Unwind the array { $unwind : "$categories" }, { $group : { "_id" : "$categories", "counts" : { "$sum" : 1 } } } );
  • The Tao of MongoDB { _id : ObjectId(), maker : “Nokia” name : “Lumia”, categories : [ "electronics", "handheld", "smart phone" ] } db.products.aggregate( Unwind the array { $unwind : "$categories" }, { $group : { "_id" : "$categories", "counts" : { "$sum" : 1 } } } Tally the occurrences );
  • The Tao of MongoDB "result" : [ { "_id" : "smart phone”, "counts" : 1589 }, { "_id" : "handheld”, "counts" : 2403 }, { "_id" : "electronics”, "counts" : 4767 } ] db.products.aggregate( { $unwind : "$categories" }, { $group : { "_id" : "$categories", "counts" : { "$sum" : 1 } } } );
  • Meh, big deal…. Right? Aren’t nested structures just a pre-joined schema? • I could use an adjacency list • I could use an intersection table
  • Goals of Normalization • Model data an understandable form • Reduce fact redundancy and data inconsistency • Enforce integrity constraints Performance is not a primary goal
  • Normalize or Denormalize Commonly held that denormalization is faster
  • Normalize or Denormalize Commonly held that denormalization is faster • Normalization can be fast, right?
  • Normalize or Denormalize Commonly held that denormalization is faster • Normalization can be fast, right? Requires proper indexing, indexing effects write performance
  • Normalize or Denormalize Commonly held that denormalization is faster • Normalization can be fast, right? Requires proper indexing, indexing effects write performance • Does denormalization commit me to a join strategy?
  • Normalize or Denormalize Commonly held that denormalization is faster • Normalization can be fast, right? Requires proper indexing, indexing effects write performance • Does denormalization commit me to a join strategy? Indexing overhead is a commitment too
  • Normalize or Denormalize Commonly held that denormalization is faster • Normalization can be fast, right? Requires proper indexing, indexing effects write performance • Does denormalization commit me to a join strategy? Indexing overhead is a commitment too • Does denormalizaiton improve a finite set of queries at the cost of several others?
  • Normalize or Denormalize Commonly held that denormalization is faster • Normalization can be fast, right? Requires proper indexing, indexing effects write performance • Does denormalization commit me to a join strategy? Indexing overhead is a commitment too • Does denormalizaiton improve a finite set of queries at the cost of several others? MongoDB works best in service to an application
  • Object–Relational Impedance Mismatch • Inheritance hierarchies • Polymorphic associations
  • Table Per Subclass Vehicles vin registration maker Motorcycle Engine rake trial Racebike racing number class team rider
  • Table Per Subclass Vehicles - electric - car - bus - motorcycle - internal combustion -motorcycle - aircraft - human powered - bicycle - skateboard -horsedrawn
  • Table Per Concrete Class • Each class is mapped to a separate table • Inherited fields are present in each class’ table • Can’t support polymorphic relationships
  • Table Per Concrete Class • Each class is mapped to a separate table • Inherited fields are present in each class’ table • Can’t support polymorphic relationships SELECT maker FROM Motorcycles WHERE Motorcycles.country = "Italy" UNION SELECT maker FROM Automobiles WHERE Automobiles.country = "Italy"
  • Table Per Class Family • Classes mapped to a single table Vehicle_id 1234 5678 91011 Maker M.V Agusta M.V. Agusta Triton Name F4 A104 Triton 95 Type sportbike helicopter submarine
  • Table Per Class Family • Classes mapped to a single table • Discriminator column to identify class discriminator Vehicle_id 1234 5678 91011 Maker M.V Agusta M.V. Agusta Triton Name F4 A104 Triton 95 Type sportbike helicopter submarine
  • Table Per Class Family • Classes mapped to a single table • Discriminator column to identify class • Many empty columns, nullability issues Vehicle_id 1234 5678 91011 Maker M.V Agusta M.V. Agusta Triton Name F4 A104 Triton 95 Type sportbike helicopter submarine
  • Table Per Class Family • Classes mapped to a single table • Discriminator column to identify class • Many empty columns, nullability issues Vehicle_id 1234 5678 91011 Maker M.V Agusta M.V. Agusta Triton maker = “M.V. Agusta”, Name type =F4 “sportbike”, num_doors = 0, A104 wing_area = 0, Triton 95 maximum_depth = 0 Type sportbike helicopter submarine ???
  • The Tao of MongoDB { } { } maker : "M.V. Agusta", type : sportsbike, engine : { type : ”internal combustion", cylinders: 4, displacement : 750 }, rake : 7, trail : 3.93 maker : "M.V. Agusta", type : Helicopter engine : { type : "turboshaft" layout : "axial”, massflow : 1318 }, Blades : 4 undercarriage : "fixed"
  • The Tao of MongoDB { } { } maker : "M.V. Agusta", type : sportsbike, engine : { type : ”internal combustion", cylinders: 4, displacement : 750 }, rake : 7, trail : 3.93 maker : "M.V. Agusta", type : Helicopter, engine : { type : "turboshaft" layout : "axial”, massflow : 1318 }, Blades : 4, undercarriage : "fixed" Discriminator column
  • The Tao of MongoDB { } { } maker : "M.V. Agusta", type : sportsbike, engine : { type : ”internal combustion", cylinders: 4, displacement : 750 }, rake : 7, trail : 3.93 maker : "M.V. Agusta", type : Helicopter engine : { type : "turboshaft" layout : "axial”, massflow : 1318 }, Blades : 4, undercarriage : "fixed" Shared indexing strategy
  • The Tao of MongoDB { } { } maker : "M.V. Agusta", type : sportsbike, engine : { type : ”internal combustion", cylinders: 4, displacement : 750 }, rake : 7, trail : 3.93 maker : "M.V. Agusta", type : Helicopter engine : { type : "turboshaft" layout : "axial”, massflow : 1318 }, Blades : 4 undercarriage : "fixed" Polymorphic attributes
  • Relaxed ACID • Atomic operations at the Document level
  • Relaxed ACID • Atomic operations at the Document level • Consistency – strong / eventual
  • Replication
  • Relaxed ACID • Atomic operations at the Document level • Consistency – strong / eventual • Isolation - read lock, write lock / logical database
  • Relaxed ACID • Atomic operations at the Document level • Consistency – strong / eventual • Isolation - read lock, write lock / logical database • Durability – write ahead journal, replication
  • The Tao of MongoDB • Document database • Flexible schema • Relaxed ACID This favors denormalization. What’s the consequence?
  • Scaling MongoDB Sharded cluster MongoDB Single Instance Or Replica Set Client Application
  • Partitioning • User defines shard key • Shard key defines range of data • Key space is like points on a line • Range is a segment of that line
  • The Mechanism of Sharding Complete Data Set Define shard key on vehicle id 1234 2345 3456 4567 5678
  • The Mechanism of Sharding Chunk Chunk Define shard key on title 1234 2345 3456 4567 5678
  • The Mechanism of Sharding Chunk Chunk Chunk Chunk Define shard key on vehicle id 1234 2345 3456 4567 5678
  • Chunk Chunk Chunk Chunk Define shard key on vehicle id 1234 Shard 1 2345 3456 Shard 2 4567 Shard 3 5678 Shard 4
  • Targeted Operations Client mongos Shard 1 Shard 2 Shard 3 Shard 4
  • Data Growth Shard 1 Shard 2 Shard 3 Shard 4
  • Load Balancing Shard 1 Shard 2 Shard 3 Shard 4
  • Relational if you need to • Enforce data constraints • Service a broad set of queries • Minimize redundancy
  • The Tao of MongoDB • Avoid ad-hoc queries • Model data for use, not storage • Index effectively, index efficiently
  • Next Steps • Webinar: From Relational Databases to MongoDB - Considerations and Best Practices – November 7 – 11am PT / 2pm ET / 6 pm UTC • Register now at: mongodb.com/events
  • Questions?
  • Thank You