scalable database, scalable language @ jdc 2013

Post on 29-Nov-2014

103 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Scalable database, Scalable language @ JDC 2013

TRANSCRIPT

Maciek Próchniak

Algebraic topologyhocolim

Group cohomology

Monads

GWT

TouKCamel

OSGi

CQRS

Scala

OrientDB

Poland, Egypt?

USA is scared :)

scalable database

OrientDB

scalable language

Scala

" ... a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way"

Scala about Scala

Potential client about Scala

"tiny market share and require a very specific type of developers, which is more likely to be found in an academic, rather than business environment"

OrientDB about OrientDB

"... an Open Source NoSQL DBMS with both the features of Document and Graph DBMSs.

"... written in Java and it's amazing fast: can store up to 150,000 records per second on common hardware"

Potential client about OrientDB

"OrientDB is another experimental product which is closely tied to European academia, much like Scala"

"Moreover, choosing a document-oriented database for a typical business/commercial application is simply an architectural mistake."

Really?

OracleMySQL

PostgreSQL

MongoCouchRiak

Neo4J

OracleMySQL

PostgreSQL

MongoCouchRiak

Neo4J

?

OracleMySQL

PostgreSQL

MongoCouchRiak

Neo4J

OrientDB

What's the real difference?

● Architecture

● Data model

● Data access

What's the real difference?

● Architecture

● Data model

● Data access

Consistency

Partition tolerance

Availability

P - do you really need it?

NoSQL is about scalability?

● Replication

● Sharding

- TBD

Need more consistency?

● Transactions

● Optimistic locking

● MVCC

NoSQL written in Java

● No additional software

● We all know how to tune JVM

... Don't we?

Architecture

Architecture - in memory

Architecture - embedded

Architecture - remote server

HTTPBinary

memory/local/remote

Impact: testability

Unit

Functional

Integration

H2/??

Mock

DevBase

Impact: testability

Unit

Functional

Integration

memory:/local:

mock/memory:

local:/remote:

What's the real difference?

● Architecture

● Data model

● Data access

Meet our domain

Customer

Address

Customer

EmailAddress

Branch

Email

How would you model that?

Address

Email

Branch Customer 1..* 1..*

1..*

Aggregate - consistency boundary

Aggregate: A collection of objects that are bound together by a root entity, otherwise known as an aggregate root.

Aggregate

The aggregate root guarantees the consistency of changes being made within the aggregate by forbidding external objects from holding references to its members.

Data model

Customer

Address

Customer

Email

Modification

Customer

Address

Customer

Email

Customer in OrientDB

When document is not enough

Data model

Customer

Address

Customer

Email

Customer

Modification

Address

Customer

Email

Graph - direct links

Customer Customer

Customer Customer

Documents

connected into

Graph

Connections in OrientDB

New possibilities

Europe

Poland France Romania

Warsaw Lublin Cracow Łódź

New possibilities

2012

Jan Feb March

1 2 3 4

OrientDB data model can reflect your domain model

better than document or relational bases

What's the real difference?

● Architecture

● Data model

● Data access

Let's get our hands dirty

Scala

● implicit conversions, parameters

● typeclasses

● for-comprehension

● infix notation

● case classes

Connecting - classic template

Connecting - classic - PROS

● Everybody knows it

● Simple

● Can easily do DI

● AOP

Composability?

Side effects?

Making DB interaction explicit

● Type constructortrait WithConnection[T]

Making DB interaction explicit

● Trivial interactiondef pt[T](a:T) : WithConnection[T]

Making DB interaction explicit

● Composing interactions def fmap[T](a:WithConnection[T],map:T=>WithConnection[H]) :

WithConnection[H]

Example

Example

for-comprehension

Composition

for-comprehension

Don't want to scary you...

... but I smell a monad here!

Scala - loading documents

Browsing documents - POJSON

Browsing documents - POJSON

Updating records

update customer set name = 'Maciej' where name = 'Maciek'

update customer add friends = #8:2

update customer put contactDetail = 'email2', 'mp@touk.pl'

Updating records - lens like

Updating records - lens like

Developers

know

SQL

ExtendedSQL

select from customer where name = 'maciek'

select labels[0] from customer where name = 'maciek'

select address.street from customer where contactDetails.email = 'mproch@g.pl'

ExtendedSQL

select from customers where trucks contains (capacity = 2)

select from suppliers where

trucks[capacity = 5].size() > 3

OrientDB

NotSoNoSQL

Scala queries

Graph queries

Developers

know

SQL

Traverse command

traverse customer.friends from #8:0 while $depth < 3

select from ( traverse customer.friends from #8:0 while $depth < 10 )where label contains nice

Traverse performance

Local operation - no joins

Constant lookup time

Traverse with scala predicates

Traverse with scala predicates

What about higher level access?

● ORM anybody?

● No need for partial updates, dirty checking?

JSON under the hood

Pluggable serialization strategies:

● Jackson

● Lift-Json

● ...

Scala serializer

Typesafe queries?

Scala

Language

Intergration

Connectivity

Kit

Lifted embedding

Lifted embedding - meta

Lifted embedding - meta

Lifted embedding - meta

Lifted embedding - query

Lifted embedding - query

Can we do better?

Direct embedding - meta

Direct embedding - query

Direct embedding - query

Type safety?

Functional Programming patterns help to create

flexible, robust data access code

Call for action!

● Try it!

● Use it

● Find bugs ;)

● Spread the word

https://github.com/nuvolabase/orientdb/

https://github.com/mproch/scala-orientdb

https://github.com/mproch/slick-orientdb

Take away:

● OrientDB data model can reflect your domain model better than document or relational bases

● Functional Programming patterns can help create flexible, robust data access code

شكرا

mpr@touk.plhttp://touk.plhttp://mproch.blogspot.com

top related