SlideShare a Scribd company logo
Three things you need to know about document
data modelling
Matthew Revell
Director of Developer Advocacy, Couchbase
1
We are still learning
2
©2014 Couchbase Inc.
Book learnin'
3
Our access pattern influences the data model
4
©2014 Couchbase Inc.
Ad-hoc versus predictable
5
Application layer computation Off-load computation
Predictable queries Key-value: pre-computed answers Views
Ad-hoc queries N1QL and key-value with manual
indexes
N1QL and views
Modelling for key-value
6
©2014 Couchbase Inc.
Principles for key-value modelling
7
Pre-compute answers asynchronously
Store object state
Choose when to embed data and when to refer to it
Design your keys well
Pre-computing answers
8
©2014 Couchbase Inc.
We're used to asking questions
9
©2014 Couchbase Inc.
A library of answers
10
©2014 Couchbase Inc.
Answer-oriented databases
11
http://martinfowler.com/bliki/AggregateOrientedDatabase.html
©2014 Couchbase Inc.
Save the answers for later use
12
Embed or refer?
13
©2014 Couchbase Inc.
An e-commerce order
14
©2014 Couchbase Inc.
The same order as a document
15
©2014 Couchbase Inc.
The same order as a document
16
©2014 Couchbase Inc.
When to embed data
17
You should embed data when:
Speed trumps all else
Slow moving data
No duplication
Application layer can keep multiple copies of same data in
sync
©2014 Couchbase Inc.
When to referdata
18
You should refer to data when:
Consistency is a priority
The data has large growth potential
Key design
19
©2014 Couchbase Inc.
Three ways to build a key
20
Key design is as important as document design.
There are three broad types of keys:
Human readable/deterministic: e.g., an email address
Computer generated/random: e.g., a UUID
Compound: e.g., a UUID with a deterministic portion
©2014 Couchbase Inc.
Human readable/deterministic key
21
public class user {
private String name;
private String email;
private String streetAddress;
private String city;
private String country;
private String postCode;
private String telephone;
private Array orders;
private Array productsViewed;
}
{
"name": "Matthew Revell",
"address": "11-21 Paul Street",
"city": "London",
"postCode": "EC2A 4JU",
"telephone": "44-20-3837-9130",
"orders": [ 1, 9, 698, 32 ],
“productsViewed”: [8, 33, 99, 100]
}
Key: matthew@couchbase.com
©2014 Couchbase Inc.
Counter key pattern
22
Application
user_id = incr(“counter_key")
add(user_id, data)
Creating a new user
add(email_address, user_id)
Application
key = get("matthew@couchbase.com")
get(key)
Finding a user by email address
©2014 Couchbase Inc.
Multiple look-up documents
23
u::count
1001
u::1001
{ "name": “Matthew Revell",
"facebook_id": 16172910,
"email": “matthew@couchbase.com”,
“password”: ab02d#Jf02K
"created_at": "5/1/2012 2:30am",
“facebook_access_token”: xox0v2dje20,
“twitter_access_token”: 20jffieieaaixixj }
fb::16172910
1001
nflx::2939202
1001
twtr::2920283830
1001
em::matthew@couchbase.com
1001
em::matthew@understated.co.uk
1001
uname::mrevell
1001
©2014 Couchbase Inc.
Compound keys
u::1001
{
"name": "Matthew Revell",
"email": "matthew@couchbase.com",
"address": "11-21 Paul Street",
"city": "London",
"postCode": "EC2A 4JU",
"telephone": "44-20-3837-9130",
"orders": [ 1, 9, 698, 32 ],
“productsViewed”: [8, 33, 99, 100]
}
©2014 Couchbase Inc.
Compound keys
u::1001
{
"name": "Matthew Revell",
"email": "matthew@couchbase.com",
"address": "11-21 Paul Street",
"city": "London",
"postCode": "EC2A 4JU",
"telephone": "44-20-3837-9130",
"orders": [ 1, 9, 698, 32 ]
}
u::1001::productsviewed
{
"productsList": [
8, 33, 99, 100
]
}
©2014 Couchbase Inc.
Compound keys
u::1001
{
"name": "Matthew Revell",
"email": "matthew@couchbase.com",
"address": "11-21 Paul Street",
"city": "London",
"postCode": "EC2A 4JU",
"telephone": "44-20-3837-9130",
"orders": [ 1, 9, 698, 32 ]
}
u::1001::productsviewed
{
"productsList": [
8, 33, 99, 100
]
}
p::8
{
id": 1,
"name": "T-shirt",
"description": "Red Couchbase shirt",
"quantityInStock": 99,
"image": "tshirt.jpg”
}
p::8::img
“http://someurl.com/tshirt.jpg”
Data modelling for N1QL
27
©2014 Couchbase Inc.
N1QL
28
• N1QL implements much of SQL++
• Dive into arrays and objects
• NEST data from JOINs
• UNNEST data
• Gracefully handles MISSING data
©2014 Couchbase Inc.
A N1QL Example
29
SELECT * FROM `travel-sample` r
JOIN `travel-sample` a
ON KEYS r.airlineid
WHERE r.sourceairport="LHR"
AND r.destinationairport = "SFO";
©2014 Couchbase Inc.
JOINs and keys
34
JOINs work on primary keys and secondary keys.
They JOIN across and within keyspaces (for now, that means buckets).
Airlines:
airline_24 ← Key (“primary key”)
{
"id": "24",
"type": "airline",
"name": "American Airlines",
"iata": "AA",
"icao": "AAL",
"callsign": "AMERICAN",
"country": "United States",
"active": "Y"
}
Routes:
route_5966 ← Key
{
"id": "5966",
"type": "route",
"airline": "AA",
"airlineid": "airline_24", ← This is the foreign key
"sourceairport": "MCO",
"destinationairport": "SEA",
"stops": "0",
"equipment": "737",
"schedule": [...
]
}
Next Steps
Couchbase Developer Portal
developer.couchbase.com
40
Forums
http://forums.couchbase.com
41

More Related Content

Viewers also liked

Covering letter vinod
Covering letter vinodCovering letter vinod
Covering letter vinodvinod gupta
 
Académicos y universitarios ¡bienvenidos a nuestro mundo!
Académicos y universitarios ¡bienvenidos a nuestro mundo!Académicos y universitarios ¡bienvenidos a nuestro mundo!
Académicos y universitarios ¡bienvenidos a nuestro mundo!
tana_unica
 
Ieee 2016 Mobile Computing Papers Namakkal
Ieee 2016 Mobile Computing Papers NamakkalIeee 2016 Mobile Computing Papers Namakkal
Ieee 2016 Mobile Computing Papers Namakkal
krish madhi
 
ICH Q3 A (Impurities in New Drug Substances Q3A(R2) )
ICH Q3 A (Impurities in New Drug Substances Q3A(R2) )ICH Q3 A (Impurities in New Drug Substances Q3A(R2) )
ICH Q3 A (Impurities in New Drug Substances Q3A(R2) )
PHARMADVISOR
 
Tesis san marcos completo
Tesis san marcos completoTesis san marcos completo
Tesis san marcos completo
hernesto1983
 
Q3D - Elemental Impurities: What implications for APIs & excipients suppliers?
Q3D - Elemental Impurities: What implications for APIs & excipients suppliers?Q3D - Elemental Impurities: What implications for APIs & excipients suppliers?
Q3D - Elemental Impurities: What implications for APIs & excipients suppliers?
Quality Assistance s.a.
 

Viewers also liked (7)

Segundo parcial tecnologias 2
Segundo parcial tecnologias 2Segundo parcial tecnologias 2
Segundo parcial tecnologias 2
 
Covering letter vinod
Covering letter vinodCovering letter vinod
Covering letter vinod
 
Académicos y universitarios ¡bienvenidos a nuestro mundo!
Académicos y universitarios ¡bienvenidos a nuestro mundo!Académicos y universitarios ¡bienvenidos a nuestro mundo!
Académicos y universitarios ¡bienvenidos a nuestro mundo!
 
Ieee 2016 Mobile Computing Papers Namakkal
Ieee 2016 Mobile Computing Papers NamakkalIeee 2016 Mobile Computing Papers Namakkal
Ieee 2016 Mobile Computing Papers Namakkal
 
ICH Q3 A (Impurities in New Drug Substances Q3A(R2) )
ICH Q3 A (Impurities in New Drug Substances Q3A(R2) )ICH Q3 A (Impurities in New Drug Substances Q3A(R2) )
ICH Q3 A (Impurities in New Drug Substances Q3A(R2) )
 
Tesis san marcos completo
Tesis san marcos completoTesis san marcos completo
Tesis san marcos completo
 
Q3D - Elemental Impurities: What implications for APIs & excipients suppliers?
Q3D - Elemental Impurities: What implications for APIs & excipients suppliers?Q3D - Elemental Impurities: What implications for APIs & excipients suppliers?
Q3D - Elemental Impurities: What implications for APIs & excipients suppliers?
 

Similar to Three things you need to know about document data modelling

NoSQL's biggest lie: SQL never went away - Martin Esmann
NoSQL's biggest lie: SQL never went away - Martin EsmannNoSQL's biggest lie: SQL never went away - Martin Esmann
NoSQL's biggest lie: SQL never went away - Martin Esmann
distributed matters
 
NoSQL’s biggest secret: NoSQL never went away
NoSQL’s biggest secret: NoSQL never went awayNoSQL’s biggest secret: NoSQL never went away
NoSQL’s biggest secret: NoSQL never went away
Codemotion
 
Big Data Day LA 2015 - Introducing N1QL: SQL for Documents by Jeff Morris of ...
Big Data Day LA 2015 - Introducing N1QL: SQL for Documents by Jeff Morris of ...Big Data Day LA 2015 - Introducing N1QL: SQL for Documents by Jeff Morris of ...
Big Data Day LA 2015 - Introducing N1QL: SQL for Documents by Jeff Morris of ...
Data Con LA
 
Couchbase 101
Couchbase 101 Couchbase 101
Couchbase 101
Dipti Borkar
 
The Why, When, and How of NoSQL - A Practical Approach
The Why, When, and How of NoSQL - A Practical ApproachThe Why, When, and How of NoSQL - A Practical Approach
The Why, When, and How of NoSQL - A Practical Approach
DATAVERSITY
 
Json data modeling june 2017 - pittsburgh tech fest
Json data modeling   june 2017 - pittsburgh tech festJson data modeling   june 2017 - pittsburgh tech fest
Json data modeling june 2017 - pittsburgh tech fest
Matthew Groves
 
Exploring sql server 2016 bi
Exploring sql server 2016 biExploring sql server 2016 bi
Exploring sql server 2016 bi
Antonios Chatzipavlis
 
Going native with Apache Cassandra
Going native with Apache CassandraGoing native with Apache Cassandra
Going native with Apache Cassandra
Johnny Miller
 
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdfNeo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j
 
Tutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB StitchTutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB Stitch
MongoDB
 
Slides: NoSQL Data Modeling Using JSON Documents – A Practical Approach
Slides: NoSQL Data Modeling Using JSON Documents – A Practical ApproachSlides: NoSQL Data Modeling Using JSON Documents – A Practical Approach
Slides: NoSQL Data Modeling Using JSON Documents – A Practical Approach
DATAVERSITY
 
QCon 2014 - How Shutl delivers even faster with Neo4j
QCon 2014 - How Shutl delivers even faster with Neo4jQCon 2014 - How Shutl delivers even faster with Neo4j
QCon 2014 - How Shutl delivers even faster with Neo4j
Volker Pacher
 
No sq ls-biggest-lie_sql-never-went-away_martin-esmann
No sq ls-biggest-lie_sql-never-went-away_martin-esmannNo sq ls-biggest-lie_sql-never-went-away_martin-esmann
No sq ls-biggest-lie_sql-never-went-away_martin-esmann
Martin Esmann
 
An Introduction to the Microsoft Cloud
An Introduction to the Microsoft CloudAn Introduction to the Microsoft Cloud
An Introduction to the Microsoft Cloud
Shaping Cloud
 
Hadoop online training
Hadoop online trainingHadoop online training
Hadoop online trainingDivya Shree
 
Building Your First App with MongoDB Stitch
Building Your First App with MongoDB StitchBuilding Your First App with MongoDB Stitch
Building Your First App with MongoDB Stitch
MongoDB
 
Access Apps for Office 365 with Power BI
Access Apps for Office 365 with Power BIAccess Apps for Office 365 with Power BI
Access Apps for Office 365 with Power BI
Chris McNulty
 
JSON Data Modeling in Document Database
JSON Data Modeling in Document DatabaseJSON Data Modeling in Document Database
JSON Data Modeling in Document Database
DATAVERSITY
 
Hadoop Online Training in India
Hadoop Online Training in India Hadoop Online Training in India
Hadoop Online Training in India
united global soft
 

Similar to Three things you need to know about document data modelling (20)

NoSQL's biggest lie: SQL never went away - Martin Esmann
NoSQL's biggest lie: SQL never went away - Martin EsmannNoSQL's biggest lie: SQL never went away - Martin Esmann
NoSQL's biggest lie: SQL never went away - Martin Esmann
 
NoSQL’s biggest secret: NoSQL never went away
NoSQL’s biggest secret: NoSQL never went awayNoSQL’s biggest secret: NoSQL never went away
NoSQL’s biggest secret: NoSQL never went away
 
Big Data Day LA 2015 - Introducing N1QL: SQL for Documents by Jeff Morris of ...
Big Data Day LA 2015 - Introducing N1QL: SQL for Documents by Jeff Morris of ...Big Data Day LA 2015 - Introducing N1QL: SQL for Documents by Jeff Morris of ...
Big Data Day LA 2015 - Introducing N1QL: SQL for Documents by Jeff Morris of ...
 
Couchbase 101
Couchbase 101 Couchbase 101
Couchbase 101
 
The Why, When, and How of NoSQL - A Practical Approach
The Why, When, and How of NoSQL - A Practical ApproachThe Why, When, and How of NoSQL - A Practical Approach
The Why, When, and How of NoSQL - A Practical Approach
 
Json data modeling june 2017 - pittsburgh tech fest
Json data modeling   june 2017 - pittsburgh tech festJson data modeling   june 2017 - pittsburgh tech fest
Json data modeling june 2017 - pittsburgh tech fest
 
Exploring sql server 2016 bi
Exploring sql server 2016 biExploring sql server 2016 bi
Exploring sql server 2016 bi
 
Going native with Apache Cassandra
Going native with Apache CassandraGoing native with Apache Cassandra
Going native with Apache Cassandra
 
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdfNeo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
 
Tutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB StitchTutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB Stitch
 
Slides: NoSQL Data Modeling Using JSON Documents – A Practical Approach
Slides: NoSQL Data Modeling Using JSON Documents – A Practical ApproachSlides: NoSQL Data Modeling Using JSON Documents – A Practical Approach
Slides: NoSQL Data Modeling Using JSON Documents – A Practical Approach
 
QCon 2014 - How Shutl delivers even faster with Neo4j
QCon 2014 - How Shutl delivers even faster with Neo4jQCon 2014 - How Shutl delivers even faster with Neo4j
QCon 2014 - How Shutl delivers even faster with Neo4j
 
No sq ls-biggest-lie_sql-never-went-away_martin-esmann
No sq ls-biggest-lie_sql-never-went-away_martin-esmannNo sq ls-biggest-lie_sql-never-went-away_martin-esmann
No sq ls-biggest-lie_sql-never-went-away_martin-esmann
 
An Introduction to the Microsoft Cloud
An Introduction to the Microsoft CloudAn Introduction to the Microsoft Cloud
An Introduction to the Microsoft Cloud
 
Hadoop online training
Hadoop online trainingHadoop online training
Hadoop online training
 
Building Your First App with MongoDB Stitch
Building Your First App with MongoDB StitchBuilding Your First App with MongoDB Stitch
Building Your First App with MongoDB Stitch
 
Access Apps for Office 365 with Power BI
Access Apps for Office 365 with Power BIAccess Apps for Office 365 with Power BI
Access Apps for Office 365 with Power BI
 
JSON Data Modeling in Document Database
JSON Data Modeling in Document DatabaseJSON Data Modeling in Document Database
JSON Data Modeling in Document Database
 
Hadoop online training
Hadoop online trainingHadoop online training
Hadoop online training
 
Hadoop Online Training in India
Hadoop Online Training in India Hadoop Online Training in India
Hadoop Online Training in India
 

Recently uploaded

DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 

Recently uploaded (20)

DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 

Three things you need to know about document data modelling

  • 1. Three things you need to know about document data modelling Matthew Revell Director of Developer Advocacy, Couchbase 1
  • 2. We are still learning 2
  • 4. Our access pattern influences the data model 4
  • 5. ©2014 Couchbase Inc. Ad-hoc versus predictable 5 Application layer computation Off-load computation Predictable queries Key-value: pre-computed answers Views Ad-hoc queries N1QL and key-value with manual indexes N1QL and views
  • 7. ©2014 Couchbase Inc. Principles for key-value modelling 7 Pre-compute answers asynchronously Store object state Choose when to embed data and when to refer to it Design your keys well
  • 9. ©2014 Couchbase Inc. We're used to asking questions 9
  • 10. ©2014 Couchbase Inc. A library of answers 10
  • 11. ©2014 Couchbase Inc. Answer-oriented databases 11 http://martinfowler.com/bliki/AggregateOrientedDatabase.html
  • 12. ©2014 Couchbase Inc. Save the answers for later use 12
  • 14. ©2014 Couchbase Inc. An e-commerce order 14
  • 15. ©2014 Couchbase Inc. The same order as a document 15
  • 16. ©2014 Couchbase Inc. The same order as a document 16
  • 17. ©2014 Couchbase Inc. When to embed data 17 You should embed data when: Speed trumps all else Slow moving data No duplication Application layer can keep multiple copies of same data in sync
  • 18. ©2014 Couchbase Inc. When to referdata 18 You should refer to data when: Consistency is a priority The data has large growth potential
  • 20. ©2014 Couchbase Inc. Three ways to build a key 20 Key design is as important as document design. There are three broad types of keys: Human readable/deterministic: e.g., an email address Computer generated/random: e.g., a UUID Compound: e.g., a UUID with a deterministic portion
  • 21. ©2014 Couchbase Inc. Human readable/deterministic key 21 public class user { private String name; private String email; private String streetAddress; private String city; private String country; private String postCode; private String telephone; private Array orders; private Array productsViewed; } { "name": "Matthew Revell", "address": "11-21 Paul Street", "city": "London", "postCode": "EC2A 4JU", "telephone": "44-20-3837-9130", "orders": [ 1, 9, 698, 32 ], “productsViewed”: [8, 33, 99, 100] } Key: matthew@couchbase.com
  • 22. ©2014 Couchbase Inc. Counter key pattern 22 Application user_id = incr(“counter_key") add(user_id, data) Creating a new user add(email_address, user_id) Application key = get("matthew@couchbase.com") get(key) Finding a user by email address
  • 23. ©2014 Couchbase Inc. Multiple look-up documents 23 u::count 1001 u::1001 { "name": “Matthew Revell", "facebook_id": 16172910, "email": “matthew@couchbase.com”, “password”: ab02d#Jf02K "created_at": "5/1/2012 2:30am", “facebook_access_token”: xox0v2dje20, “twitter_access_token”: 20jffieieaaixixj } fb::16172910 1001 nflx::2939202 1001 twtr::2920283830 1001 em::matthew@couchbase.com 1001 em::matthew@understated.co.uk 1001 uname::mrevell 1001
  • 24. ©2014 Couchbase Inc. Compound keys u::1001 { "name": "Matthew Revell", "email": "matthew@couchbase.com", "address": "11-21 Paul Street", "city": "London", "postCode": "EC2A 4JU", "telephone": "44-20-3837-9130", "orders": [ 1, 9, 698, 32 ], “productsViewed”: [8, 33, 99, 100] }
  • 25. ©2014 Couchbase Inc. Compound keys u::1001 { "name": "Matthew Revell", "email": "matthew@couchbase.com", "address": "11-21 Paul Street", "city": "London", "postCode": "EC2A 4JU", "telephone": "44-20-3837-9130", "orders": [ 1, 9, 698, 32 ] } u::1001::productsviewed { "productsList": [ 8, 33, 99, 100 ] }
  • 26. ©2014 Couchbase Inc. Compound keys u::1001 { "name": "Matthew Revell", "email": "matthew@couchbase.com", "address": "11-21 Paul Street", "city": "London", "postCode": "EC2A 4JU", "telephone": "44-20-3837-9130", "orders": [ 1, 9, 698, 32 ] } u::1001::productsviewed { "productsList": [ 8, 33, 99, 100 ] } p::8 { id": 1, "name": "T-shirt", "description": "Red Couchbase shirt", "quantityInStock": 99, "image": "tshirt.jpg” } p::8::img “http://someurl.com/tshirt.jpg”
  • 28. ©2014 Couchbase Inc. N1QL 28 • N1QL implements much of SQL++ • Dive into arrays and objects • NEST data from JOINs • UNNEST data • Gracefully handles MISSING data
  • 29. ©2014 Couchbase Inc. A N1QL Example 29 SELECT * FROM `travel-sample` r JOIN `travel-sample` a ON KEYS r.airlineid WHERE r.sourceairport="LHR" AND r.destinationairport = "SFO";
  • 30. ©2014 Couchbase Inc. JOINs and keys 34 JOINs work on primary keys and secondary keys. They JOIN across and within keyspaces (for now, that means buckets). Airlines: airline_24 ← Key (“primary key”) { "id": "24", "type": "airline", "name": "American Airlines", "iata": "AA", "icao": "AAL", "callsign": "AMERICAN", "country": "United States", "active": "Y" } Routes: route_5966 ← Key { "id": "5966", "type": "route", "airline": "AA", "airlineid": "airline_24", ← This is the foreign key "sourceairport": "MCO", "destinationairport": "SEA", "stops": "0", "equipment": "737", "schedule": [... ] }

Editor's Notes

  1. Views let us automate that. View ain't going nowhere. Views might be the right way to index some stuff. Ultimately you're still doing KV but the indexes are slightly out of sync. Still, you're telling Couchbase how to go about giving you the data you want.
  2. Using the travel sample data we can find flights from LHR to SFO. Explain that we're aliasing travel-sample twice, because both sides of the join are in the same bucket. It's important not to conflate buckets and tables. Run this in cbq as it's too much for a GIF.
  3. Using the travel sample data we can find flights from LHR to SFO. Explain that we're aliasing travel-sample twice, because both sides of the join are in the same bucket. It's important not to conflate buckets and tables. Run this in cbq as it's too much for a GIF.
  4. Using the travel sample data we can find flights from LHR to SFO. Explain that we're aliasing travel-sample twice, because both sides of the join are in the same bucket. It's important not to conflate buckets and tables. Run this in cbq as it's too much for a GIF.
  5. Using the travel sample data we can find flights from LHR to SFO. Explain that we're aliasing travel-sample twice, because both sides of the join are in the same bucket. It's important not to conflate buckets and tables. Run this in cbq as it's too much for a GIF.
  6. Using the travel sample data we can find flights from LHR to SFO. Explain that we're aliasing travel-sample twice, because both sides of the join are in the same bucket. It's important not to conflate buckets and tables. Run this in cbq as it's too much for a GIF.
  7. Using the travel sample data we can find flights from LHR to SFO. Explain that we're aliasing travel-sample twice, because both sides of the join are in the same bucket. It's important not to conflate buckets and tables. Run this in cbq as it's too much for a GIF.
  8. It gives us airports, airlines, routes and that translates into flights.
  9. N1QL is all about giving you the data you want, not the data that happens to be in the database. JOINs are an essential part of that.
  10. Let's look at some sample docs from the travel sample.
  11. Here we use UNNEST and an inner join to find a list of all the flights from heathrow to SFO ordered by time. We are now aliasing the UNNESTed data too so we can easily use its data in our results.
  12. 31: Break