App Dev with Documents, their Schemas and Relationships Tugdual Grall Technical Evangelist.

Slides:



Advertisements
Similar presentations
Access 2007 ® Use Databases How can Microsoft Access 2007 help you structure your database?
Advertisements

Chapter 10: Designing Databases
SERVICE MANAGER 9.2 VIEWS AND REPORTS July, 2011.
Database Management3-1 L3 Database Management Santa R. Susarapu Ph.D. Student Virginia Commonwealth University.
Database Management System MIS 520 – Database Theory Fall 2001 (Day) Lecture 13.
Accounting System Design
Visibility Information Exchange Web System. Source Data Import Source Data Validation Database Rules Program Logic Storage RetrievalPresentation AnalysisInterpretation.
Chapter 3 Database Management
Database Management: Getting Data Together Chapter 14.
Chapter 11 Data Management Layer Design
Mgt 20600: IT Management & Applications Databases Tuesday April 4, 2006.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Chapter 2 Introduction to Database Development Database Processing David M. Kroenke © 2000 Prentice Hall.
1 Agenda Views Pages Web Parts Navigation Office Wrap-Up.
A Social blog using MongoDB ITEC-810 Final Presentation Lucero Soria Supervisor: Dr. Jian Yang.
Phil Brewster  One of the first steps – identify the proper data types  Decide how data (in columns) should be stored and used.
IST Databases and DBMSs Todd S. Bacastow January 2005.
Module 3: Table Selection
Database Design for DNN Developers Sebastian Leupold.
Denise Luther Senior IT Consultant Practical Technology Enablement with Enterprise Integrator.
Systems analysis and design, 6th edition Dennis, wixom, and roth
Oracle10g Developer: PL/SQL Programming1 Objectives Manipulating data with cursors Managing errors with exception handlers Addressing exception-handling.
ISV Innovation Presented by ISV Innovation Presented by Business Intelligence Fundamentals: Data Loading Ola Ekdahl IT Mentors 9/12/08.
Online Autonomous Citation Management for CiteSeer CSE598B Course Project By Huajing Li.
PowerPoint Presentation for Dennis & Haley Wixom, Systems Analysis and Design, 2 nd Edition Copyright 2003 © John Wiley & Sons, Inc. All rights reserved.
 DATABASE DATABASE  DATABASE ENVIRONMENT DATABASE ENVIRONMENT  WHY STUDY DATABASE WHY STUDY DATABASE  DBMS & ITS FUNCTIONS DBMS & ITS FUNCTIONS 
Database System Concepts and Architecture
Introduction: Databases and Database Users
Chapter 7: Database Systems Succeeding with Technology: Second Edition.
HNDComputing – DeMontfort University  DeMontfort University 2011 Database Fundamentals wk2 Database Design ConceptsDatabase Design Concepts Database Design.
NoSQL Databases NoSQL Concepts SoftUni Team Technical Trainers Software University
I Information Systems Technology Ross Malaga 4 "Part I Understanding Information Systems Technology" Copyright © 2005 Prentice Hall, Inc. 4-1 DATABASE.
Discovering Computers Fundamentals Fifth Edition Chapter 9 Database Management.
DAY 12: DATABASE CONCEPT Tazin Afrin September 26,
Object Persistence Design Chapter 13. Key Definitions Object persistence involves the selection of a storage format and optimization for performance.
Information Systems & Databases 2.2) Organisation methods.
1 Relational Databases and SQL. Learning Objectives Understand techniques to model complex accounting phenomena in an E-R diagram Develop E-R diagrams.
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
CS370 Spring 2007 CS 370 Database Systems Lecture 1 Overview of Database Systems.
1 CS 430 Database Theory Winter 2005 Lecture 2: General Concepts.
INFO1408 Database Design Concepts Week 15: Introduction to Database Management Systems.
Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Access 2007 ® Use Databases How can Microsoft Access 2007 help you structure your database?
Esri UC 2014 | Technical Workshop | Editing Versioned Geodatabases : An Introduction Cheryl Cleghorn and Shawn Thorne.
Alternative Architecture for Information in Digital Libraries Onno W. Purbo
1-1 Chapter 1 Databases and Database Users 1.1 Introduction 1.2 An Example 1.3 Characteristics of the Database Approach 1.4 Actors on the Scene 1.5 Workers.
File and Database Design Class 22. File and database design: 1. Choosing the storage format for each attribute from the logical data model. 2. Grouping.
Metadata By N.Gopinath AP/CSE Metadata and it’s role in the lifecycle. The collection, maintenance, and deployment of metadata Metadata and tool integration.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
Transportation Agenda 77. Transportation About Columns Each file in a library and item in a list has properties For example, a Word document can have.
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
Database Planning Database Design Normalization.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
SQL Basics Review Reviewing what we’ve learned so far…….
Databases and DBMSs Todd S. Bacastow January
NOSQL Data Models.
Introduction To DBMS.
Datab ase Systems Week 1 by Zohaib Jan.
Outline Types of Databases and Database Applications Basic Definitions
MongoDB Er. Shiva K. Shrestha ME Computer, NCIT
Chapter 12 Information Systems.
9/22/2018.
Ben Burbridge, Rebecca Jones, Hilary Newman Product Development
Accounting System Design
Teaching slides Chapter 8.
Fundamentals of Databases
Data Model.
Accounting System Design
Your code is not just…your code
Your code is not just…your code
Presentation transcript:

App Dev with Documents, their Schemas and Relationships Tugdual Grall Technical Evangelist

Agenda More about aggregates and JSON ­What are schemas in a Document Database? The modeling behind our sample database ­Document structure, metadata in Couchbase Server ­An example of how to handle new requirements as needed ­Addressing concurrent modifications to documents

Flexible Schema

Documents and Schema Couchbase is not schema-less, documents have an implicit schema. We’re going to be big in Japan!

Schema Updates: Techniques Add the additional fields to new documents as they arrive ­Clearly, comes with an application level upgrade Define a sane default for this new field for record retrievals where the record doesn’t exist ­Example: adding loyalty points to the receipt- default to 0 points May need to incorporate fields to assist with processing:  A docType for use in control processing: “docType”: “receipt” ­Versioning of documents for application to upgrade a document

Document Structure, Extending Documents

JSON Documents Map more closely to your application’s external API CRUD Operations, lightweight schema Stored under an identifier key { “fields” : [“with basic types”, , true], “like” : “your favorite language” } client.set(“mydocumentid”, myDocument); mySavedDocument = client.get(“mydocumentid”);

Meta + Document Body { "brewery": "New Belgium Brewing", "name": "1554 Enlightened Black Ale", "abv": 5.5, "description": "Born of a flood...", "category": "Belgian and French Ale", "style": "Other Belgian-Style Ales", "updated": " :00:20" } { "id" : "beer_Enlightened_Black_Ale ”,... { Document user data, can be anything unique ID Metadata identifier, expiration, etc “ vintage ” date format from an SQL dump >_<

Handling New Requirements

Have you ever… Needed to update your schema in a large database? ­It can quite literally take months. Needed to go re-visit the data model with the team because requirements changed? ­Happens frequently, and can frequently end up using a separate database, then a challenge to keep data linked. ­Things like Rails migrations are awesome ways to address this problem, but it’s better to not need to do it at all.

Beer sample database The beer database is based on this kind of flexible schema ­Not all beers have all attributes and some may have unique attributes ­Still, there tends to be a common schema, since they came from the same application Different document types ­While all are JSON, there do tend to be different entity types represented in our set of JSON. Common approach is to add an attribute to define type, such as “type”: “beer”. Breweries and Beers Document relationships ­While it’s not a relational database, there are relationships: Beers, Breweries, Locations and others yet to be added. Constraints are enforced in most real world applications at the app level, not the database level.

Let ’ s Add Comments and Ratings to the Beer Challenge linking items together Whether to grow an existing item or store independent documents No transactionality between documents! I give that a 5! good w/ burgers tastes like college! { "brewery": "New Belgium Brewing", "name": "1554 Enlightened Black Ale", "abv": 5.5, "description": "Born of a flood...", "category": "Belgian and French Ale", "style": "Other Belgian-Style Ales", "updated": " :00:20" }

Let ’ s Add Comments and Ratings to the Beer We ’ ll put comments in their own document And add the ratings to the beer document itself. { "type": "comment", "about_id": "beer_Enlightened_Black_Ale", "user_id": 525, "text": "tastes like college!", "updated": " :00:20" } I give that a 5! { "brewery": "New Belgium Brewing", "name": "1554 Enlightened Black Ale", "abv": 5.5, "description": "Born of a flood...", "category": "Belgian and French Ale", "style": "Other Belgian-Style Ales", "updated” : " :00:20", “ ratings ” : { “ 525 ” : 5, “ 30 ” : 4, “ 1044 ” : 2 }, “ comments ” : [ “ f1e62 ”, “ 6ad8c ” ] }

Do it: save the comment document Set at the id “ u525_c1 ” client.set(“ u525_c1 ”,{ }); create a new document { "id": " u525_c1 " } "type": "comment", "about_id”: "beer_Enlightened_Black_Ale", "user_id": 525, "text": "tastes like college!", "updated": " :00:20"

Link between comments and beers "name": "1554 Enlightened Black Ale", "abv": 5.5, "description": "Born of a flood...", "category": "Belgian and French Ale", "style": "Other Belgian-Style Ales", "updated": " :00:20", “ ratings ” : { “ 525 ” : 5, “ 30 ” : 4, “ 1044 ” : 2 }, “ comment_ids ” : [ “ u525_c1 ”, “ 6ad8c ” ] } 16 { "type": "comment", "about_id": "beer_Enlightened_Black_Ale", "user_id": 525, "text": "tastes like college!", "updated": " :00:20" } link to comments link to beer { "id": " u525_c1 " }

How to: look up comments from a beer SERIALIZED LOOP beer = client.get(“beer:A_cold_one”); beer.comment_ids.each { |id| comments.push(client.get(id)); } ASYNC VIEW QUERY comments = client.asyncGet(“myapp”,“by_comment_on”, {:key => “beer:A_cold_one”}); FAST MULTI-KEY LOOKUP beer = client.get(“beer:A_cold_one”); comments = client.multiGet(beer.comment_ids)

Concurrency Problem: Adding Ratings Other users are ratings beers also, so we use a CAS update  we don ’ t want to accidentally overwrite another users rating that is being saved at the same time as ours Retry the operation, if appropriate ­Also useful if you have internal structure that you want to maintain cb.cas("mykey") do |doc| doc["ratings"][current_user.id] = my_rating doc end Actor 1 Actor 2 Couchbase Server CAS mismatch & retry Success

Object Graph With Shared Interactive Updates Challenge: higher level data structures Objects shared across multiple users Mixed object sets (updating some private and some shared objects) Only marginally related figure courtesy of

Get With Lock (GETL) Often referred to as “ GETL ” Pessimistic concurrency control Locks have a short TTL Locks released with CAS operations Useful when working with object graphs Still only marginally related figure courtesy of

Document Structure Relationships Couchbase stores metadata with documents. Documents do have relationships, even though it is not relational. Extending your Document Requirements Extending your document structure is simple, but you may need to consider a few things when deciding how to do so. In document, or separate documents? Couchbase in Summary 21 Couchbase has Flexible Schema Schema is implicit per document. This makes it easier to model entities.

Q&A

Thanks!