SlideShare a Scribd company logo
1 of 49
Download to read offline
Relationships are Hard:
NoSQL Data Modeling
BY: CURT GRATZ
‣ Which NoSQL database is the
cats pajamas
‣ Why you should never use a
RDBMS again
‣ Map/Reduce, Views, or other
NoSQL query options
‣ How to prove the theory of
relativity
What we won’t be covering
‣ Where NoSQL came from
‣ Some database theory
‣ When its good or not good to use NoSQL
‣ A few Key Patterns
‣ A few Data Modeling Patterns
‣ Modeling a simple e-commerce platform with NoSQL
What we will be covering
‣ Husband
‣ Dad
‣ Coach
‣ Youth Leader
‣ Co-Owner of Computer Know How
‣ Member of Team ColdBox
‣ Open CFML Foundation Board
The Obligatory Who Am I?
#noSQL (Johan Oskarsson)
It’s Just a Buzz Word
What does it mean?
Brief History
‣ Characteristics
‣ non-relational
‣ open-source (some)
‣ cluster-friendly (some)
‣ 21st Century
‣ schema less
Brief History
‣ Types
‣ key/value
‣ MemcacheDB
‣ document
‣ Couchbase, Redis,
MongoDB
‣ column
‣ Cassandra, HBase
‣ graph
‣ neo4j, InfiniteGraph
CAP THEOREM
PICK TWO
CAP Theorem (pick 2 please)
‣ Consistency
‣ all nodes see the same data at the same
time
‣ Availability
‣ a guarantee that every request receives a
response about whether it succeeded or
failed
‣ Partition Tolerance
‣ the system continues to operate despite
arbitrary message loss or failure of part of
the system
ACID
‣ Atomicity
‣ All or Nothing (transactions)
‣ Consistency
‣ data is never violated (constraints.
validation, etc)
‣ Isolation
‣ operations must not see data from other
non-finished operations(locks)
‣ Durability
‣ state of data is persisted when operation
finishes (server crash protection)
MongoDB is Web Scale
BASE
‣ Basically Available
‣ Should be up, but not guaranteed
‣ Soft state
‣ changes happening even without
input
‣ Eventual consistency
‣ At some point your changes will
be consistent
‣ Less data duplication
‣ Less storage space
‣ Higher data consistency/integrity
‣ Easy to query
‣ Updates are EASY
Normalisation
Normalisation
userID username groupID statusID
1 wither 1 1
2 zombie 1 1
3 slime 2 2
4 enderman 1 2
statusID status
1 active
2 inactive
groupID group
1 monster
2 block
reference
reference
‣ Minimize the need for joins
‣ Reduce the number of indexes
‣ Reduce the number of relationships
‣ Updates are harder (slower)
Denormalisation
Denormalisation
userID username group status
1 wither monster active
2 zombie monster active
3 slime block inactive
4 enderman monster inactive
Keying in NoSQL
‣ Predictable Keys
‣ Counter-ID
‣ Lookup Pattern
‣ Counter/Lookup
combined
‣ No built in key mechanisms in most NoSQL
‣ Use a Unique value for key (email, usernames, sku, isbn, etc)
‣ Users
‣ u::ender@dragon.com
‣ u::enderdragon
‣ Products
‣ p::231-0321404314123 (isbn)
‣ Unpredictable Keys (GUID, UUID, etc) require Views (Map-Reduce
indexes) to find their documents
Predictable Keys
‣ Similar to IDENTITY column in RDBMS
‣ Creating New Documents is a pair of operations in your
application, increment and add
‣ initialize one Key as an Atomic Counter (on app start)
‣ increment counter and save new value
‣ id = client.incr(“blog::slug::comment_count”)
‣ Use the id as component of the key for the new document
‣ client.add(“blog::slug::c” + id, comment_data)
Counter-ID Keys
‣ Create simple documents that has referential data (Key) to primary
documents
‣ Primary Document u::abc123-12345-4312
‣ Lookup Document u::iron@golem.com = {u::abc123-12345-4312}
‣ Lookup documents aren’t JSON, they should be the key as a string so
you skip the JSON parsing
‣ Requires two get operations, first the lookup doc, then the primary doc
‣ key = client.get(“u::iron@golem.com”)
‣ doc = client.get(key)
Lookup Pattern
RDBMS vs NoSQL
Gets slower with
growth
userData = {

	 "name":"Cave Spider",

	 "facebookID":100167,

	 "email":"cave@spider.com",

	 "createdAt":"5/1/2019 2:30am"

};

uid = app.incr("u::count");

app.add("u::"+uid, userData)

add.set("em::"+userData.email,uid);;

add.set("fb::"+userData.facebookID,uid);

//Get User By FacebookID

uid = app.get("fb::100167");

userData = app.get("u::"+uid);

//Get User By Email

uid = app.get("em::cave@spider.com");

userData = app.get("u::"+uid);

INSERT INTO Users

(name,facebookID,email,createdAt)

VALUES (

'Cave Spider',100167,'cave@spider.com'

,'5/1/2019 2:30am'

);

--Get user by FacebookID

SELECT * FROM Users

WHERE facebookID = 100167

--Get user by Email

SELECT * FROM Users

WHERE email = 'cave@spider.com'
Embedding vs Linking
‣ Embed copies of frequently accessed related
objects
‣ Users friends into the users profile “friendlist”
‣ Allows for quick fetch of users friendlist and all friend
profiles in one read
‣ Denormalized
Embedding
‣ Can cause data duplication
‣ Updates are painful
‣ Easy to become inconsistent
Embedding
‣ user.friendsList = [ “user1”, “user2”]
‣ If you use linking you have to get the linked data
yourself
‣ The DB Driver doesn’t do it for you, you can
delete a link without the reference deleting
Linking
‣ Embedding when
‣ there are no or few updates of the data
‣ caching
‣ when time-to-live is very restricted
‣ Otherwise link the related data
Embedding vs Linking
‣ Logging data
‣ Lots of records
‣ Little need to access all the children
Parent-Referencing
‣ One - To - Few = Embedding
‣ One - To - Many = Linking
‣ One - To - Squillions = Parent Referencing
Rule of Thumb
Making a mental shift
‣ In SQL we tend to want to avoid hitting the database as
much as possible
‣ we know that its costly when tying up connection pools and
overloading db servers
‣ even with indexing SQL still gets bogged down by complex joins
and huge indexes
‣ In noSQL gets and sets ARE FAST, and not a bottleneck, this
is hard for many people to accept and absorb at first
Making a mental shift
Gets and Sets are fast…
Gets and Sets are fast…
Gets and Sets are fast…
Gets and Sets are fast…
‣ Denormalization takes getting used to
‣ Data integrity
‣ Schema changes are easy
Making a mental shift
Simple e-Commerce Example
‣ Store order history (including price at the time
of order)
‣ Keep product inventory
‣ Know the number of orders per product
‣ Know the number of orders per customer
‣ Human readable category URLs
Specs
‣ Email as key
‣ Embedded addresses
‣ Orders linking
Customer
‣ slug as key
‣ Products count
‣ Orders count
‣ Products parent referencing
Category
‣ SKU as key
‣ Orders count
‣ Inventory
‣ Categories linking
Product
‣ User Session ID as key
‣ Products Count
‣ Total
‣ Products embedded (partially)
‣ Status (active, completed, expired)
Cart
‣ Order Counter for Key
‣ Embed customer info
‣ Embed product info
‣ Totals
Order
‣ Set cart status to completed
‣ decrement inventory, adjust “inCart”
‣ create/update customer record
‣ add order counter ID to customer orders
‣ Update order counts on category and product
Order
‣ Workshop on NoSQL data model (Jan Steeman)
‣ Part 1 https://www.youtube.com/watch?v=EAeviDFkZL8
‣ Part 2 https://www.youtube.com/watch?v=fFGR1FBDpE4
‣ Introduction to NoSQL (Martin Folwer)
‣ https://www.youtube.com/watch?v=qI_g07C_Q5I
‣ Data modeling in key/value and document database
‣ http://openslava.sk/2014/Presentations/Data-modeling-in-KeyValue-and-Document-
Stores_Philipp-Fehre.pdf
‣ NoSQL data modeling techniques
‣ https://highlyscalable.wordpress.com/2012/03/01/nosql-data-modeling-techniques/
More Information
“Thank you.”
–hold up applause sign here
‣ Email - gratzc@compknowhow.com
‣ Blog - http://www.compknowhow.com/blog/
‣ Twitter - gratzc
‣ Skype - gratzc
‣ League of Legends - gratzc
Contact Info

More Related Content

Viewers also liked

Getting started with mobile application development
Getting started with mobile application developmentGetting started with mobile application development
Getting started with mobile application developmentColdFusionConference
 
Multiply like rabbits with rabbit mq
Multiply like rabbits with rabbit mqMultiply like rabbits with rabbit mq
Multiply like rabbits with rabbit mqColdFusionConference
 
Understanding bdd and tdd with lego
Understanding bdd and tdd with legoUnderstanding bdd and tdd with lego
Understanding bdd and tdd with legoColdFusionConference
 
Bring Order to the Chaos: Take the MVC Plunge
Bring Order to the Chaos: Take the MVC PlungeBring Order to the Chaos: Take the MVC Plunge
Bring Order to the Chaos: Take the MVC PlungeColdFusionConference
 
Safeguarding applications from cyber attacks
Safeguarding applications from cyber attacksSafeguarding applications from cyber attacks
Safeguarding applications from cyber attacksColdFusionConference
 
Dev objecttives-2015 auth-auth-fine-grained-slides
Dev objecttives-2015 auth-auth-fine-grained-slidesDev objecttives-2015 auth-auth-fine-grained-slides
Dev objecttives-2015 auth-auth-fine-grained-slidesColdFusionConference
 
Refactor Large applications with Backbone
Refactor Large applications with BackboneRefactor Large applications with Backbone
Refactor Large applications with BackboneColdFusionConference
 

Viewers also liked (20)

CFML Sessions For Dummies
CFML Sessions For DummiesCFML Sessions For Dummies
CFML Sessions For Dummies
 
I am-designer
I am-designerI am-designer
I am-designer
 
How we rest
How we restHow we rest
How we rest
 
Getting started with mobile application development
Getting started with mobile application developmentGetting started with mobile application development
Getting started with mobile application development
 
Test box bdd
Test box bddTest box bdd
Test box bdd
 
Locking Down CF Servers
Locking Down CF ServersLocking Down CF Servers
Locking Down CF Servers
 
Multiply like rabbits with rabbit mq
Multiply like rabbits with rabbit mqMultiply like rabbits with rabbit mq
Multiply like rabbits with rabbit mq
 
Cold fusion is racecar fast
Cold fusion is racecar fastCold fusion is racecar fast
Cold fusion is racecar fast
 
Understanding bdd and tdd with lego
Understanding bdd and tdd with legoUnderstanding bdd and tdd with lego
Understanding bdd and tdd with lego
 
Preso slidedeck
Preso slidedeckPreso slidedeck
Preso slidedeck
 
Open Yourself to Closures
Open Yourself to ClosuresOpen Yourself to Closures
Open Yourself to Closures
 
Bring Order to the Chaos: Take the MVC Plunge
Bring Order to the Chaos: Take the MVC PlungeBring Order to the Chaos: Take the MVC Plunge
Bring Order to the Chaos: Take the MVC Plunge
 
Safeguarding applications from cyber attacks
Safeguarding applications from cyber attacksSafeguarding applications from cyber attacks
Safeguarding applications from cyber attacks
 
Command box
Command boxCommand box
Command box
 
Rest ful tools for lazy experts
Rest ful tools for lazy expertsRest ful tools for lazy experts
Rest ful tools for lazy experts
 
Dev objecttives-2015 auth-auth-fine-grained-slides
Dev objecttives-2015 auth-auth-fine-grained-slidesDev objecttives-2015 auth-auth-fine-grained-slides
Dev objecttives-2015 auth-auth-fine-grained-slides
 
Web hackingtools 2015
Web hackingtools 2015Web hackingtools 2015
Web hackingtools 2015
 
This is how we REST
This is how we RESTThis is how we REST
This is how we REST
 
Refactor Large applications with Backbone
Refactor Large applications with BackboneRefactor Large applications with Backbone
Refactor Large applications with Backbone
 
ColdFusion Craftsmanship
ColdFusion CraftsmanshipColdFusion Craftsmanship
ColdFusion Craftsmanship
 

Similar to Relationships are hard

ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdfITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdfOrtus Solutions, Corp
 
SQL to NoSQL: Top 6 Questions
SQL to NoSQL: Top 6 QuestionsSQL to NoSQL: Top 6 Questions
SQL to NoSQL: Top 6 QuestionsMike Broberg
 
Introduction to NoSQL Database
Introduction to NoSQL DatabaseIntroduction to NoSQL Database
Introduction to NoSQL DatabaseMohammad Alghanem
 
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)Ontico
 
Coding for beginners - Future Assembly 2016
Coding for beginners - Future Assembly 2016Coding for beginners - Future Assembly 2016
Coding for beginners - Future Assembly 2016Milly Schmidt
 
Evolution of the DBA to Data Platform Administrator/Specialist
Evolution of the DBA to Data Platform Administrator/SpecialistEvolution of the DBA to Data Platform Administrator/Specialist
Evolution of the DBA to Data Platform Administrator/SpecialistTony Rogerson
 
CData Data Today: A Developer's Dilemma
CData Data Today: A Developer's DilemmaCData Data Today: A Developer's Dilemma
CData Data Today: A Developer's DilemmaJerod Johnson
 
No SQL, No Problem: Use Azure DocumentDB
No SQL, No Problem: Use Azure DocumentDBNo SQL, No Problem: Use Azure DocumentDB
No SQL, No Problem: Use Azure DocumentDBKen Cenerelli
 
Querying NoSQL with SQL: HAVING Your JSON Cake and SELECTing it too
Querying NoSQL with SQL: HAVING Your JSON Cake and SELECTing it tooQuerying NoSQL with SQL: HAVING Your JSON Cake and SELECTing it too
Querying NoSQL with SQL: HAVING Your JSON Cake and SELECTing it tooAll Things Open
 
Open Source Lambda Architecture with Hadoop, Kafka, Samza and Druid
Open Source Lambda Architecture with Hadoop, Kafka, Samza and DruidOpen Source Lambda Architecture with Hadoop, Kafka, Samza and Druid
Open Source Lambda Architecture with Hadoop, Kafka, Samza and DruidDataWorks Summit
 
Neo4j Makes Graphs Easy
Neo4j Makes Graphs EasyNeo4j Makes Graphs Easy
Neo4j Makes Graphs EasyNeo4j
 
SplunkApplicationLoggingBestPractices_Template_2.3.pdf
SplunkApplicationLoggingBestPractices_Template_2.3.pdfSplunkApplicationLoggingBestPractices_Template_2.3.pdf
SplunkApplicationLoggingBestPractices_Template_2.3.pdfTuynNguyn819213
 
SSIS Monitoring Deep Dive
SSIS Monitoring Deep DiveSSIS Monitoring Deep Dive
SSIS Monitoring Deep DiveDavide Mauri
 
JFall 2011 no sql workshop
JFall 2011 no sql workshopJFall 2011 no sql workshop
JFall 2011 no sql workshopfvanvollenhoven
 
NoSQL Data Modeling using Couchbase
NoSQL Data Modeling using CouchbaseNoSQL Data Modeling using Couchbase
NoSQL Data Modeling using CouchbaseBrant Burnett
 

Similar to Relationships are hard (20)

ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdfITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
 
Multi model-databases
Multi model-databasesMulti model-databases
Multi model-databases
 
Multi model-databases
Multi model-databasesMulti model-databases
Multi model-databases
 
SQL to NoSQL: Top 6 Questions
SQL to NoSQL: Top 6 QuestionsSQL to NoSQL: Top 6 Questions
SQL to NoSQL: Top 6 Questions
 
Introduction to NoSQL Database
Introduction to NoSQL DatabaseIntroduction to NoSQL Database
Introduction to NoSQL Database
 
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)
 
Coding for beginners - Future Assembly 2016
Coding for beginners - Future Assembly 2016Coding for beginners - Future Assembly 2016
Coding for beginners - Future Assembly 2016
 
Evolution of the DBA to Data Platform Administrator/Specialist
Evolution of the DBA to Data Platform Administrator/SpecialistEvolution of the DBA to Data Platform Administrator/Specialist
Evolution of the DBA to Data Platform Administrator/Specialist
 
Database basics
Database basicsDatabase basics
Database basics
 
Some NoSQL
Some NoSQLSome NoSQL
Some NoSQL
 
CData Data Today: A Developer's Dilemma
CData Data Today: A Developer's DilemmaCData Data Today: A Developer's Dilemma
CData Data Today: A Developer's Dilemma
 
No SQL, No Problem: Use Azure DocumentDB
No SQL, No Problem: Use Azure DocumentDBNo SQL, No Problem: Use Azure DocumentDB
No SQL, No Problem: Use Azure DocumentDB
 
Querying NoSQL with SQL: HAVING Your JSON Cake and SELECTing it too
Querying NoSQL with SQL: HAVING Your JSON Cake and SELECTing it tooQuerying NoSQL with SQL: HAVING Your JSON Cake and SELECTing it too
Querying NoSQL with SQL: HAVING Your JSON Cake and SELECTing it too
 
Open Source Lambda Architecture with Hadoop, Kafka, Samza and Druid
Open Source Lambda Architecture with Hadoop, Kafka, Samza and DruidOpen Source Lambda Architecture with Hadoop, Kafka, Samza and Druid
Open Source Lambda Architecture with Hadoop, Kafka, Samza and Druid
 
Neo4j Makes Graphs Easy
Neo4j Makes Graphs EasyNeo4j Makes Graphs Easy
Neo4j Makes Graphs Easy
 
SplunkApplicationLoggingBestPractices_Template_2.3.pdf
SplunkApplicationLoggingBestPractices_Template_2.3.pdfSplunkApplicationLoggingBestPractices_Template_2.3.pdf
SplunkApplicationLoggingBestPractices_Template_2.3.pdf
 
SSIS Monitoring Deep Dive
SSIS Monitoring Deep DiveSSIS Monitoring Deep Dive
SSIS Monitoring Deep Dive
 
JFall 2011 no sql workshop
JFall 2011 no sql workshopJFall 2011 no sql workshop
JFall 2011 no sql workshop
 
NOSQL Overview
NOSQL OverviewNOSQL Overview
NOSQL Overview
 
NoSQL Data Modeling using Couchbase
NoSQL Data Modeling using CouchbaseNoSQL Data Modeling using Couchbase
NoSQL Data Modeling using Couchbase
 

More from ColdFusionConference

Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server DatabasesColdFusionConference
 
API Economy, Realizing the Business Value of APIs
API Economy, Realizing the Business Value of APIsAPI Economy, Realizing the Business Value of APIs
API Economy, Realizing the Business Value of APIsColdFusionConference
 
Crafting ColdFusion Applications like an Architect
Crafting ColdFusion Applications like an ArchitectCrafting ColdFusion Applications like an Architect
Crafting ColdFusion Applications like an ArchitectColdFusionConference
 
Security And Access Control For APIS using CF API Manager
Security And Access Control For APIS using CF API ManagerSecurity And Access Control For APIS using CF API Manager
Security And Access Control For APIS using CF API ManagerColdFusionConference
 
Monetizing Business Models: ColdFusion and APIS
Monetizing Business Models: ColdFusion and APISMonetizing Business Models: ColdFusion and APIS
Monetizing Business Models: ColdFusion and APISColdFusionConference
 
Become a Security Rockstar with ColdFusion 2016
Become a Security Rockstar with ColdFusion 2016Become a Security Rockstar with ColdFusion 2016
Become a Security Rockstar with ColdFusion 2016ColdFusionConference
 
Developer Insights for Application Upgrade to ColdFusion 2016
Developer Insights for Application Upgrade to ColdFusion 2016Developer Insights for Application Upgrade to ColdFusion 2016
Developer Insights for Application Upgrade to ColdFusion 2016ColdFusionConference
 
ColdFusion Keynote: Building the Agile Web Since 1995
ColdFusion Keynote: Building the Agile Web Since 1995ColdFusion Keynote: Building the Agile Web Since 1995
ColdFusion Keynote: Building the Agile Web Since 1995ColdFusionConference
 
Super Fast Application development with Mura CMS
Super Fast Application development with Mura CMSSuper Fast Application development with Mura CMS
Super Fast Application development with Mura CMSColdFusionConference
 
Build your own secure and real-time dashboard for mobile and web
Build your own secure and real-time dashboard for mobile and webBuild your own secure and real-time dashboard for mobile and web
Build your own secure and real-time dashboard for mobile and webColdFusionConference
 

More from ColdFusionConference (20)

Api manager preconference
Api manager preconferenceApi manager preconference
Api manager preconference
 
Cf ppt vsr
Cf ppt vsrCf ppt vsr
Cf ppt vsr
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
 
API Economy, Realizing the Business Value of APIs
API Economy, Realizing the Business Value of APIsAPI Economy, Realizing the Business Value of APIs
API Economy, Realizing the Business Value of APIs
 
Don't just pdf, Smart PDF
Don't just pdf, Smart PDFDon't just pdf, Smart PDF
Don't just pdf, Smart PDF
 
Crafting ColdFusion Applications like an Architect
Crafting ColdFusion Applications like an ArchitectCrafting ColdFusion Applications like an Architect
Crafting ColdFusion Applications like an Architect
 
Security And Access Control For APIS using CF API Manager
Security And Access Control For APIS using CF API ManagerSecurity And Access Control For APIS using CF API Manager
Security And Access Control For APIS using CF API Manager
 
Monetizing Business Models: ColdFusion and APIS
Monetizing Business Models: ColdFusion and APISMonetizing Business Models: ColdFusion and APIS
Monetizing Business Models: ColdFusion and APIS
 
Become a Security Rockstar with ColdFusion 2016
Become a Security Rockstar with ColdFusion 2016Become a Security Rockstar with ColdFusion 2016
Become a Security Rockstar with ColdFusion 2016
 
ColdFusion in Transit action
ColdFusion in Transit actionColdFusion in Transit action
ColdFusion in Transit action
 
Developer Insights for Application Upgrade to ColdFusion 2016
Developer Insights for Application Upgrade to ColdFusion 2016Developer Insights for Application Upgrade to ColdFusion 2016
Developer Insights for Application Upgrade to ColdFusion 2016
 
Where is cold fusion headed
Where is cold fusion headedWhere is cold fusion headed
Where is cold fusion headed
 
ColdFusion Keynote: Building the Agile Web Since 1995
ColdFusion Keynote: Building the Agile Web Since 1995ColdFusion Keynote: Building the Agile Web Since 1995
ColdFusion Keynote: Building the Agile Web Since 1995
 
Instant ColdFusion with Vagrant
Instant ColdFusion with VagrantInstant ColdFusion with Vagrant
Instant ColdFusion with Vagrant
 
Restful services with ColdFusion
Restful services with ColdFusionRestful services with ColdFusion
Restful services with ColdFusion
 
Super Fast Application development with Mura CMS
Super Fast Application development with Mura CMSSuper Fast Application development with Mura CMS
Super Fast Application development with Mura CMS
 
Build your own secure and real-time dashboard for mobile and web
Build your own secure and real-time dashboard for mobile and webBuild your own secure and real-time dashboard for mobile and web
Build your own secure and real-time dashboard for mobile and web
 
Why Everyone else writes bad code
Why Everyone else writes bad codeWhy Everyone else writes bad code
Why Everyone else writes bad code
 
Securing applications
Securing applicationsSecuring applications
Securing applications
 
Testing automaton
Testing automatonTesting automaton
Testing automaton
 

Recently uploaded

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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 WorkerThousandEyes
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 

Recently uploaded (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

Relationships are hard

  • 1. Relationships are Hard: NoSQL Data Modeling BY: CURT GRATZ
  • 2. ‣ Which NoSQL database is the cats pajamas ‣ Why you should never use a RDBMS again ‣ Map/Reduce, Views, or other NoSQL query options ‣ How to prove the theory of relativity What we won’t be covering
  • 3. ‣ Where NoSQL came from ‣ Some database theory ‣ When its good or not good to use NoSQL ‣ A few Key Patterns ‣ A few Data Modeling Patterns ‣ Modeling a simple e-commerce platform with NoSQL What we will be covering
  • 4. ‣ Husband ‣ Dad ‣ Coach ‣ Youth Leader ‣ Co-Owner of Computer Know How ‣ Member of Team ColdBox ‣ Open CFML Foundation Board The Obligatory Who Am I?
  • 6. It’s Just a Buzz Word
  • 7. What does it mean?
  • 8. Brief History ‣ Characteristics ‣ non-relational ‣ open-source (some) ‣ cluster-friendly (some) ‣ 21st Century ‣ schema less
  • 9. Brief History ‣ Types ‣ key/value ‣ MemcacheDB ‣ document ‣ Couchbase, Redis, MongoDB ‣ column ‣ Cassandra, HBase ‣ graph ‣ neo4j, InfiniteGraph
  • 11. CAP Theorem (pick 2 please) ‣ Consistency ‣ all nodes see the same data at the same time ‣ Availability ‣ a guarantee that every request receives a response about whether it succeeded or failed ‣ Partition Tolerance ‣ the system continues to operate despite arbitrary message loss or failure of part of the system
  • 12. ACID ‣ Atomicity ‣ All or Nothing (transactions) ‣ Consistency ‣ data is never violated (constraints. validation, etc) ‣ Isolation ‣ operations must not see data from other non-finished operations(locks) ‣ Durability ‣ state of data is persisted when operation finishes (server crash protection)
  • 13. MongoDB is Web Scale
  • 14. BASE ‣ Basically Available ‣ Should be up, but not guaranteed ‣ Soft state ‣ changes happening even without input ‣ Eventual consistency ‣ At some point your changes will be consistent
  • 15.
  • 16. ‣ Less data duplication ‣ Less storage space ‣ Higher data consistency/integrity ‣ Easy to query ‣ Updates are EASY Normalisation
  • 17. Normalisation userID username groupID statusID 1 wither 1 1 2 zombie 1 1 3 slime 2 2 4 enderman 1 2 statusID status 1 active 2 inactive groupID group 1 monster 2 block reference reference
  • 18. ‣ Minimize the need for joins ‣ Reduce the number of indexes ‣ Reduce the number of relationships ‣ Updates are harder (slower) Denormalisation
  • 19. Denormalisation userID username group status 1 wither monster active 2 zombie monster active 3 slime block inactive 4 enderman monster inactive
  • 20. Keying in NoSQL ‣ Predictable Keys ‣ Counter-ID ‣ Lookup Pattern ‣ Counter/Lookup combined
  • 21. ‣ No built in key mechanisms in most NoSQL ‣ Use a Unique value for key (email, usernames, sku, isbn, etc) ‣ Users ‣ u::ender@dragon.com ‣ u::enderdragon ‣ Products ‣ p::231-0321404314123 (isbn) ‣ Unpredictable Keys (GUID, UUID, etc) require Views (Map-Reduce indexes) to find their documents Predictable Keys
  • 22. ‣ Similar to IDENTITY column in RDBMS ‣ Creating New Documents is a pair of operations in your application, increment and add ‣ initialize one Key as an Atomic Counter (on app start) ‣ increment counter and save new value ‣ id = client.incr(“blog::slug::comment_count”) ‣ Use the id as component of the key for the new document ‣ client.add(“blog::slug::c” + id, comment_data) Counter-ID Keys
  • 23. ‣ Create simple documents that has referential data (Key) to primary documents ‣ Primary Document u::abc123-12345-4312 ‣ Lookup Document u::iron@golem.com = {u::abc123-12345-4312} ‣ Lookup documents aren’t JSON, they should be the key as a string so you skip the JSON parsing ‣ Requires two get operations, first the lookup doc, then the primary doc ‣ key = client.get(“u::iron@golem.com”) ‣ doc = client.get(key) Lookup Pattern
  • 24. RDBMS vs NoSQL Gets slower with growth userData = { "name":"Cave Spider", "facebookID":100167, "email":"cave@spider.com", "createdAt":"5/1/2019 2:30am" }; uid = app.incr("u::count"); app.add("u::"+uid, userData) add.set("em::"+userData.email,uid);; add.set("fb::"+userData.facebookID,uid); //Get User By FacebookID uid = app.get("fb::100167"); userData = app.get("u::"+uid); //Get User By Email uid = app.get("em::cave@spider.com"); userData = app.get("u::"+uid); INSERT INTO Users (name,facebookID,email,createdAt) VALUES ( 'Cave Spider',100167,'cave@spider.com' ,'5/1/2019 2:30am' ); --Get user by FacebookID SELECT * FROM Users WHERE facebookID = 100167 --Get user by Email SELECT * FROM Users WHERE email = 'cave@spider.com'
  • 26. ‣ Embed copies of frequently accessed related objects ‣ Users friends into the users profile “friendlist” ‣ Allows for quick fetch of users friendlist and all friend profiles in one read ‣ Denormalized Embedding
  • 27. ‣ Can cause data duplication ‣ Updates are painful ‣ Easy to become inconsistent Embedding
  • 28. ‣ user.friendsList = [ “user1”, “user2”] ‣ If you use linking you have to get the linked data yourself ‣ The DB Driver doesn’t do it for you, you can delete a link without the reference deleting Linking
  • 29. ‣ Embedding when ‣ there are no or few updates of the data ‣ caching ‣ when time-to-live is very restricted ‣ Otherwise link the related data Embedding vs Linking
  • 30. ‣ Logging data ‣ Lots of records ‣ Little need to access all the children Parent-Referencing
  • 31. ‣ One - To - Few = Embedding ‣ One - To - Many = Linking ‣ One - To - Squillions = Parent Referencing Rule of Thumb
  • 33. ‣ In SQL we tend to want to avoid hitting the database as much as possible ‣ we know that its costly when tying up connection pools and overloading db servers ‣ even with indexing SQL still gets bogged down by complex joins and huge indexes ‣ In noSQL gets and sets ARE FAST, and not a bottleneck, this is hard for many people to accept and absorb at first Making a mental shift
  • 34. Gets and Sets are fast…
  • 35. Gets and Sets are fast…
  • 36. Gets and Sets are fast…
  • 37. Gets and Sets are fast…
  • 38. ‣ Denormalization takes getting used to ‣ Data integrity ‣ Schema changes are easy Making a mental shift
  • 40. ‣ Store order history (including price at the time of order) ‣ Keep product inventory ‣ Know the number of orders per product ‣ Know the number of orders per customer ‣ Human readable category URLs Specs
  • 41. ‣ Email as key ‣ Embedded addresses ‣ Orders linking Customer
  • 42. ‣ slug as key ‣ Products count ‣ Orders count ‣ Products parent referencing Category
  • 43. ‣ SKU as key ‣ Orders count ‣ Inventory ‣ Categories linking Product
  • 44. ‣ User Session ID as key ‣ Products Count ‣ Total ‣ Products embedded (partially) ‣ Status (active, completed, expired) Cart
  • 45. ‣ Order Counter for Key ‣ Embed customer info ‣ Embed product info ‣ Totals Order
  • 46. ‣ Set cart status to completed ‣ decrement inventory, adjust “inCart” ‣ create/update customer record ‣ add order counter ID to customer orders ‣ Update order counts on category and product Order
  • 47. ‣ Workshop on NoSQL data model (Jan Steeman) ‣ Part 1 https://www.youtube.com/watch?v=EAeviDFkZL8 ‣ Part 2 https://www.youtube.com/watch?v=fFGR1FBDpE4 ‣ Introduction to NoSQL (Martin Folwer) ‣ https://www.youtube.com/watch?v=qI_g07C_Q5I ‣ Data modeling in key/value and document database ‣ http://openslava.sk/2014/Presentations/Data-modeling-in-KeyValue-and-Document- Stores_Philipp-Fehre.pdf ‣ NoSQL data modeling techniques ‣ https://highlyscalable.wordpress.com/2012/03/01/nosql-data-modeling-techniques/ More Information
  • 48. “Thank you.” –hold up applause sign here
  • 49. ‣ Email - gratzc@compknowhow.com ‣ Blog - http://www.compknowhow.com/blog/ ‣ Twitter - gratzc ‣ Skype - gratzc ‣ League of Legends - gratzc Contact Info