Domain Driven Design and NoSQL
Dublin 2014-09-04 martin Schönert (triAGENS) TRI-MS-1409-001-V100-20140901 DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
1
martin
Studied mathematics and investigated algebraic structures with the computer Since then in IT in many roles:
Programmer
Project Manager
Product Owner
etc.
These days primarily architect
Consulting other companies
For the ArangoDB database
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
2
Project YAWS (Yet Another Web Shop)
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
3
Wellcome to the Specification Workshop
Product managers talk about what they expect from the Shop Site
ability to browse through the shop powerful search with good products at the top rather informal
The Expert, 2014, Lauris Beinerts
all participants are in high spirits
no disagreements DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
4
and so the developers develop
Object Oriented
3-tier Architectur
Model View Controller
Modern Framework
Responsive Design
etc.
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
5
but at handover Why are there no recommendations
of course the position in the result list should depend on the net margin.
Checkout is not usable!
… but that is obvious!
Developers are incompetent!
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
6
what developers think of the business side
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
7
but in fact it is a problem in the system
functionality is not gathered methodically „obvious“ functions are missing no common language misunderstandings about the details of the functions
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
8
Agile Development helps to gather functionality methodically
continous interaction
Product Backlog
Stories / Epics
etc.
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
9
Domain Driven Design
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
10
was described by Eric Evans
Approach to model complex business oriented software centers around the business logic towards this goal you model the application domain
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
11
Ubiqous Language
common language
is used by ALL participants
is used in ALL phases of the project must be based on the business logic
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
12
Entities
have an identity two identities are different even if they have the same values for all attributes Examples
Persons
Shopping Cart
Mutability
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
13
Value Objects
have no identity of their own are only defined by their attributes can be copied (without changing the semantics) Examples:
Product descriptions
Immutable (at least from the business logic view)
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
14
Aggregates
Collection of entities and value objects into one transactional unit
Session session-id last-access
one entity defines the access for the aggregate
User name pw-hash e-mail
Shopping-Cart
Wishlist
the controlled access allows to maintain the invariants
Ubiq P.K. Dick
Little, Big 25 J. Crowley
Brazil T. Gilliam
In Bruges M.McDonagh
Rain Dogs T. Waits Aggregate
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
15
Associations
knows knows
works-for
shares-flat
Relations between entities and value objects
can have properties
are usually inmutable
works-for send-request
knows
invited
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
16
Factories
create complex aggregates, entities and value objects correspond to patterns
Factory
Builder
Prototype
Example:
Create an aggregate for a new user with empty shopping cart and wish list
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
17
Repository
Stores entities and aggregates
Persistence
corresponds to the bottom layer in a 3 tier architecture
Methods for searching
Example:
Product Catalog
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
18
Relational Databases
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
19
in Relational Databases you have (very special) Relations not a relation
relation
Foreign Key
relational Algebra
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
20
you have Normal Forms
Marc Rettig
Rules of Data Normalization
orig. published 1989
(still very useful)
(how many normal forms are there: 1NF, 2NF, 3NF, BCNF, 4NF, 5NF, EKNF, DKNF, 6NF, ...)
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
21
what normal form means ...
our nice objects are taken apart and distributes the pieces over many tables
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
22
and then you need Joins
Instructions (Joins) to put the objects back together again when you read them
(Yes - there are joins for other purposes)
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
23
and then you need Transactions
Rules (Transactions) so that nothing gets lost when you piece the object together again
(Yes – there are transactions for other purposes)
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
24
in short: Database Developers speak their own language
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
25
NoSQL Databases
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
26
Recently there has been a development of many non relational databases: NoSQL
Conditions for DBs have changed functional requirements
many simple operations
non functional requirements
Volume
Variety
Velocity
hardware
RAM is cheap
SSDs DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
27
NoSQL databases are generally classified in four categories Key-Value Stores
Document Databases
Extended Column Stores
Graph Databases
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
28
A new development are the Multi-Model Databases
Multi-Model Databases
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
29
Key-Value Stores are the simplest data stores Key
Value
Key 2
{Value name: „paavo“ }
Key 3
{Value first: „emil“ }
Key „runners“
{Value ids: [ 1, 2, 3, 5 ] }
Key 5
{Value name:„haile“,act:1 }
Key 1
{Value first: „paul“ }
Key „last“
Value 5
Map Keys to Values (dict) Access only via the Key Values are unstructured usually no ability to loop over the kv-pairs e.g. shopping cart scales very well
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
30
Document Databases
{
FirstName:"Jonathan", Address:"15 Wanamassa Road",
Children:[ {Name:"Michael",Age:10},
Documents are sets of attribute/value pairs Attributes can be structured lists, subobjects Collections external representation usually in JSON e.g. product catalog
{Name:"Jennifer", Age:8}, {Name:"Samantha", Age:5}, {Name:"Elena", Age:2} ], Job: “Tennis Trainer“ }
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
31
Graph Databases
Vertices usually objects (documents) Edges connecting two vertices directed (from → to) with type („knows“, „likes“) additional attributes e.g. relations between products [successor-of], [accessory-for], ..
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
32
Match between Domain Driven Design and NoSQL Datenbanken
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
33
Entities DDD
Document database
Entity
Identity
document every document has its own identity
ID or Key Attribut
Complex Structure
structured attributes
Variance
Schemaless
no EAV neccessary
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
34
Value Objects DDD
Value Object
Document database
document
Inmutability
or
Subobject in another document (Entity oder VO) must be implemented on the application layer
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
35
Aggregate DDD
Document database
Aggregate
Central Access
document with direct references to other document must be implemented on the application layer
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
36
Associations DDD
Graph database
Association
Edge between two documents
type of the association
type attribut of the edge
further properties
additional attributes
Access methods based on the associations
e.g. recommendations
Graph algorithms in the database
e.g. path search
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
37
Repositories DDD
NoSQL databases
Repository
Collection
Searching in Repositories
Queries
using appropriate Indices
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
38
Summary
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
39
DDD and Multi-Model-NoSQL-DBs are made for one another
A common language used by all participants throughout the project is critical for the success. Domain Driven Design is an approach that demands and supports such a language. Development with relational databases requires a unique language (and way of approaching modelling). Non-relational/NoSQL DBs are modern DBs that fit the changed constrains of modern software development better. There is a direct match between the language of Domain Driven Design and the concents of NoSQL DBs. Multi-Model Databases – that marry document- and graph-models – give a complete match in a single database. DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
40
triAGENS martin Schönert Geschäftsführer / executive director
[email protected] +49 170 8602158 triAGENS GmbH Hohenstaufenalle 43-45 50674 Köln
Die triAGENS GmbH ist ein Dienstleister im Bereich komplexer Informationssysteme und webbasierter Business-Lösungen, mit hohen Anforderungen an Performance, Skalierbarkeit und Sicherheit. triAGENS entwickelt High-PerformanceDatenbanken auf Basis optimierter NoSQLDatenbanktechnologien, die u.a. bei der Deutschen Post zum Einsatz kommen.
www.triagens.de The triAGENS GmbH is a service company in the area of complex IT Systems and web based business solutions with high requirements on performance, scalability and security. triAGENS supplies high performance databases based on NoSQL database technology, which are utilized for example by Deutsche Post.
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
41
Dokumentinformationen Metainformationen
Historie
Kontext Marketing Titel Domain Driven Design und NoSQL Ablage 70_Praesentationen ID TRI-MS-1409-001 Verantwortlich martin Schönert / triagens Leser öffentlich Sicherheitsein. öffentlich SchlüsselworteSoftwareentwicklung DDD Evans NoSQL Multi-Model
Version V1.00
Bearbeitungsschritte
Todos
Schritt Bearbeiter Finale Version m.Schönert
geplant bis 2014-09-01
Fertigstellung 2014-09-01
Kommentar
Folie -
Datum 2014-09-01
Bearbeiter m.Schönert
Kommentar Finale Version
Kommentar -
DevCon TLV | © 2014 triAGENS GmbH | 2014-06-05
42