SlideShare a Scribd company logo
1 of 48
Download to read offline
Document databases in practice

Nicola Baldi

http://it.linkedin.com/in/nicolabaldi

Luigi Berrettini

http://it.linkedin.com/in/luigiberrettini
Overview

15/12/2012

Document databases in practice

2
Unbounded result sets problem
Unbounded number of requests problem

15/12/2012

Document databases in practice - Overview

3
 They favor denormalization over

composition and joins

 Relations are different than in RDBMSs
 They are schema-less, but attention should

be paid in designing documents

15/12/2012

Document databases in practice - Overview

4
« a conceptual model should be drawn with
little or no regard for the software that might
implement it » (Martin Fowler, UML Distilled)

A domain model should be independent from
implementation details like persistence
In RavenDB this is somewhat true
15/12/2012

Document databases in practice - Overview

5
 RDBMS are schema-full
• tuples = sets of key-value pairs ⇒ flat structure
• more complex data structures are stored as relations

 Document databases are schema-less
• object graphs stored as docs ⇒ no flat structure
• each document is treated as a single entity
RavenDB suggested approach is to follow the
aggregate pattern from the DDD book

15/12/2012

Document databases in practice - Overview

6
ENTITY
 Some objects are not defined primarily by

their attributes

 They represent a thread of identity that runs

through time and often across distinct
representations

 Mistaken identity can lead to data corruption
15/12/2012

Document databases in practice - Overview

7
VALUE OBJECT
 When you care only about the attributes of an

element of the model, classify it as a value object

 Make it express the meaning of the attributes it

conveys and give it related functionality

 Treat the value object as immutable
 Don't give it any identity and avoid the design

complexities necessary to maintain entities

15/12/2012

Document databases in practice - Overview

8
AGGREGATE
 Invariants are consistency rules that must be

maintained whenever data changes

 They’ll involve relationships within an aggregate

(relations & foreign keys: order / orderlines)

 Invariants applied within an aggregate will be

enforced with the completion of each transaction

15/12/2012

Document databases in practice - Overview

9
 Cluster entities and value objects into aggregates

and define boundaries around each

 Choose one entity to be the root of each

aggregate and control all access to the objects
inside the boundary through the root

 Allow external objects to hold references to the

root only

 Transient references to internal members can be

passed out for use within a single operation only

15/12/2012

Document databases in practice - Overview

10
 Because the root controls access, it cannot

be blindsided by changes to the internals

 This arrangement makes it practical to

enforce all invariants for objects in the
aggregate and for the aggregate as a
whole in any state change

15/12/2012

Document databases in practice - Overview

11
Nested child document

15/12/2012

Document databases in practice - Overview

12
Document referenced by ID

15/12/2012

Document databases in practice - Overview

13
Denormalized reference
 we clone properties that we care about when

displaying or processing a containing document
 avoids many cross document lookups and results in
only the necessary data being transmitted over the
network
 it makes other scenarios more difficult: if we add
frequently changing data, keeping details in synch
could become very demanding on the server
 use only for rarely changing data or for data that
can be dereferenced by out-of-sync data
15/12/2012

Document databases in practice - Overview

14
15/12/2012

Document databases in practice - Overview

15
Order contains
denormalized data
from Customer
and Product
Full data are
saved elsewhere

15/12/2012

Document databases in practice - Overview

16
15/12/2012

Document databases in practice - Overview

17
Querying

15/12/2012

Document databases in practice

18
 DocumentStore
• used to connect to a RavenDB data store
• thread-safe
• one instance per database per application

 Session
• used to perform operations on the database
• not thread-safe
• implements the Unit of Work pattern
 in a single session, a single document (identified
by its key) always resolves to the same instance
 change tracking
15/12/2012

Document databases in practice – Querying

19
15/12/2012

Document databases in practice – Querying

20
 Sequential GUID key
• when document key is not relevant (e.g. log entries)
• entity Id = sequential GUID (sorts well for indexing)
• Id property missing / not set ⇒ server generates a key

 Identity key
• entity Id = prefix + next available integer Id for it
• Id property set to a prefix = value ending with slash
• new DocumentStore ⇒ server sends a range of HiLo keys

 Assign a key yourself
• for documents which already have native id (e.g. users)
15/12/2012

Document databases in practice – Querying

21
15/12/2012

Document databases in practice – Querying

22
 soft-limit = 128

no Take() replaced by Take(128)

 hard-limit = 1024

if x > 1024 Take(x) returns 1024 documents

15/12/2012

Document databases in practice – Querying

23
 RavenDB can skip over some results internally

⇒ TotalResults value invalidated

 For proper paging use SkippedResults:
Skip(currentPage * pageSize + SkippedResults)
 Assuming a page size of 10…

15/12/2012

Document databases in practice – Querying

24
15/12/2012

Document databases in practice – Querying

25
15/12/2012

Document databases in practice – Querying

26
 RavenDB supports Count and Distinct
 SelectMany, GroupBy and Join are not supported

 The let keyword is not supported
 For such operations an index is needed

15/12/2012

Document databases in practice – Querying

27
All queries use an index to return results
 Dynamic = created automatically by the server
 Static = created explicitly by the user

15/12/2012

Document databases in practice – Querying

28
 no matching static index to query ⇒ RavenDB

automatically creates a dynamic index on the
fly (on first user query)

 based on requests coming in, RavenDB can

decide to promote a temporary index to a
permanent one

15/12/2012

Document databases in practice – Querying

29
 permanent
 expose much more functionality
 low latency: on first run dynamic indexes

have performance issues

 map / reduce

15/12/2012

Document databases in practice – Querying

30
15/12/2012

Document databases in practice – Querying

31
15/12/2012

Document databases in practice – Querying

32
15/12/2012

Document databases in practice – Querying

33
Advanced topics

15/12/2012

Document databases in practice

34
 an index is made of documents

 document
•
•
•
•

15/12/2012

atomic unit of indexing and searching
flat ⇒ recursion and joins must be denormalized
flexible schema
made of fields

Document databases in practice – Advanced topics

35
 field
• a name-value pair with associated info
• can be indexed if you're going to search on it
⇒ tokenization by analysis
• can be stored in order to preserve original
untokenized value within document

 example of physical index structure
{“__document_id”: “docs/1”, “tag”: “NoSQL”}

15/12/2012

Document databases in practice – Advanced topics

36
15/12/2012

Document databases in practice - Overview

37
15/12/2012

Document databases in practice – Advanced topics

38
15/12/2012

Document databases in practice – Advanced topics

39
One to one

15/12/2012

Document databases in practice – Advanced topics

40
One to many ⇒ SELECT N+1

15/12/2012

Document databases in practice – Advanced topics

41
Value type

15/12/2012

Document databases in practice – Advanced topics

42
 indexing: thread executed on creation or update
 server responds quickly BUT you may query stale

indexes (better stale than offline)

15/12/2012

Document databases in practice – Advanced topics

43
15/12/2012

Document databases in practice – Advanced topics

44
documentStore.Conventions.DefaultQueryingConsistency

 ConsistencyOptions.QueryYourWrites

same behavior of
WaitForNonStaleResultsAsOfLastWrite

 ConsistencyOptions.MonotonicRead

you never go back in time and read older
data than what you have already seen

15/12/2012

Document databases in practice – Advanced topics

45
15/12/2012

Document databases in practice - Overview

46
15/12/2012

Document databases in practice - Overview

47
15/12/2012

Document databases in practice - Overview

48

More Related Content

What's hot

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 ApproachDATAVERSITY
 
Business Intelligence & NoSQL Databases
Business Intelligence & NoSQL DatabasesBusiness Intelligence & NoSQL Databases
Business Intelligence & NoSQL DatabasesRadhoueneRouached
 
SQLite forensics - Free Lists, unallocated space, carving
SQLite forensics - Free Lists, unallocated space, carvingSQLite forensics - Free Lists, unallocated space, carving
SQLite forensics - Free Lists, unallocated space, carvingDmitry Kirillin
 
Designing database week ix part 1
Designing database week ix part 1Designing database week ix part 1
Designing database week ix part 1Johnecis Madrid
 
Database Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDatabase Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDAGEOP LTD
 
Jarrar: Data Schema Integration
Jarrar: Data Schema IntegrationJarrar: Data Schema Integration
Jarrar: Data Schema IntegrationMustafa Jarrar
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Beat Signer
 
Inb343 week2 sql server intro
Inb343 week2 sql server introInb343 week2 sql server intro
Inb343 week2 sql server introFredlive503
 
Data documentation and retrieval using unity in a universe®
Data documentation and retrieval using unity in a universe®Data documentation and retrieval using unity in a universe®
Data documentation and retrieval using unity in a universe®ANIL247048
 
5 data resource management
5 data resource management5 data resource management
5 data resource managementNymphea Saraf
 
2011 06-sq lite-forensics
2011 06-sq lite-forensics2011 06-sq lite-forensics
2011 06-sq lite-forensicsviaForensics
 
Redis Cashe is an open-source distributed in-memory data store.
Redis Cashe is an open-source distributed in-memory data store.Redis Cashe is an open-source distributed in-memory data store.
Redis Cashe is an open-source distributed in-memory data store.Artan Ajredini
 
Native JSON Support in SQL2016
Native JSON Support in SQL2016Native JSON Support in SQL2016
Native JSON Support in SQL2016Ivo Andreev
 
A Survey of Non -Relational Databases with Big Data
A Survey of Non -Relational Databases with Big DataA Survey of Non -Relational Databases with Big Data
A Survey of Non -Relational Databases with Big Datarahulmonikasharma
 
Comparison of Relational Database and Object Oriented Database
Comparison of Relational Database and Object Oriented DatabaseComparison of Relational Database and Object Oriented Database
Comparison of Relational Database and Object Oriented DatabaseEditor IJMTER
 

What's hot (20)

Nosql
NosqlNosql
Nosql
 
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
 
Managing data resources
Managing  data resourcesManaging  data resources
Managing data resources
 
Business Intelligence & NoSQL Databases
Business Intelligence & NoSQL DatabasesBusiness Intelligence & NoSQL Databases
Business Intelligence & NoSQL Databases
 
SQLite forensics - Free Lists, unallocated space, carving
SQLite forensics - Free Lists, unallocated space, carvingSQLite forensics - Free Lists, unallocated space, carving
SQLite forensics - Free Lists, unallocated space, carving
 
Designing database week ix part 1
Designing database week ix part 1Designing database week ix part 1
Designing database week ix part 1
 
Lecture 04 data resource management
Lecture 04 data resource managementLecture 04 data resource management
Lecture 04 data resource management
 
Database Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDatabase Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance Analysis
 
Jarrar: Data Schema Integration
Jarrar: Data Schema IntegrationJarrar: Data Schema Integration
Jarrar: Data Schema Integration
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
 
Inb343 week2 sql server intro
Inb343 week2 sql server introInb343 week2 sql server intro
Inb343 week2 sql server intro
 
Data documentation and retrieval using unity in a universe®
Data documentation and retrieval using unity in a universe®Data documentation and retrieval using unity in a universe®
Data documentation and retrieval using unity in a universe®
 
5 data resource management
5 data resource management5 data resource management
5 data resource management
 
Session#5; data resource managment
Session#5;  data resource managmentSession#5;  data resource managment
Session#5; data resource managment
 
2011 06-sq lite-forensics
2011 06-sq lite-forensics2011 06-sq lite-forensics
2011 06-sq lite-forensics
 
Redis Cashe is an open-source distributed in-memory data store.
Redis Cashe is an open-source distributed in-memory data store.Redis Cashe is an open-source distributed in-memory data store.
Redis Cashe is an open-source distributed in-memory data store.
 
Native JSON Support in SQL2016
Native JSON Support in SQL2016Native JSON Support in SQL2016
Native JSON Support in SQL2016
 
A Survey of Non -Relational Databases with Big Data
A Survey of Non -Relational Databases with Big DataA Survey of Non -Relational Databases with Big Data
A Survey of Non -Relational Databases with Big Data
 
My C.V
My C.VMy C.V
My C.V
 
Comparison of Relational Database and Object Oriented Database
Comparison of Relational Database and Object Oriented DatabaseComparison of Relational Database and Object Oriented Database
Comparison of Relational Database and Object Oriented Database
 

Similar to RavenDB

Database workshop - Encode | Bhuvan Gandhi | Vishwas Ganatra
Database workshop - Encode | Bhuvan Gandhi | Vishwas GanatraDatabase workshop - Encode | Bhuvan Gandhi | Vishwas Ganatra
Database workshop - Encode | Bhuvan Gandhi | Vishwas GanatraBhuvan Gandhi
 
Introduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBIntroduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBAhmed Farag
 
Denodo: Enabling a Data Mesh Architecture and Data Sharing Culture at Landsba...
Denodo: Enabling a Data Mesh Architecture and Data Sharing Culture at Landsba...Denodo: Enabling a Data Mesh Architecture and Data Sharing Culture at Landsba...
Denodo: Enabling a Data Mesh Architecture and Data Sharing Culture at Landsba...Denodo
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBKnoldus Inc.
 
Choosing an IdM User Store technology
Choosing an IdM User Store technologyChoosing an IdM User Store technology
Choosing an IdM User Store technologyMichael J Geiser
 
3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf
3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf
3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdfKrishnaShah908060
 
Logical Data Fabric and Data Mesh – Driving Business Outcomes
Logical Data Fabric and Data Mesh – Driving Business OutcomesLogical Data Fabric and Data Mesh – Driving Business Outcomes
Logical Data Fabric and Data Mesh – Driving Business OutcomesDenodo
 
computer fund-database presentation
 computer fund-database presentation computer fund-database presentation
computer fund-database presentationRakibul islam
 
Complete first chapter rdbm 17332
Complete first chapter rdbm 17332Complete first chapter rdbm 17332
Complete first chapter rdbm 17332Tushar Wagh
 
Building next generation data warehouses
Building next generation data warehousesBuilding next generation data warehouses
Building next generation data warehousesAlex Meadows
 
Real world business workflow with SharePoint designer 2013
Real world business workflow with SharePoint designer 2013Real world business workflow with SharePoint designer 2013
Real world business workflow with SharePoint designer 2013Ivan Sanders
 
System i - DDL vs DDS Presentation
System i - DDL vs DDS PresentationSystem i - DDL vs DDS Presentation
System i - DDL vs DDS PresentationChuck Walker
 
PGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles Darold
PGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles DaroldPGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles Darold
PGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles DaroldEqunix Business Solutions
 
Prague data management meetup 2017-02-28
Prague data management meetup 2017-02-28Prague data management meetup 2017-02-28
Prague data management meetup 2017-02-28Martin Bém
 
CH10-Managing a Database
CH10-Managing a DatabaseCH10-Managing a Database
CH10-Managing a DatabaseSukanya Ben
 

Similar to RavenDB (20)

Database workshop - Encode | Bhuvan Gandhi | Vishwas Ganatra
Database workshop - Encode | Bhuvan Gandhi | Vishwas GanatraDatabase workshop - Encode | Bhuvan Gandhi | Vishwas Ganatra
Database workshop - Encode | Bhuvan Gandhi | Vishwas Ganatra
 
Introduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBIntroduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDB
 
Chap14
Chap14Chap14
Chap14
 
Denodo: Enabling a Data Mesh Architecture and Data Sharing Culture at Landsba...
Denodo: Enabling a Data Mesh Architecture and Data Sharing Culture at Landsba...Denodo: Enabling a Data Mesh Architecture and Data Sharing Culture at Landsba...
Denodo: Enabling a Data Mesh Architecture and Data Sharing Culture at Landsba...
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Choosing an IdM User Store technology
Choosing an IdM User Store technologyChoosing an IdM User Store technology
Choosing an IdM User Store technology
 
3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf
3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf
3170722_BDA_GTU_Study_Material_Presentations_Unit-3_29092021094744AM.pdf
 
Logical Data Fabric and Data Mesh – Driving Business Outcomes
Logical Data Fabric and Data Mesh – Driving Business OutcomesLogical Data Fabric and Data Mesh – Driving Business Outcomes
Logical Data Fabric and Data Mesh – Driving Business Outcomes
 
DBMS outline.pptx
DBMS outline.pptxDBMS outline.pptx
DBMS outline.pptx
 
MongoDB DOC v1.5
MongoDB DOC v1.5MongoDB DOC v1.5
MongoDB DOC v1.5
 
computer fund-database presentation
 computer fund-database presentation computer fund-database presentation
computer fund-database presentation
 
NoSQL for SQL Users
NoSQL for SQL UsersNoSQL for SQL Users
NoSQL for SQL Users
 
Complete first chapter rdbm 17332
Complete first chapter rdbm 17332Complete first chapter rdbm 17332
Complete first chapter rdbm 17332
 
Building next generation data warehouses
Building next generation data warehousesBuilding next generation data warehouses
Building next generation data warehouses
 
Real world business workflow with SharePoint designer 2013
Real world business workflow with SharePoint designer 2013Real world business workflow with SharePoint designer 2013
Real world business workflow with SharePoint designer 2013
 
Sql good practices
Sql good practicesSql good practices
Sql good practices
 
System i - DDL vs DDS Presentation
System i - DDL vs DDS PresentationSystem i - DDL vs DDS Presentation
System i - DDL vs DDS Presentation
 
PGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles Darold
PGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles DaroldPGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles Darold
PGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles Darold
 
Prague data management meetup 2017-02-28
Prague data management meetup 2017-02-28Prague data management meetup 2017-02-28
Prague data management meetup 2017-02-28
 
CH10-Managing a Database
CH10-Managing a DatabaseCH10-Managing a Database
CH10-Managing a Database
 

Recently uploaded

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Recently uploaded (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

RavenDB

  • 1. Document databases in practice Nicola Baldi http://it.linkedin.com/in/nicolabaldi Luigi Berrettini http://it.linkedin.com/in/luigiberrettini
  • 3. Unbounded result sets problem Unbounded number of requests problem 15/12/2012 Document databases in practice - Overview 3
  • 4.  They favor denormalization over composition and joins  Relations are different than in RDBMSs  They are schema-less, but attention should be paid in designing documents 15/12/2012 Document databases in practice - Overview 4
  • 5. « a conceptual model should be drawn with little or no regard for the software that might implement it » (Martin Fowler, UML Distilled) A domain model should be independent from implementation details like persistence In RavenDB this is somewhat true 15/12/2012 Document databases in practice - Overview 5
  • 6.  RDBMS are schema-full • tuples = sets of key-value pairs ⇒ flat structure • more complex data structures are stored as relations  Document databases are schema-less • object graphs stored as docs ⇒ no flat structure • each document is treated as a single entity RavenDB suggested approach is to follow the aggregate pattern from the DDD book 15/12/2012 Document databases in practice - Overview 6
  • 7. ENTITY  Some objects are not defined primarily by their attributes  They represent a thread of identity that runs through time and often across distinct representations  Mistaken identity can lead to data corruption 15/12/2012 Document databases in practice - Overview 7
  • 8. VALUE OBJECT  When you care only about the attributes of an element of the model, classify it as a value object  Make it express the meaning of the attributes it conveys and give it related functionality  Treat the value object as immutable  Don't give it any identity and avoid the design complexities necessary to maintain entities 15/12/2012 Document databases in practice - Overview 8
  • 9. AGGREGATE  Invariants are consistency rules that must be maintained whenever data changes  They’ll involve relationships within an aggregate (relations & foreign keys: order / orderlines)  Invariants applied within an aggregate will be enforced with the completion of each transaction 15/12/2012 Document databases in practice - Overview 9
  • 10.  Cluster entities and value objects into aggregates and define boundaries around each  Choose one entity to be the root of each aggregate and control all access to the objects inside the boundary through the root  Allow external objects to hold references to the root only  Transient references to internal members can be passed out for use within a single operation only 15/12/2012 Document databases in practice - Overview 10
  • 11.  Because the root controls access, it cannot be blindsided by changes to the internals  This arrangement makes it practical to enforce all invariants for objects in the aggregate and for the aggregate as a whole in any state change 15/12/2012 Document databases in practice - Overview 11
  • 12. Nested child document 15/12/2012 Document databases in practice - Overview 12
  • 13. Document referenced by ID 15/12/2012 Document databases in practice - Overview 13
  • 14. Denormalized reference  we clone properties that we care about when displaying or processing a containing document  avoids many cross document lookups and results in only the necessary data being transmitted over the network  it makes other scenarios more difficult: if we add frequently changing data, keeping details in synch could become very demanding on the server  use only for rarely changing data or for data that can be dereferenced by out-of-sync data 15/12/2012 Document databases in practice - Overview 14
  • 15. 15/12/2012 Document databases in practice - Overview 15
  • 16. Order contains denormalized data from Customer and Product Full data are saved elsewhere 15/12/2012 Document databases in practice - Overview 16
  • 17. 15/12/2012 Document databases in practice - Overview 17
  • 19.  DocumentStore • used to connect to a RavenDB data store • thread-safe • one instance per database per application  Session • used to perform operations on the database • not thread-safe • implements the Unit of Work pattern  in a single session, a single document (identified by its key) always resolves to the same instance  change tracking 15/12/2012 Document databases in practice – Querying 19
  • 20. 15/12/2012 Document databases in practice – Querying 20
  • 21.  Sequential GUID key • when document key is not relevant (e.g. log entries) • entity Id = sequential GUID (sorts well for indexing) • Id property missing / not set ⇒ server generates a key  Identity key • entity Id = prefix + next available integer Id for it • Id property set to a prefix = value ending with slash • new DocumentStore ⇒ server sends a range of HiLo keys  Assign a key yourself • for documents which already have native id (e.g. users) 15/12/2012 Document databases in practice – Querying 21
  • 22. 15/12/2012 Document databases in practice – Querying 22
  • 23.  soft-limit = 128 no Take() replaced by Take(128)  hard-limit = 1024 if x > 1024 Take(x) returns 1024 documents 15/12/2012 Document databases in practice – Querying 23
  • 24.  RavenDB can skip over some results internally ⇒ TotalResults value invalidated  For proper paging use SkippedResults: Skip(currentPage * pageSize + SkippedResults)  Assuming a page size of 10… 15/12/2012 Document databases in practice – Querying 24
  • 25. 15/12/2012 Document databases in practice – Querying 25
  • 26. 15/12/2012 Document databases in practice – Querying 26
  • 27.  RavenDB supports Count and Distinct  SelectMany, GroupBy and Join are not supported  The let keyword is not supported  For such operations an index is needed 15/12/2012 Document databases in practice – Querying 27
  • 28. All queries use an index to return results  Dynamic = created automatically by the server  Static = created explicitly by the user 15/12/2012 Document databases in practice – Querying 28
  • 29.  no matching static index to query ⇒ RavenDB automatically creates a dynamic index on the fly (on first user query)  based on requests coming in, RavenDB can decide to promote a temporary index to a permanent one 15/12/2012 Document databases in practice – Querying 29
  • 30.  permanent  expose much more functionality  low latency: on first run dynamic indexes have performance issues  map / reduce 15/12/2012 Document databases in practice – Querying 30
  • 31. 15/12/2012 Document databases in practice – Querying 31
  • 32. 15/12/2012 Document databases in practice – Querying 32
  • 33. 15/12/2012 Document databases in practice – Querying 33
  • 35.  an index is made of documents  document • • • • 15/12/2012 atomic unit of indexing and searching flat ⇒ recursion and joins must be denormalized flexible schema made of fields Document databases in practice – Advanced topics 35
  • 36.  field • a name-value pair with associated info • can be indexed if you're going to search on it ⇒ tokenization by analysis • can be stored in order to preserve original untokenized value within document  example of physical index structure {“__document_id”: “docs/1”, “tag”: “NoSQL”} 15/12/2012 Document databases in practice – Advanced topics 36
  • 37. 15/12/2012 Document databases in practice - Overview 37
  • 38. 15/12/2012 Document databases in practice – Advanced topics 38
  • 39. 15/12/2012 Document databases in practice – Advanced topics 39
  • 40. One to one 15/12/2012 Document databases in practice – Advanced topics 40
  • 41. One to many ⇒ SELECT N+1 15/12/2012 Document databases in practice – Advanced topics 41
  • 42. Value type 15/12/2012 Document databases in practice – Advanced topics 42
  • 43.  indexing: thread executed on creation or update  server responds quickly BUT you may query stale indexes (better stale than offline) 15/12/2012 Document databases in practice – Advanced topics 43
  • 44. 15/12/2012 Document databases in practice – Advanced topics 44
  • 45. documentStore.Conventions.DefaultQueryingConsistency  ConsistencyOptions.QueryYourWrites same behavior of WaitForNonStaleResultsAsOfLastWrite  ConsistencyOptions.MonotonicRead you never go back in time and read older data than what you have already seen 15/12/2012 Document databases in practice – Advanced topics 45
  • 46. 15/12/2012 Document databases in practice - Overview 46
  • 47. 15/12/2012 Document databases in practice - Overview 47
  • 48. 15/12/2012 Document databases in practice - Overview 48