#MDBlocal A Complete Methodology of Data Modeling for MongoDB Daniel Coupal Education, MongoDB SOCAL
@ #MDBlocal Daniel Coupal Senior Curriculum Engineer, Education, MongoDB danielcoupal SOCAL
Goals of the Presentation Introduction Document vs Tabular Recognize the differences
Goals of the Presentation Introduction Document vs Tabular Recognize the differences Methodology Summarize the steps when modeling for MongoDB
Goals of the Presentation Introduction Document vs Tabular Recognize the differences Methodology Summarize the steps when modeling for MongoDB Use Case Franchise of coffee shops
Goals of the Presentation Introduction Document vs Tabular Recognize the differences Methodology Summarize the steps when modeling for MongoDB Patterns Recognize when to apply them Use Case Franchise of coffee shops
Goals of the Presentation Introduction Document vs Tabular Recognize the differences Methodology Summarize the steps when modeling for MongoDB Patterns Recognize when to apply them Use Case Franchise of coffee shops Conclusion and Questions
Document versus Tabular Recognize the differences when modeling for a Document Database versus a Relational/Tabular Database
#MDBLocal Document Model A. Fields/Attributes B. Arrays C. Sub-documents
#MDBLocal A. Fields/Attributes in the Document Model Explicit column names for defined values
#MDBLocal A. Fields/Attributes in the Document Model { 007, "Daniel", "Ferrari", "GTS", 1982 } Explicit column names for defined values
#MDBLocal A. Fields/Attributes in the Document Model { "_id": 007 "owner": "Daniel", "make": "Ferrari", "model": "GTS", "year": 1982 } Explicit column names for defined values
#MDBLocal B. Arrays in the Document Model Use to represents One-to-Many relationships
#MDBLocal B. Arrays in the Document Model { owner: "Daniel", make: "Ferrari", wheels: [ partNo: 234819, partNo: 281928, partNo: 392838, partNo: 928038 ], ... } Use to represents One-to-Many relationships
#MDBLocal C. Sub-documents in the Document Model Use to represents One-to-One relationships
#MDBLocal C. Sub-documents in the Document Model { owner: "Daniel", make: "Ferrari", power: 660hp, consumption: 10mpg … } Use to represents One-to-One relationships
#MDBLocal C. Sub-documents in the Document Model { owner: "Daniel", make: "Ferrari", engine: { power: 660hp, consumption: 10mpg } … } Use to represents One-to-One relationships
#MDBLocal C. Sub-documents in the Document Model { owner: "Daniel", make: "Ferrari", engine: { power: 660hp, consumption: 10mpg } … } Use to represents One-to-One relationships db.cars.find( {"owner":"Daniel"}, {"engine":1} ) Projection
#MDBLocal Car Stored in a Tabular/Relational Database SELECT * FROM Cars WHERE Cars.owner = "Daniel" INNER JOIN Wheels Cars.id = Wheels.car_id INNER JOIN Seats Cars.id = Seats.car_id INNER JOIN Brakes Cars.id = Brakes.car_id ...
#MDBLocal Car Stored in a Document Database db.cars.find( {"owner":"Daniel"} ) What goes together is stored together
#MDBLocal Example 1: Modeling a blog
#MDBLocal CRDs: A few Collection-Relationship-Diagrams Solutions Solution A Queries by users Simple
#MDBLocal CRDs: A few Collection-Relationship-Diagrams Solutions Solution A Queries by articles Queries by users Duplication of users information Simple Solution B
#MDBLocal CRDs: A few Collection-Relationship-Diagrams Solutions Solution A Solution C Queries by articles Queries by users Duplication of users information Simple Solution B
#MDBLocal Example 2: Modeling a Social Network
#MDBLocal Example 2: Modeling a Social Network Solution A writes reads Images Collection CC: Joanna Penn
#MDBLocal Example 2: Modeling a Social Network Solution B writes reads Submitter Profiles CC: Joanna Penn
#MDBLocal Example 2: Modeling a Social Network Solution C writes reads Follower Profiles
#MDBLocal Example 2: Modeling a Social Network Solution C writes reads ü Slower writes ü More storage space ü Duplication ü Faster reads Pre-aggregated Data Follower Profiles
#MDBLocal Differences: Tabular vs Document Tabular MongoDB Steps to create the model 1 – define schema 2 – develop app and queries 1 – identifying the queries 2 – define schema
#MDBLocal Differences: Tabular vs Document Tabular MongoDB Steps to create the model 1 – define schema 2 – develop app and queries 1 – identifying the queries 2 – define schema Initial schema • 3rd normal form • one possible solution • many possible solutions
#MDBLocal Differences: Tabular vs Document Tabular MongoDB Steps to create the model 1 – define schema 2 – develop app and queries 1 – identifying the queries 2 – define schema Initial schema • 3rd normal form • one possible solution • many possible solutions Final schema • likely denormalized • few changes
#MDBLocal Differences: Tabular vs Document Tabular MongoDB Steps to create the model 1 – define schema 2 – develop app and queries 1 – identifying the queries 2 – define schema Initial schema • 3rd normal form • one possible solution • many possible solutions Final schema • likely denormalized • few changes Schema evolution • difficult and not optimal • likely downtime • easy • no downtime
#MDBLocal Differences: Tabular vs Document Tabular MongoDB Steps to create the model 1 – define schema 2 – develop app and queries 1 – identifying the queries 2 – define schema Initial schema • 3rd normal form • one possible solution • many possible solutions Final schema • likely denormalized • few changes Schema evolution • difficult and not optimal • likely downtime • easy • no downtime Performance • mediocre • optimized
Methodology Summarize the steps of a methodology when modeling for MongoDB
#MDBLocal Main Tradeoff in Modeling
#MDBLocal Methodology
Methodology 1. Describe the Workload
Methodology 1. Describe the Workload 2. Identify and Model the Relationships
#MDBLocal Actors, Movies and Reviews actor_name date_of_birth movie_title revenues reviewer_name rating
#MDBLocal Actors, Movies and Reviews actor_name date_of_birth movie_title revenues reviewer rating
#MDBLocal Actors, Movies and Reviews actor_name date_of_birth movie_title revenues reviewer rating
Methodology 1. Describe the Workload 2. Identify and Model the Relationships 3. Apply Patterns
#MDBLocal Flexible Methodology
Use Case Let's start a franchise of coffee shops…
#MDBLocal Case Study: Coffee Shop Franchises Name: Beyond the Stars Coffee
#MDBLocal Case Study: Coffee Shop Franchises Name: Beyond the Stars Coffee Objective: • 10 000 stores in North America
#MDBLocal Case Study: Coffee Shop Franchises Name: Beyond the Stars Coffee Objective: • 10 000 stores in North America • … then we expend to the rest of the World
#MDBLocal Case Study: Coffee Shop Franchises Name: Beyond the Stars Coffee Objective: • 10 000 stores in North America • … then we expand to the rest of the World Keys to success: 1. Best coffee in the world
#MDBLocal Case Study: Coffee Shop Franchises Name: Beyond the Stars Coffee Objective: • 10 000 stores in North America • … then we expand to the rest of the World Keys to success: 1. Best coffee in the world 2. Best Technology
#MDBLocal First Key to Success: Make the Best Coffee in the World 23g of ground coffee in, 20g of extracted coffee out, in approximately 20 seconds 1. Fill a small or regular cup with 80% hot water (not boiling but pretty hot). Your cup should be 150ml to 200ml in total volume, 80% of which will be hot water. 2. Grind 23g of coffee into your portafilter using the double basket. We use a scale that you can get here. 3. Draw 20g of coffee over the hot water by placing your cup on a scale, press tare and extract your shot.
#MDBLocal Second Key to Success: Use the Best Technology a) Intelligent Coffee Machines • Weightings, temperature, time to produce, … • Coffee perfection
#MDBLocal Key to Success 2: Best Technology a) Intelligent Coffee Machines • Weightings, temperature, time to produce, … • Coffee perfection b) Intelligent Shelves • Measure inventory in real time
#MDBLocal Key to Success 2: Best Technology a) Intelligent Coffee Machines • Weightings, temperature, time to produce, … • Coffee perfection b) Intelligent Shelves • Measure inventory in real time c) Intelligent Data Storage • MongoDB
Methodology 1. Describe the Workload 2. Identify and Model the Relationships 3. Apply Patterns
#MDBLocal 1 – Workload: List Queries Query Operation Description 1. Coffee weight on the shelves write A shelf send information when coffee bags are added or removed
#MDBLocal 1 – Workload: List Queries Query Operation Description 1. Coffee weight on the shelves write A shelf send information when coffee bags are added or removed 2. Coffee to deliver to stores read How much coffee do we have to ship to the store in the next days
#MDBLocal 1 – Workload: List Queries Query Operation Description 1. Coffee weight on the shelves write A shelf send information when coffee bags are added or removed 2. Coffee to deliver to stores read How much coffee do we have to ship to the store in the next days 3. Anomalies in the inventory read Analytics
#MDBLocal 1 – Workload: List Queries Query Operation Description 1. Coffee weight on the shelves write A shelf send information when coffee bags are added or removed 2. Coffee to deliver to stores read How much coffee do we have to ship to the store in the next days 3. Anomalies in the inventory read Analytics 4. Making a cup of coffee write A coffee machine reporting on the production of a coffee cup
#MDBLocal 1 – Workload: List Queries Query Operation Description 1. Coffee weight on the shelves write A shelf send information when coffee bags are added or removed 2. Coffee to deliver to stores read How much coffee do we have to ship to the store in the next days 3. Anomalies in the inventory read Analytics 4. Making a cup of coffee write A coffee machine reporting on the production of a coffee cup 5. Analysis of cups of coffee read Analytics
#MDBLocal 1 – Workload: List Queries Query Operation Description 1. Coffee weight on the shelves write A shelf send information when coffee bags are added or removed 2. Coffee to deliver to stores read How much coffee do we have to ship to the store in the next days 3. Anomalies in the inventory read Analytics 4. Making a cup of coffee write A coffee machine reporting on the production of a coffee cup 5. Analysis of cups of coffee read Analytics 6. Technical Support read Helping our franchisees
#MDBLocal 1 – Workload: quantify/qualify the queries Query Quantification Qualification 1. Coffee weight on the shelves 10/day*shelf*store => 1/sec <1s critical write 2. Coffee to deliver to stores 1/day*store => 0.1/sec <60s 3. Anomalies in the inventory 24 reads/day <5mins "collection scan" 4. Making a cup of coffee 10 000 000 writes/day 115 writes/sec <100ms non-critical write … cups of coffee at rush hour 3 000 000 writes/hr 833 writes/sec <100ms non-critical write 5. Analysis of cups of coffee 24 reads/day stale data is fine "collection scan" 6. Technical Support 1000 reads/day <1s
#MDBLocal 1 – Workload: quantify/qualify the queries Query Quantification Qualification 1. Coffee weight on the shelves 10/day*shelf*store => 1/sec <1s critical write 2. Coffee to deliver to stores 1/day*store => 0.1/sec <60s 3. Anomalies in the inventory 24 reads/day <5mins "collection scan" 4. Making a cup of coffee 10 000 000 writes/day 115 writes/sec <100ms non-critical write … cups of coffee at rush hour 3 000 000 writes/hr 833 writes/sec <100ms non-critical write 5. Analysis of cups of coffee 24 reads/day stale data is fine "collection scan" 6. Technical Support 1000 reads/day <1s
#MDBLocal 1 – Workload: details of the most important queries Attribute Value Description Making a cup of coffee at rush hour Type Write Frequency 3 000 000 writes/hr 833 writes/sec Size 100 bytes Consistency/Integrity weak Latency < 10 sec Durability weak Life/Duration 1 year Security None
#MDBLocal Disk Space Cups of coffee • one year of data • 10000 x 1000/day x 365 • 3.7 billions/year • 370 GB (100 bytes/cup of coffee) Weighings • one year of data • 10000 x 10/day x 365 • 365 billions/year • 3.7 GB (100 bytes/weighings)
Methodology 1. Describe the Workload 2. Identify and Model the Relationships 3. Apply Patterns
#MDBLocal 2 - Relations are still important Type of Relation -> one-to-one/1-1 one-to-many/1-N many-to-many/N-N Document embedded in the parent document • one read • no joins • one read • no joins • one read • no joins • duplication of information Document referenced in the parent document • smaller reads • many reads • smaller reads • many reads • smaller reads • many reads
#MDBLocal 2 - Entities for Beyond the Stars Coffee Entities: • Coffee cups • Stores • Coffee machines • Shelves • Weighings • Coffee bags
Methodology 1. Describe the Workload 2. Identify and Model the Relationships 3. Apply Patterns
Patterns Recognize the need and when to apply Schema Design Patterns
#MDBLocal Schema Design Patterns Resources A. Advanced Schema Design Patterns, Daniel Coupal • MongoDB World 2017 B. Blogs on Patterns, Ken Alger & Daniel Coupal • https://www.mongodb.com/blog/post/building- with-patterns-a-summary C. MongoDB University: M320 – Data Modeling • https://university.mongodb.com/courses/M320/about
#MDBLocal Schema Versioning
#MDBLocal Schema Versioning
#MDBLocal Computed Pattern
#MDBLocal Computed Pattern
#MDBLocal Subset Pattern
#MDBLocal Subset Pattern
#MDBLocal Bucket Pattern
#MDBLocal Bucket Pattern { "device_id": 000123456, "type": "2A", "date": ISODate("2018-03-02"), "temp": [ [ 20.0, 20.1, 20.2, ... ], [ 22.1, 22.1, 22.0, ... ], ... ] } { "device_id": 000123456, "type": "2A", "date": ISODate("2018-03-03"), "temp": [ [ 20.1, 20.2, 20.3, ... ], [ 22.4, 22.4, 22.3, ... ], ... ] } { "device_id": 000123456, "type": "2A", "date": ISODate("2018-03-02T13"), "temp": { 1: 20.0, 2: 20.1, 3: 20.2, ... } } { "device_id": 000123456, "type": "2A", "date": ISODate("2018-03-02T14"), "temp": { 1: 22.1, 2: 22.1, 3: 22.0, ... } } Bucket per Day Bucket per Hour
#MDBLocal Solution with Patterns • Schema Versioning • Computed • Subset • Bucket
#MDBLocal https://university.mongodb.com/courses/M320/about Data Modeling Patterns Use Cases
Conclusion
Takeaways from the Presentation Document vs Tabular Recognize the differences Methodology Summarize the steps when modeling for MongoDB Patterns Recognize when to apply
Takeaways from the Presentation Document vs Tabular Recognize the differences Methodology Summarize the steps when modeling for MongoDB Patterns Recognize when to apply
Takeaways from the Presentation Document vs Tabular Recognize the differences Methodology Summarize the steps when modeling for MongoDB Patterns Recognize when to apply
Thank you for taking our FREE MongoDB classes at university.mongodb.com
Register Now! https://university.mongodb.com/courses/M320/about
#MDBlocal Every session you rate enters you into a drawing for a gift card and TWO passes to MongoDB World 2020! A Complete Methodology of Data Modeling with MongoDB https://www.surveymonkey.com/r/W8N6DLY
Appendix A Schema Versioning Pattern
#MDBLocal Nightmare: Alter Table
#MDBLocal This is what your dreams should be when thinking about a schema upgrade !
#MDBLocal Schema Revision Relational MongoDB Versioned Unit Schema Document Migration Procedure Difficult Easy Service Uptime Interrupted No interruption Rollback Difficult to nightmare-ish Easy
#MDBLocal
#MDBLocal
#MDBLocal Application Lifecycle Modify Application • Can read/process all versions of documents • Have different handler per version • Reshape the document before processing it Update all Application servers • Install updated application • Remove old processes Once migration completed • remove the code to process old versions.
#MDBLocal Document Lifecycle New Documents: • Application writes them in latest version Existing Documents A) Use updates to documents • to transform to latest version • keep forever documents that never need an update B) or transform all documents in batch • no worry even if process takes days
#MDBLocal Timeline of the migration
#MDBLocal Problem Solution Use Cases Examples Benefits and Trade-Offs Schema Versioning Pattern • Avoid downtime while doing schema upgrades • Upgrading all documents can take hours, days or even weeks when dealing with big data • Don't want to update all documents No downtime needed Feel in control of the migration Less future technical debt 🆇 May need 2 indexes for same field while in migration period • Each document gets a "schema_version" field • Application can handle all versions • Choose your strategy to migrate the documents • Every application that use a database, deployed in production and heavily used. • System with a lot of legacy data
Appendix B Computed Pattern
#MDBLocal Mathematical Operations
#MDBLocal Mathematical Operations
#MDBLocal "Fan Out" Operations
#MDBLocal "Roll Up" Operations
#MDBLocal Problem Solution Use Cases Examples Benefits and Trade-Offs Computed Pattern • Costly computation or manipulation of data • Executed frequently on the same data, producing the same result Read queries are faster Saving on resources like CPU and Disk 🆇 May be difficult to identify the need 🆇 Avoid applying or overusing it unless needed • Perform the operation and store the result in the appropriate document and collection • If need to redo the operations, keep the source of them • Internet Of Things (IOT) • Event Sourcing • Time Series Data • Frequent Aggregation Framework queries
THANK YOU

MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB

  • 1.
    #MDBlocal A Complete Methodologyof Data Modeling for MongoDB Daniel Coupal Education, MongoDB SOCAL
  • 2.
    @ #MDBlocal Daniel Coupal Senior CurriculumEngineer, Education, MongoDB danielcoupal SOCAL
  • 3.
    Goals of thePresentation Introduction Document vs Tabular Recognize the differences
  • 4.
    Goals of thePresentation Introduction Document vs Tabular Recognize the differences Methodology Summarize the steps when modeling for MongoDB
  • 5.
    Goals of thePresentation Introduction Document vs Tabular Recognize the differences Methodology Summarize the steps when modeling for MongoDB Use Case Franchise of coffee shops
  • 6.
    Goals of thePresentation Introduction Document vs Tabular Recognize the differences Methodology Summarize the steps when modeling for MongoDB Patterns Recognize when to apply them Use Case Franchise of coffee shops
  • 7.
    Goals of thePresentation Introduction Document vs Tabular Recognize the differences Methodology Summarize the steps when modeling for MongoDB Patterns Recognize when to apply them Use Case Franchise of coffee shops Conclusion and Questions
  • 8.
    Document versus Tabular Recognize thedifferences when modeling for a Document Database versus a Relational/Tabular Database
  • 9.
  • 10.
    #MDBLocal A. Fields/Attributes inthe Document Model Explicit column names for defined values
  • 11.
    #MDBLocal A. Fields/Attributes inthe Document Model { 007, "Daniel", "Ferrari", "GTS", 1982 } Explicit column names for defined values
  • 12.
    #MDBLocal A. Fields/Attributes inthe Document Model { "_id": 007 "owner": "Daniel", "make": "Ferrari", "model": "GTS", "year": 1982 } Explicit column names for defined values
  • 13.
    #MDBLocal B. Arrays inthe Document Model Use to represents One-to-Many relationships
  • 14.
    #MDBLocal B. Arrays inthe Document Model { owner: "Daniel", make: "Ferrari", wheels: [ partNo: 234819, partNo: 281928, partNo: 392838, partNo: 928038 ], ... } Use to represents One-to-Many relationships
  • 15.
    #MDBLocal C. Sub-documents inthe Document Model Use to represents One-to-One relationships
  • 16.
    #MDBLocal C. Sub-documents inthe Document Model { owner: "Daniel", make: "Ferrari", power: 660hp, consumption: 10mpg … } Use to represents One-to-One relationships
  • 17.
    #MDBLocal C. Sub-documents inthe Document Model { owner: "Daniel", make: "Ferrari", engine: { power: 660hp, consumption: 10mpg } … } Use to represents One-to-One relationships
  • 18.
    #MDBLocal C. Sub-documents inthe Document Model { owner: "Daniel", make: "Ferrari", engine: { power: 660hp, consumption: 10mpg } … } Use to represents One-to-One relationships db.cars.find( {"owner":"Daniel"}, {"engine":1} ) Projection
  • 19.
    #MDBLocal Car Stored ina Tabular/Relational Database SELECT * FROM Cars WHERE Cars.owner = "Daniel" INNER JOIN Wheels Cars.id = Wheels.car_id INNER JOIN Seats Cars.id = Seats.car_id INNER JOIN Brakes Cars.id = Brakes.car_id ...
  • 20.
    #MDBLocal Car Stored ina Document Database db.cars.find( {"owner":"Daniel"} ) What goes together is stored together
  • 21.
  • 22.
    #MDBLocal CRDs: A fewCollection-Relationship-Diagrams Solutions Solution A Queries by users Simple
  • 23.
    #MDBLocal CRDs: A fewCollection-Relationship-Diagrams Solutions Solution A Queries by articles Queries by users Duplication of users information Simple Solution B
  • 24.
    #MDBLocal CRDs: A fewCollection-Relationship-Diagrams Solutions Solution A Solution C Queries by articles Queries by users Duplication of users information Simple Solution B
  • 25.
  • 26.
    #MDBLocal Example 2: Modelinga Social Network Solution A writes reads Images Collection CC: Joanna Penn
  • 27.
    #MDBLocal Example 2: Modelinga Social Network Solution B writes reads Submitter Profiles CC: Joanna Penn
  • 28.
    #MDBLocal Example 2: Modelinga Social Network Solution C writes reads Follower Profiles
  • 29.
    #MDBLocal Example 2: Modelinga Social Network Solution C writes reads ü Slower writes ü More storage space ü Duplication ü Faster reads Pre-aggregated Data Follower Profiles
  • 30.
    #MDBLocal Differences: Tabular vsDocument Tabular MongoDB Steps to create the model 1 – define schema 2 – develop app and queries 1 – identifying the queries 2 – define schema
  • 31.
    #MDBLocal Differences: Tabular vsDocument Tabular MongoDB Steps to create the model 1 – define schema 2 – develop app and queries 1 – identifying the queries 2 – define schema Initial schema • 3rd normal form • one possible solution • many possible solutions
  • 32.
    #MDBLocal Differences: Tabular vsDocument Tabular MongoDB Steps to create the model 1 – define schema 2 – develop app and queries 1 – identifying the queries 2 – define schema Initial schema • 3rd normal form • one possible solution • many possible solutions Final schema • likely denormalized • few changes
  • 33.
    #MDBLocal Differences: Tabular vsDocument Tabular MongoDB Steps to create the model 1 – define schema 2 – develop app and queries 1 – identifying the queries 2 – define schema Initial schema • 3rd normal form • one possible solution • many possible solutions Final schema • likely denormalized • few changes Schema evolution • difficult and not optimal • likely downtime • easy • no downtime
  • 34.
    #MDBLocal Differences: Tabular vsDocument Tabular MongoDB Steps to create the model 1 – define schema 2 – develop app and queries 1 – identifying the queries 2 – define schema Initial schema • 3rd normal form • one possible solution • many possible solutions Final schema • likely denormalized • few changes Schema evolution • difficult and not optimal • likely downtime • easy • no downtime Performance • mediocre • optimized
  • 35.
    Methodology Summarize the stepsof a methodology when modeling for MongoDB
  • 36.
  • 37.
  • 38.
  • 39.
    Methodology 1. Describe the Workload 2.Identify and Model the Relationships
  • 40.
    #MDBLocal Actors, Movies andReviews actor_name date_of_birth movie_title revenues reviewer_name rating
  • 41.
    #MDBLocal Actors, Movies andReviews actor_name date_of_birth movie_title revenues reviewer rating
  • 42.
    #MDBLocal Actors, Movies andReviews actor_name date_of_birth movie_title revenues reviewer rating
  • 43.
    Methodology 1. Describe the Workload 2.Identify and Model the Relationships 3. Apply Patterns
  • 44.
  • 45.
    Use Case Let's starta franchise of coffee shops…
  • 46.
    #MDBLocal Case Study: CoffeeShop Franchises Name: Beyond the Stars Coffee
  • 47.
    #MDBLocal Case Study: CoffeeShop Franchises Name: Beyond the Stars Coffee Objective: • 10 000 stores in North America
  • 48.
    #MDBLocal Case Study: CoffeeShop Franchises Name: Beyond the Stars Coffee Objective: • 10 000 stores in North America • … then we expend to the rest of the World
  • 49.
    #MDBLocal Case Study: CoffeeShop Franchises Name: Beyond the Stars Coffee Objective: • 10 000 stores in North America • … then we expand to the rest of the World Keys to success: 1. Best coffee in the world
  • 50.
    #MDBLocal Case Study: CoffeeShop Franchises Name: Beyond the Stars Coffee Objective: • 10 000 stores in North America • … then we expand to the rest of the World Keys to success: 1. Best coffee in the world 2. Best Technology
  • 51.
    #MDBLocal First Key toSuccess: Make the Best Coffee in the World 23g of ground coffee in, 20g of extracted coffee out, in approximately 20 seconds 1. Fill a small or regular cup with 80% hot water (not boiling but pretty hot). Your cup should be 150ml to 200ml in total volume, 80% of which will be hot water. 2. Grind 23g of coffee into your portafilter using the double basket. We use a scale that you can get here. 3. Draw 20g of coffee over the hot water by placing your cup on a scale, press tare and extract your shot.
  • 52.
    #MDBLocal Second Key toSuccess: Use the Best Technology a) Intelligent Coffee Machines • Weightings, temperature, time to produce, … • Coffee perfection
  • 53.
    #MDBLocal Key to Success2: Best Technology a) Intelligent Coffee Machines • Weightings, temperature, time to produce, … • Coffee perfection b) Intelligent Shelves • Measure inventory in real time
  • 54.
    #MDBLocal Key to Success2: Best Technology a) Intelligent Coffee Machines • Weightings, temperature, time to produce, … • Coffee perfection b) Intelligent Shelves • Measure inventory in real time c) Intelligent Data Storage • MongoDB
  • 55.
    Methodology 1. Describe the Workload 2.Identify and Model the Relationships 3. Apply Patterns
  • 56.
    #MDBLocal 1 – Workload:List Queries Query Operation Description 1. Coffee weight on the shelves write A shelf send information when coffee bags are added or removed
  • 57.
    #MDBLocal 1 – Workload:List Queries Query Operation Description 1. Coffee weight on the shelves write A shelf send information when coffee bags are added or removed 2. Coffee to deliver to stores read How much coffee do we have to ship to the store in the next days
  • 58.
    #MDBLocal 1 – Workload:List Queries Query Operation Description 1. Coffee weight on the shelves write A shelf send information when coffee bags are added or removed 2. Coffee to deliver to stores read How much coffee do we have to ship to the store in the next days 3. Anomalies in the inventory read Analytics
  • 59.
    #MDBLocal 1 – Workload:List Queries Query Operation Description 1. Coffee weight on the shelves write A shelf send information when coffee bags are added or removed 2. Coffee to deliver to stores read How much coffee do we have to ship to the store in the next days 3. Anomalies in the inventory read Analytics 4. Making a cup of coffee write A coffee machine reporting on the production of a coffee cup
  • 60.
    #MDBLocal 1 – Workload:List Queries Query Operation Description 1. Coffee weight on the shelves write A shelf send information when coffee bags are added or removed 2. Coffee to deliver to stores read How much coffee do we have to ship to the store in the next days 3. Anomalies in the inventory read Analytics 4. Making a cup of coffee write A coffee machine reporting on the production of a coffee cup 5. Analysis of cups of coffee read Analytics
  • 61.
    #MDBLocal 1 – Workload:List Queries Query Operation Description 1. Coffee weight on the shelves write A shelf send information when coffee bags are added or removed 2. Coffee to deliver to stores read How much coffee do we have to ship to the store in the next days 3. Anomalies in the inventory read Analytics 4. Making a cup of coffee write A coffee machine reporting on the production of a coffee cup 5. Analysis of cups of coffee read Analytics 6. Technical Support read Helping our franchisees
  • 62.
    #MDBLocal 1 – Workload:quantify/qualify the queries Query Quantification Qualification 1. Coffee weight on the shelves 10/day*shelf*store => 1/sec <1s critical write 2. Coffee to deliver to stores 1/day*store => 0.1/sec <60s 3. Anomalies in the inventory 24 reads/day <5mins "collection scan" 4. Making a cup of coffee 10 000 000 writes/day 115 writes/sec <100ms non-critical write … cups of coffee at rush hour 3 000 000 writes/hr 833 writes/sec <100ms non-critical write 5. Analysis of cups of coffee 24 reads/day stale data is fine "collection scan" 6. Technical Support 1000 reads/day <1s
  • 63.
    #MDBLocal 1 – Workload:quantify/qualify the queries Query Quantification Qualification 1. Coffee weight on the shelves 10/day*shelf*store => 1/sec <1s critical write 2. Coffee to deliver to stores 1/day*store => 0.1/sec <60s 3. Anomalies in the inventory 24 reads/day <5mins "collection scan" 4. Making a cup of coffee 10 000 000 writes/day 115 writes/sec <100ms non-critical write … cups of coffee at rush hour 3 000 000 writes/hr 833 writes/sec <100ms non-critical write 5. Analysis of cups of coffee 24 reads/day stale data is fine "collection scan" 6. Technical Support 1000 reads/day <1s
  • 64.
    #MDBLocal 1 – Workload:details of the most important queries Attribute Value Description Making a cup of coffee at rush hour Type Write Frequency 3 000 000 writes/hr 833 writes/sec Size 100 bytes Consistency/Integrity weak Latency < 10 sec Durability weak Life/Duration 1 year Security None
  • 65.
    #MDBLocal Disk Space Cups ofcoffee • one year of data • 10000 x 1000/day x 365 • 3.7 billions/year • 370 GB (100 bytes/cup of coffee) Weighings • one year of data • 10000 x 10/day x 365 • 365 billions/year • 3.7 GB (100 bytes/weighings)
  • 66.
    Methodology 1. Describe the Workload 2.Identify and Model the Relationships 3. Apply Patterns
  • 67.
    #MDBLocal 2 - Relationsare still important Type of Relation -> one-to-one/1-1 one-to-many/1-N many-to-many/N-N Document embedded in the parent document • one read • no joins • one read • no joins • one read • no joins • duplication of information Document referenced in the parent document • smaller reads • many reads • smaller reads • many reads • smaller reads • many reads
  • 68.
    #MDBLocal 2 - Entitiesfor Beyond the Stars Coffee Entities: • Coffee cups • Stores • Coffee machines • Shelves • Weighings • Coffee bags
  • 69.
    Methodology 1. Describe the Workload 2.Identify and Model the Relationships 3. Apply Patterns
  • 70.
    Patterns Recognize the needand when to apply Schema Design Patterns
  • 71.
    #MDBLocal Schema Design PatternsResources A. Advanced Schema Design Patterns, Daniel Coupal • MongoDB World 2017 B. Blogs on Patterns, Ken Alger & Daniel Coupal • https://www.mongodb.com/blog/post/building- with-patterns-a-summary C. MongoDB University: M320 – Data Modeling • https://university.mongodb.com/courses/M320/about
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
    #MDBLocal Bucket Pattern { "device_id": 000123456, "type":"2A", "date": ISODate("2018-03-02"), "temp": [ [ 20.0, 20.1, 20.2, ... ], [ 22.1, 22.1, 22.0, ... ], ... ] } { "device_id": 000123456, "type": "2A", "date": ISODate("2018-03-03"), "temp": [ [ 20.1, 20.2, 20.3, ... ], [ 22.4, 22.4, 22.3, ... ], ... ] } { "device_id": 000123456, "type": "2A", "date": ISODate("2018-03-02T13"), "temp": { 1: 20.0, 2: 20.1, 3: 20.2, ... } } { "device_id": 000123456, "type": "2A", "date": ISODate("2018-03-02T14"), "temp": { 1: 22.1, 2: 22.1, 3: 22.0, ... } } Bucket per Day Bucket per Hour
  • 80.
    #MDBLocal Solution with Patterns •Schema Versioning • Computed • Subset • Bucket
  • 81.
  • 82.
  • 83.
    Takeaways from thePresentation Document vs Tabular Recognize the differences Methodology Summarize the steps when modeling for MongoDB Patterns Recognize when to apply
  • 84.
    Takeaways from thePresentation Document vs Tabular Recognize the differences Methodology Summarize the steps when modeling for MongoDB Patterns Recognize when to apply
  • 85.
    Takeaways from thePresentation Document vs Tabular Recognize the differences Methodology Summarize the steps when modeling for MongoDB Patterns Recognize when to apply
  • 86.
    Thank you fortaking our FREE MongoDB classes at university.mongodb.com
  • 87.
  • 88.
    #MDBlocal Every session yourate enters you into a drawing for a gift card and TWO passes to MongoDB World 2020! A Complete Methodology of Data Modeling with MongoDB https://www.surveymonkey.com/r/W8N6DLY
  • 90.
  • 91.
  • 92.
    #MDBLocal This is whatyour dreams should be when thinking about a schema upgrade !
  • 93.
    #MDBLocal Schema Revision Relational MongoDB VersionedUnit Schema Document Migration Procedure Difficult Easy Service Uptime Interrupted No interruption Rollback Difficult to nightmare-ish Easy
  • 94.
  • 95.
  • 96.
    #MDBLocal Application Lifecycle Modify Application •Can read/process all versions of documents • Have different handler per version • Reshape the document before processing it Update all Application servers • Install updated application • Remove old processes Once migration completed • remove the code to process old versions.
  • 97.
    #MDBLocal Document Lifecycle New Documents: •Application writes them in latest version Existing Documents A) Use updates to documents • to transform to latest version • keep forever documents that never need an update B) or transform all documents in batch • no worry even if process takes days
  • 98.
  • 99.
    #MDBLocal Problem Solution Use CasesExamples Benefits and Trade-Offs Schema Versioning Pattern • Avoid downtime while doing schema upgrades • Upgrading all documents can take hours, days or even weeks when dealing with big data • Don't want to update all documents No downtime needed Feel in control of the migration Less future technical debt 🆇 May need 2 indexes for same field while in migration period • Each document gets a "schema_version" field • Application can handle all versions • Choose your strategy to migrate the documents • Every application that use a database, deployed in production and heavily used. • System with a lot of legacy data
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
    #MDBLocal Problem Solution Use CasesExamples Benefits and Trade-Offs Computed Pattern • Costly computation or manipulation of data • Executed frequently on the same data, producing the same result Read queries are faster Saving on resources like CPU and Disk 🆇 May be difficult to identify the need 🆇 Avoid applying or overusing it unless needed • Perform the operation and store the result in the appropriate document and collection • If need to redo the operations, keep the source of them • Internet Of Things (IOT) • Event Sourcing • Time Series Data • Frequent Aggregation Framework queries
  • 106.