SlideShare a Scribd company logo
1 of 38
Document-oriented data access for
domain-driven .NET systems with
PostgreSQL & Marten
Bojan Veljanovski, CTO at HASELT
October, 2017 @ Macedonian .NET User Group
1
What we are going to talk about?
● Limitations in relational-only DBs for storing true domain
aggregates
● How document-oriented DBs come into play
● Marten as document DB for .NET with PostgreSQL
● SQL + NoSQL => best of both worlds
2
Setting context
● How I got interested in document-oriented DBs?
Why it makes so much sense?
● Why PostgreSQL?
Why not MongoDb, CouchDb, RavenDb?
What about SQL Server, MySQL?
● Who else uses this approach?
3
Sample domain model
4
DDD Aggregate
Cluster of domain objects that can be treated as a
single unit.
● Consists of
○ Aggregate Root (or Root Entity)
○ Entities
○ Value Objects
○ Services
○ Repositories 5
Basic characteristics of an Aggregate Root
● Global identity
● Ensures invariants within aggregate
● Guarantees consistency
● Can reference other ARs only by identity
● Cannot reference non ARs
● Transactional consistency
● Stored and loaded in DB as a whole. 6
Relational-only model
7
Sample domain model in code
Let’s see the sample codebase in Visual Studio.
8
Limitations when working with
domain models in relational-only DBs...
● Cannot store an array of values
○ Needs new table with 1-m relation
● ...an array of objects
○ Needs new table with 1-m relation
● …a nested object
○ Needs new table with 1-1 relation
● …an AR in a single table
○ AR is spanned across many tables, and needs joinsThese limitations often lead to...
9
These limitations often lead to...
● Complex O/R mapping code
● Sacrificing encapsulation for easier O/R mapping
● Leak of domain logic to upper layers
● Anemic domain models - only data, no behavior
● Dev teams focusing on data-relations instead of
system behavior
● Implicit “SELECT N+1” problems
● Unit tests full with mocks & stubs 10
Moving out of the relational-only mindset
From thinking in terms of relations and data
To thinking in terms of behavior and data
11
Document model
12
How document-oriented DBs come into play
● Single document per [whole] aggregate
● Can store complex object graphs
● Can store arrays, collections, nested objects
● No need for ORM
● No limitations for creating rich domain models
● Dev team focus is in on behavior and logic
● Models are easy to unit test
13
Introducing PostgreSQL
14
Introducing PostgreSQL
● Object-relational database
● ACID
● Transactional
● Highly Extendable
● Open Source
● Free
15
PostgreSQL NoSQL data types
● Key/Value store
○ hstore
● Document store
○ json and jsonb
● Spatial and Geographic objects
○ postgis 16
PostgreSQL as document store:
Creating table with JSONB column
17
Inserting documents
18
Querying documents (1)
19
Querying documents (2)
20
Indexing documents
Various indexes are supported. 21
Marten as Document DB for
.NET with PostgreSQL
22
Introducing Marten
● OSS .NET library that provides polyglot persistence
● Document store
● Event store
● Uses PostgreSQL’s powerful JSON support
● Initial pre-alpha release on 08.12.2015
● Current version 2.3.2
● Community chat: gitter.im/JasperFx/marten
23
Getting started
24
Persisting documents
25
How our data looks like? -> User
26
Loading document by Id
27
Querying documents with LINQ
28
Filtering in arrays
29
Paging and sorting
30
Querying with plain SQL through Dapper
(yes, querying NoSQL documents with plain-old SQL)
31
Adding Foreign Key to Order document
32
How our data looks like with FK? -> Order
33
Querying multiple documents
by using SQL JOIN
34
Other notable features in Marten as Document Db
● Foreign Keys
● Indexes
● Duplicate columns
● Batched queries
● Compiled queries
● Bulk insert
● Multitenancy
● Optimistic Concurrency 35
Closing
36
Summary
● Relational-only DBs limit the ability to craft good
domain models
● Document DBs are natural fit for DDD Aggregates
● SQL + NoSQL in Postgres = best of both worlds
in a single DB provider
● Marten helps .NET devs leverage PostgreSQL as
polyglot database
● Polyglot data access mindset - there is no single
approach
37
Resources
● Marten
○ https://jasperfx.github.io/marten
○ https://gitter.im/JasperFx/marten
● PostgreSQL JSON Functions and Operators
○ https://www.postgresql.org
● This presentation’s code samples
○ https://github.com/bojanv91/MartenPostgreSamples
● Other useful articles
○ https://martinfowler.com/bliki/AggregateOrientedDatabase.html
38

More Related Content

What's hot

What's hot (19)

Mongo db
Mongo dbMongo db
Mongo db
 
The ECM world from the point of view of Alfresco - Linux Day 2013 - Rome
The ECM world from the point of view of Alfresco - Linux Day 2013 - RomeThe ECM world from the point of view of Alfresco - Linux Day 2013 - Rome
The ECM world from the point of view of Alfresco - Linux Day 2013 - Rome
 
MongoDB NoSQL - Developer Guide
MongoDB NoSQL - Developer GuideMongoDB NoSQL - Developer Guide
MongoDB NoSQL - Developer Guide
 
Mongo db nosql (1)
Mongo db nosql (1)Mongo db nosql (1)
Mongo db nosql (1)
 
Mongo db
Mongo dbMongo db
Mongo db
 
Crawling the Web for Structured Documents
Crawling the Web for Structured DocumentsCrawling the Web for Structured Documents
Crawling the Web for Structured Documents
 
Legislation.gov.uk
Legislation.gov.ukLegislation.gov.uk
Legislation.gov.uk
 
Storage dei dati con MongoDB
Storage dei dati con MongoDBStorage dei dati con MongoDB
Storage dei dati con MongoDB
 
Nosql
NosqlNosql
Nosql
 
Redis - Your Magical superfast database
Redis - Your Magical superfast databaseRedis - Your Magical superfast database
Redis - Your Magical superfast database
 
CSCi226PPT1
CSCi226PPT1CSCi226PPT1
CSCi226PPT1
 
Structures
StructuresStructures
Structures
 
Xml
XmlXml
Xml
 
Xml databases
Xml databasesXml databases
Xml databases
 
DataTables view CKAN monthly live
DataTables view   CKAN monthly liveDataTables view   CKAN monthly live
DataTables view CKAN monthly live
 
Neo4j graph database
Neo4j graph databaseNeo4j graph database
Neo4j graph database
 
Intoduction to OrientDB
Intoduction to OrientDBIntoduction to OrientDB
Intoduction to OrientDB
 
Mobicents Summit 2012 - Alexandre Mendonca - Mobicents jDiameter
Mobicents Summit 2012 - Alexandre Mendonca - Mobicents jDiameterMobicents Summit 2012 - Alexandre Mendonca - Mobicents jDiameter
Mobicents Summit 2012 - Alexandre Mendonca - Mobicents jDiameter
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
 

Similar to NoSQL document oriented data access for .net systems with postgresql and marten

PostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabasePostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabaseMubashar Iqbal
 
No sql bigdata and postgresql
No sql bigdata and postgresqlNo sql bigdata and postgresql
No sql bigdata and postgresqlZaid Shabbir
 
Introduction to mongo db by zain
Introduction to mongo db by zainIntroduction to mongo db by zain
Introduction to mongo db by zainKenAndTea
 
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLBack to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLMongoDB
 
Back to Basics 2017 - Introduction to NoSQL
Back to Basics 2017 - Introduction to NoSQLBack to Basics 2017 - Introduction to NoSQL
Back to Basics 2017 - Introduction to NoSQLJoe Drumgoole
 
Introduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBIntroduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBAhmed Farag
 
MongoDB Introduction - Document Oriented Nosql Database
MongoDB Introduction - Document Oriented Nosql DatabaseMongoDB Introduction - Document Oriented Nosql Database
MongoDB Introduction - Document Oriented Nosql DatabaseSudhir Patil
 
SQL or NoSQL - how to choose
SQL or NoSQL - how to chooseSQL or NoSQL - how to choose
SQL or NoSQL - how to chooseLars Thorup
 
MongoDB 2.4 and spring data
MongoDB 2.4 and spring dataMongoDB 2.4 and spring data
MongoDB 2.4 and spring dataJimmy Ray
 
Introduction to SQL Alchemy - SyPy June 2013
Introduction to SQL Alchemy - SyPy June 2013Introduction to SQL Alchemy - SyPy June 2013
Introduction to SQL Alchemy - SyPy June 2013Roger Barnes
 
An Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for .NET Developers.pdfAn Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for .NET Developers.pdfStephen Lorello
 
Quick overview on mongo db
Quick overview on mongo dbQuick overview on mongo db
Quick overview on mongo dbEman Mohamed
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBKnoldus Inc.
 
Ledingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartLedingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartMukesh Singh
 
An Introduction to Pentaho Kettle
An Introduction to Pentaho KettleAn Introduction to Pentaho Kettle
An Introduction to Pentaho KettleDan Moore
 
Oracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration HustleOracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration HustleEDB
 

Similar to NoSQL document oriented data access for .net systems with postgresql and marten (20)

PostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabasePostgreSQL - Object Relational Database
PostgreSQL - Object Relational Database
 
No sql bigdata and postgresql
No sql bigdata and postgresqlNo sql bigdata and postgresql
No sql bigdata and postgresql
 
Introduction to mongo db by zain
Introduction to mongo db by zainIntroduction to mongo db by zain
Introduction to mongo db by zain
 
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLBack to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQL
 
Back to Basics 2017 - Introduction to NoSQL
Back to Basics 2017 - Introduction to NoSQLBack to Basics 2017 - Introduction to NoSQL
Back to Basics 2017 - Introduction to NoSQL
 
Introduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBIntroduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDB
 
MongoDB Introduction - Document Oriented Nosql Database
MongoDB Introduction - Document Oriented Nosql DatabaseMongoDB Introduction - Document Oriented Nosql Database
MongoDB Introduction - Document Oriented Nosql Database
 
SQL or NoSQL - how to choose
SQL or NoSQL - how to chooseSQL or NoSQL - how to choose
SQL or NoSQL - how to choose
 
MongoDB 2.4 and spring data
MongoDB 2.4 and spring dataMongoDB 2.4 and spring data
MongoDB 2.4 and spring data
 
Introduction to SQL Alchemy - SyPy June 2013
Introduction to SQL Alchemy - SyPy June 2013Introduction to SQL Alchemy - SyPy June 2013
Introduction to SQL Alchemy - SyPy June 2013
 
An Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for .NET Developers.pdfAn Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for .NET Developers.pdf
 
Quick overview on mongo db
Quick overview on mongo dbQuick overview on mongo db
Quick overview on mongo db
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Mongo db
Mongo dbMongo db
Mongo db
 
Graph databases
Graph databasesGraph databases
Graph databases
 
Ledingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartLedingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @Lendingkart
 
An Introduction to Pentaho Kettle
An Introduction to Pentaho KettleAn Introduction to Pentaho Kettle
An Introduction to Pentaho Kettle
 
Oracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration HustleOracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration Hustle
 
Datastore PPT.pptx
Datastore PPT.pptxDatastore PPT.pptx
Datastore PPT.pptx
 
Introduction To Pentaho Kettle
Introduction To Pentaho KettleIntroduction To Pentaho Kettle
Introduction To Pentaho Kettle
 

More from Bojan Veljanovski

CodeCamp 2018 - Architecting Systems with CQRS - Four Years Experience Report...
CodeCamp 2018 - Architecting Systems with CQRS - Four Years Experience Report...CodeCamp 2018 - Architecting Systems with CQRS - Four Years Experience Report...
CodeCamp 2018 - Architecting Systems with CQRS - Four Years Experience Report...Bojan Veljanovski
 
DIGIT Noe 2016 - Overview of front end development today
DIGIT Noe 2016 - Overview of front end development todayDIGIT Noe 2016 - Overview of front end development today
DIGIT Noe 2016 - Overview of front end development todayBojan Veljanovski
 
Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)
Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)
Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)Bojan Veljanovski
 
Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG
Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UGVertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG
Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UGBojan Veljanovski
 
Quick look at Web Components and Project Polymer - MKNET UG
Quick look at Web Components and Project Polymer - MKNET UGQuick look at Web Components and Project Polymer - MKNET UG
Quick look at Web Components and Project Polymer - MKNET UGBojan Veljanovski
 
Real-world software design practices when developing ASP.NET web systems by B...
Real-world software design practices when developing ASP.NET web systems by B...Real-world software design practices when developing ASP.NET web systems by B...
Real-world software design practices when developing ASP.NET web systems by B...Bojan Veljanovski
 
AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...
AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...
AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...Bojan Veljanovski
 

More from Bojan Veljanovski (7)

CodeCamp 2018 - Architecting Systems with CQRS - Four Years Experience Report...
CodeCamp 2018 - Architecting Systems with CQRS - Four Years Experience Report...CodeCamp 2018 - Architecting Systems with CQRS - Four Years Experience Report...
CodeCamp 2018 - Architecting Systems with CQRS - Four Years Experience Report...
 
DIGIT Noe 2016 - Overview of front end development today
DIGIT Noe 2016 - Overview of front end development todayDIGIT Noe 2016 - Overview of front end development today
DIGIT Noe 2016 - Overview of front end development today
 
Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)
Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)
Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)
 
Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG
Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UGVertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG
Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG
 
Quick look at Web Components and Project Polymer - MKNET UG
Quick look at Web Components and Project Polymer - MKNET UGQuick look at Web Components and Project Polymer - MKNET UG
Quick look at Web Components and Project Polymer - MKNET UG
 
Real-world software design practices when developing ASP.NET web systems by B...
Real-world software design practices when developing ASP.NET web systems by B...Real-world software design practices when developing ASP.NET web systems by B...
Real-world software design practices when developing ASP.NET web systems by B...
 
AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...
AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...
AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...
 

Recently uploaded

College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 

Recently uploaded (20)

College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 

NoSQL document oriented data access for .net systems with postgresql and marten

  • 1. Document-oriented data access for domain-driven .NET systems with PostgreSQL & Marten Bojan Veljanovski, CTO at HASELT October, 2017 @ Macedonian .NET User Group 1
  • 2. What we are going to talk about? ● Limitations in relational-only DBs for storing true domain aggregates ● How document-oriented DBs come into play ● Marten as document DB for .NET with PostgreSQL ● SQL + NoSQL => best of both worlds 2
  • 3. Setting context ● How I got interested in document-oriented DBs? Why it makes so much sense? ● Why PostgreSQL? Why not MongoDb, CouchDb, RavenDb? What about SQL Server, MySQL? ● Who else uses this approach? 3
  • 5. DDD Aggregate Cluster of domain objects that can be treated as a single unit. ● Consists of ○ Aggregate Root (or Root Entity) ○ Entities ○ Value Objects ○ Services ○ Repositories 5
  • 6. Basic characteristics of an Aggregate Root ● Global identity ● Ensures invariants within aggregate ● Guarantees consistency ● Can reference other ARs only by identity ● Cannot reference non ARs ● Transactional consistency ● Stored and loaded in DB as a whole. 6
  • 8. Sample domain model in code Let’s see the sample codebase in Visual Studio. 8
  • 9. Limitations when working with domain models in relational-only DBs... ● Cannot store an array of values ○ Needs new table with 1-m relation ● ...an array of objects ○ Needs new table with 1-m relation ● …a nested object ○ Needs new table with 1-1 relation ● …an AR in a single table ○ AR is spanned across many tables, and needs joinsThese limitations often lead to... 9
  • 10. These limitations often lead to... ● Complex O/R mapping code ● Sacrificing encapsulation for easier O/R mapping ● Leak of domain logic to upper layers ● Anemic domain models - only data, no behavior ● Dev teams focusing on data-relations instead of system behavior ● Implicit “SELECT N+1” problems ● Unit tests full with mocks & stubs 10
  • 11. Moving out of the relational-only mindset From thinking in terms of relations and data To thinking in terms of behavior and data 11
  • 13. How document-oriented DBs come into play ● Single document per [whole] aggregate ● Can store complex object graphs ● Can store arrays, collections, nested objects ● No need for ORM ● No limitations for creating rich domain models ● Dev team focus is in on behavior and logic ● Models are easy to unit test 13
  • 15. Introducing PostgreSQL ● Object-relational database ● ACID ● Transactional ● Highly Extendable ● Open Source ● Free 15
  • 16. PostgreSQL NoSQL data types ● Key/Value store ○ hstore ● Document store ○ json and jsonb ● Spatial and Geographic objects ○ postgis 16
  • 17. PostgreSQL as document store: Creating table with JSONB column 17
  • 22. Marten as Document DB for .NET with PostgreSQL 22
  • 23. Introducing Marten ● OSS .NET library that provides polyglot persistence ● Document store ● Event store ● Uses PostgreSQL’s powerful JSON support ● Initial pre-alpha release on 08.12.2015 ● Current version 2.3.2 ● Community chat: gitter.im/JasperFx/marten 23
  • 26. How our data looks like? -> User 26
  • 31. Querying with plain SQL through Dapper (yes, querying NoSQL documents with plain-old SQL) 31
  • 32. Adding Foreign Key to Order document 32
  • 33. How our data looks like with FK? -> Order 33
  • 34. Querying multiple documents by using SQL JOIN 34
  • 35. Other notable features in Marten as Document Db ● Foreign Keys ● Indexes ● Duplicate columns ● Batched queries ● Compiled queries ● Bulk insert ● Multitenancy ● Optimistic Concurrency 35
  • 37. Summary ● Relational-only DBs limit the ability to craft good domain models ● Document DBs are natural fit for DDD Aggregates ● SQL + NoSQL in Postgres = best of both worlds in a single DB provider ● Marten helps .NET devs leverage PostgreSQL as polyglot database ● Polyglot data access mindset - there is no single approach 37
  • 38. Resources ● Marten ○ https://jasperfx.github.io/marten ○ https://gitter.im/JasperFx/marten ● PostgreSQL JSON Functions and Operators ○ https://www.postgresql.org ● This presentation’s code samples ○ https://github.com/bojanv91/MartenPostgreSamples ● Other useful articles ○ https://martinfowler.com/bliki/AggregateOrientedDatabase.html 38