140
Long story short, a true tale about an hopeless DevTeam CMF: a pain in the F David Funaro & Alessandro Nadalin May, 14 2011

CMF: a pain in the F @ PHPDay 05-14-2011

Embed Size (px)

DESCRIPTION

A presentation about the problems you'll face when dealing with the relational model and highly customizable general-purpose projects, with a look at the NoSQL word focusing on a real solution, a graph database.

Citation preview

Page 1: CMF: a pain in the F @ PHPDay 05-14-2011

Long story short, a true tale about an hopeless DevTeam

CMF: a pain in the F

David Funaro & Alessandro NadalinMay, 14 2011

Page 2: CMF: a pain in the F @ PHPDay 05-14-2011

let us introduce

The Problem™

Page 3: CMF: a pain in the F @ PHPDay 05-14-2011

There comes the boss< there's a new project

Page 4: CMF: a pain in the F @ PHPDay 05-14-2011

There comes the boss

< seems easy, let's use Joomla!

Page 5: CMF: a pain in the F @ PHPDay 05-14-2011

Don't open that door!

Page 6: CMF: a pain in the F @ PHPDay 05-14-2011

The 80/20 dilemma

CMS

Page 7: CMF: a pain in the F @ PHPDay 05-14-2011

80% is cool at all

Page 8: CMF: a pain in the F @ PHPDay 05-14-2011

but as

the requirements grows

Page 9: CMF: a pain in the F @ PHPDay 05-14-2011

(you always knew that)

Page 10: CMF: a pain in the F @ PHPDay 05-14-2011

the project becomes a mess

Page 11: CMF: a pain in the F @ PHPDay 05-14-2011

There comes the boss< can I haz fotonic menthal scanner in the website

Page 12: CMF: a pain in the F @ PHPDay 05-14-2011

There comes the boss

< can't do boss Joomla! is not meant...

Page 13: CMF: a pain in the F @ PHPDay 05-14-2011

There comes the boss< STFU NOOB DO THAT OR BLA BLA BLA

Page 14: CMF: a pain in the F @ PHPDay 05-14-2011

what if

Page 15: CMF: a pain in the F @ PHPDay 05-14-2011

There comes the boss

< seems complex,no Joomla this time,

let's use a framework!

Page 16: CMF: a pain in the F @ PHPDay 05-14-2011

There comes the boss< STFU NOOB WE SHOULD GO LIVE NEXT WEEK BLA BLA

Page 17: CMF: a pain in the F @ PHPDay 05-14-2011

The 20/80 dilemma

Framework

Page 18: CMF: a pain in the F @ PHPDay 05-14-2011

20% is cool at all

Page 19: CMF: a pain in the F @ PHPDay 05-14-2011

the 80%is reallyfunny

Page 20: CMF: a pain in the F @ PHPDay 05-14-2011

but has a cost

Time To Market

Page 21: CMF: a pain in the F @ PHPDay 05-14-2011

again, what if

Page 22: CMF: a pain in the F @ PHPDay 05-14-2011

There comes the boss

< seems complex,no Joomla this time,

when should it go live?

Page 23: CMF: a pain in the F @ PHPDay 05-14-2011

There comes the boss< salesguy just told the client tomorrow

Page 24: CMF: a pain in the F @ PHPDay 05-14-2011

There comes the boss

< ok, let's use a CMF

Page 25: CMF: a pain in the F @ PHPDay 05-14-2011

unfortunately, there is no stableCMF in the PHP ecosystem

Page 26: CMF: a pain in the F @ PHPDay 05-14-2011

so it has a cost

initial development

Page 27: CMF: a pain in the F @ PHPDay 05-14-2011

investment=

know how (team) + quality (framework) +

velocity (that customers pretend)

=

CMF

Page 28: CMF: a pain in the F @ PHPDay 05-14-2011

"Our" CMF

Page 29: CMF: a pain in the F @ PHPDay 05-14-2011

should be able to manage a site editing pages withdifferent elements.

Easily, like a CMS.

Target: End User/Site admin

Page 30: CMF: a pain in the F @ PHPDay 05-14-2011

Target: Developer

should be able to plug the CMF with NO PAIN,using the kick-ass framework at the bottom of the CMF.

Page 31: CMF: a pain in the F @ PHPDay 05-14-2011
Page 32: CMF: a pain in the F @ PHPDay 05-14-2011

2things

Page 33: CMF: a pain in the F @ PHPDay 05-14-2011

Pages

Page 34: CMF: a pain in the F @ PHPDay 05-14-2011

Pages

main structure of a web site organized as a treea way to express our contentsusually composed by a series of containers ( that we'll refer to as boxes )

Page 35: CMF: a pain in the F @ PHPDay 05-14-2011

Boxes

Page 36: CMF: a pain in the F @ PHPDay 05-14-2011

Boxes

The way to separate single elements of a page

Loosely coupled HMVC structures

Page 37: CMF: a pain in the F @ PHPDay 05-14-2011

Entities

Boxes {Bridge}

Pages

Boxes let entities be shown inside webpages

Page 38: CMF: a pain in the F @ PHPDay 05-14-2011

Boxes

We dispose of different types of boxes:

CommonDSL

Page 39: CMF: a pain in the F @ PHPDay 05-14-2011

Common Box

Simple Input field TextareaVideoImageFile Richtext

CompositeInput field + imageinput field + image + richetextextarea + video

Page 40: CMF: a pain in the F @ PHPDay 05-14-2011

what about the DSL?

Page 41: CMF: a pain in the F @ PHPDay 05-14-2011

Domain Specific Language

DSL = ! (Website 1 Website 2 )

Page 42: CMF: a pain in the F @ PHPDay 05-14-2011

Event

News Users

Books Review

Page

Widget

Event

News

UsersCars

Contract

Widget

Page

Example: Identify DSL

Page 43: CMF: a pain in the F @ PHPDay 05-14-2011

Cars

Contract

NewsBooks

Review

Page

Widget

DSL

Web Elements = CMF Entities

Page 44: CMF: a pain in the F @ PHPDay 05-14-2011

back to the CMF

Page 45: CMF: a pain in the F @ PHPDay 05-14-2011

CMF Stack

Framework: symfony, for exampleCMF entities: Site, Pages, Menus, Users ...DSL entities: cars, contracts (for Hertz)Common Boxes : Textarea, image, video, ...Dsl boxes: Cars image gallery

Page 46: CMF: a pain in the F @ PHPDay 05-14-2011

Common Boxes + DSL Boxes=

The main tool for the developer to build a page with the CMF

Page 47: CMF: a pain in the F @ PHPDay 05-14-2011

Example : page & box composition

Page 48: CMF: a pain in the F @ PHPDay 05-14-2011

The Page-Box Binding Storage

Data can change its structure fastly, according to the domain model.

We need a technology supporting this fast change.

Since we have N box type, to compose a page we shouldlook for a few tables.

We need a technology supporting this kind of lookups.

Page 49: CMF: a pain in the F @ PHPDay 05-14-2011

so,How will we

manage the data?

Page 50: CMF: a pain in the F @ PHPDay 05-14-2011

RDBMS, of course

Page 51: CMF: a pain in the F @ PHPDay 05-14-2011

because different data always have

the same need

Page 52: CMF: a pain in the F @ PHPDay 05-14-2011

one size fits all

Page 53: CMF: a pain in the F @ PHPDay 05-14-2011

We tend to think at the way we should store data

not how we're gonna use it

Page 54: CMF: a pain in the F @ PHPDay 05-14-2011

and we think that the

shit-it-always-happens migration

will be easy

Page 55: CMF: a pain in the F @ PHPDay 05-14-2011

also if that column is useful for one and one only row

Page 56: CMF: a pain in the F @ PHPDay 05-14-2011

among milions

Page 57: CMF: a pain in the F @ PHPDay 05-14-2011

so we know we're gonna facea few well-known problems...

Page 58: CMF: a pain in the F @ PHPDay 05-14-2011

Data Mapping

Data Structure RDBMS

id 10

name tom

parent_id 19

we have to find a way to re-organize the data-structre to insert our tree inside a table.But is really different! Tree find a node in O(nlogn)

Page 59: CMF: a pain in the F @ PHPDay 05-14-2011

Data Mapping

Data Structure RDBMS

is better than before, but isn't the best way

Page 60: CMF: a pain in the F @ PHPDay 05-14-2011

Data Mapping

Data Structure RDBMS

... and NOW??????

?

Page 61: CMF: a pain in the F @ PHPDay 05-14-2011

The Alien

BUT you always find

something that as a different Behaviour

spend more time to normalize your models

Page 62: CMF: a pain in the F @ PHPDay 05-14-2011

Unpredictable Tomorrow

User Story evolve continous

Worse than the Alien

Page 63: CMF: a pain in the F @ PHPDay 05-14-2011

EAVformerly known as:

normalization WTF?!?!?!

or:how to do 70k joins to retrieve an entity of you model

Page 64: CMF: a pain in the F @ PHPDay 05-14-2011

Overnormalized

user_id | mail_iduser_id | phone_id

user_id | address_id

user_id | mail | phone | address

Large schema is broken into smaller ones

Page 65: CMF: a pain in the F @ PHPDay 05-14-2011

Overnormalized

user_id | address_id

user_id | phone_id

user_id | mail_id

...

...

...

...

...

LEFT JOIN

LEFT JOIN

LEFT JOIN

Page 66: CMF: a pain in the F @ PHPDay 05-14-2011

Overnormalized

Users ListLEFT JOIN

LEFT JOIN

LEFT JOIN

LEFT JOINLEFT JOIN

LEFT JOINLEFT JOIN

Page 67: CMF: a pain in the F @ PHPDay 05-14-2011

Overnormalized

LEFT JOIN

LEFT JOIN

LEFT JOINLEFT JOIN

LEFT JOIN

LEFT JOIN

LEFT JOINLEFT JOINLEFT JOIN

LEFT JOINLEFT JOIN

LEFT JOIN

LEFT JOIN

LEFT JOINLEFT JOIN

LEFT JOIN

LEFT JOINLEFT JOIN

What if you need to show only a single primary address?

Users List

Page 68: CMF: a pain in the F @ PHPDay 05-14-2011

back to the CMF

Page 69: CMF: a pain in the F @ PHPDay 05-14-2011

Bind Page with Boxes

Foreing Key -> TextareaBox

Page 70: CMF: a pain in the F @ PHPDay 05-14-2011

Bind Page with Boxes

Foreing Key -> ?

AND NOWAND NOW ???

Page 71: CMF: a pain in the F @ PHPDay 05-14-2011

Mantain the RI#1

Page 72: CMF: a pain in the F @ PHPDay 05-14-2011

Not Mantain the RI#2

Page 73: CMF: a pain in the F @ PHPDay 05-14-2011

Maintain or not Maintain the RI; that is the

question

Page 74: CMF: a pain in the F @ PHPDay 05-14-2011

we have to choose

Page 75: CMF: a pain in the F @ PHPDay 05-14-2011

have you ever thought

"there should beanother way!"

?

Page 76: CMF: a pain in the F @ PHPDay 05-14-2011

Can someone help us?

Page 77: CMF: a pain in the F @ PHPDay 05-14-2011

NoSQLlets try

world

Page 78: CMF: a pain in the F @ PHPDay 05-14-2011

Written in: C/C++ Main point: Blazing fastProtocol: Telnet-likeDisk-backed in-memory database, but since 2.0, it can swap to disk. Master-slave replication Simple keys and values, but complex operations like ZREVRANGEBYSCORE INCRValues can be set to expire (as in a cache)

$ redis-cli set mykey "my binary safe value" => OK $ redis-cli get mykey => my binary safe value

Page 79: CMF: a pain in the F @ PHPDay 05-14-2011

Best used: rapidly changing data with a foreseeable database size (should fit mostly in memory)

For example: analyticsreal-time data collectioncachingMQlog

http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis

Page 80: CMF: a pain in the F @ PHPDay 05-14-2011

very fast

Page 81: CMF: a pain in the F @ PHPDay 05-14-2011

Object != key -> value

very fast

Page 82: CMF: a pain in the F @ PHPDay 05-14-2011

Object != key -> value

Not reliable

very fast

Can I haz otha nozql?

Page 83: CMF: a pain in the F @ PHPDay 05-14-2011

> j = { name : 'david', surname : 'funaro' };

{ "name" : "david", "surname" : "funaro" }

> db.things.save(t);

> db.things.find();

{ "_id" : ObjectId("4c2209f9f3924d31102bd84a"), "name" : "mongo" }

Written in: C++ Main point: Retains some friendly properties of SQLProtocol: Custom, binary (BSON) Master/slave replication speaks JavaScriptBuilt-in shardingPerformance over features After crash, it needs to repair tables

Page 84: CMF: a pain in the F @ PHPDay 05-14-2011

Best used:you need dynamic queriesyou prefer to define indexes, not map/reduce functionsyou need good performance on a big DB

For example: all things that you would do with MySQL or PostgreSQL, but having predefined columns really holds you back

http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis

Page 85: CMF: a pain in the F @ PHPDay 05-14-2011

Document Oriented

Page 86: CMF: a pain in the F @ PHPDay 05-14-2011

Document Oriented

Schema Free

Page 87: CMF: a pain in the F @ PHPDay 05-14-2011

Document Oriented

Schema Free

Navigate Object

Can I haz otha nozql?

Page 88: CMF: a pain in the F @ PHPDay 05-14-2011

Written in: Erlang Main point: DB consistency, ease of useProtocol: HTTP, some say RESTBi-directional replication => master-masterconflict detection ( 409 Conflict )MVCC: write operations do not block reads Previous versions of documents are available Crash-only (reliable) design Needs compacting from time to time Views: embedded map/reducejQuery library included

curl -d '{"keys":["bar"]}' -X POST http://host:port/foo/_all_docs?include_docs=true

Page 89: CMF: a pain in the F @ PHPDay 05-14-2011

Best used: accumulating occasionally-changing datapre-defined queriesversioning is king

For example: CRM/CMS systemsAPI

http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis

Page 90: CMF: a pain in the F @ PHPDay 05-14-2011

Reliable

Page 91: CMF: a pain in the F @ PHPDay 05-14-2011

Document Oriented

Reliable

Page 92: CMF: a pain in the F @ PHPDay 05-14-2011

Document Oriented

Schema Free

Reliable

Page 93: CMF: a pain in the F @ PHPDay 05-14-2011

Document Oriented

Schema Free

Navigate Object

Reliable

Can I haz otha nozql?

Page 94: CMF: a pain in the F @ PHPDay 05-14-2011

Why do we so hardlyneed a GraphDBlike OrientDB?

Page 95: CMF: a pain in the F @ PHPDay 05-14-2011

"GraphDBs don't avoid relations but they embrace them in a way that they are not a computational problem anymore, by making them explicit instead of implicit through joins."

Claudio Martella( http://blog.acaro.org/entry/somebody-is-going-to-hate-me-nosparql )

Page 96: CMF: a pain in the F @ PHPDay 05-14-2011

Easy joins

select from users where city.country.continent = 'Oceania'

Page 97: CMF: a pain in the F @ PHPDay 05-14-2011

Same link semantics,different objects

select links from menu >> 28:1, 17:5

Page 98: CMF: a pain in the F @ PHPDay 05-14-2011

Same link semantics,different objects

select from [28:1, 17:5]

28:1

ExternalLinkurl: http://www.google.com

17:5

ProductLinkid: 4

Page 99: CMF: a pain in the F @ PHPDay 05-14-2011

28:1

ExternalLinkurl: http://www.google.com

17:5

ProductLinkid: 4

$link->render()

Page 100: CMF: a pain in the F @ PHPDay 05-14-2011

Written in: JavaMain point: GraphProtocol: Binary or HTTPACIDDisk-persisted or in-memory,Cluster150k inserts per secondSchema-less, *-full, *-mixedSpeaks JSONIntegrated GUIDocumentalSQL commands

curl -X PUT '127.0.0.1:2480/document/demo/1:2' --data "{'@rid': '1:2'}"

Page 101: CMF: a pain in the F @ PHPDay 05-14-2011

Reliable

Page 102: CMF: a pain in the F @ PHPDay 05-14-2011

Graph - Documental

Reliable

Page 103: CMF: a pain in the F @ PHPDay 05-14-2011

Graph - Documental

Schema-*

Reliable

Page 104: CMF: a pain in the F @ PHPDay 05-14-2011

Graph - Documental

Schema-*

Reliable

Easy traversal

Page 105: CMF: a pain in the F @ PHPDay 05-14-2011

Graph - Documental

Schema-*

Reliable

Easy traversal

SQL-friendly

Page 106: CMF: a pain in the F @ PHPDay 05-14-2011

Graph - Documental

Schema-*

Reliable

Easy traversal

SQL-friendly

UberFast ( binary protocol )

Page 107: CMF: a pain in the F @ PHPDay 05-14-2011

Graph - Documental

Schema-*

Reliable

Easy traversal

SQL-friendly

UberFast ( binary protocol )

Universal ( HTTP protocol )

Page 108: CMF: a pain in the F @ PHPDay 05-14-2011

is so cool

Page 109: CMF: a pain in the F @ PHPDay 05-14-2011

but has a problem...

Page 110: CMF: a pain in the F @ PHPDay 05-14-2011

ver 1.0

Page 111: CMF: a pain in the F @ PHPDay 05-14-2011

rc1

Page 112: CMF: a pain in the F @ PHPDay 05-14-2011

but has a couple problems...

Page 113: CMF: a pain in the F @ PHPDay 05-14-2011

JAVA

Page 114: CMF: a pain in the F @ PHPDay 05-14-2011

but somebody

Page 115: CMF: a pain in the F @ PHPDay 05-14-2011

started writing the binary-protocol binding

https://github.com/AntonTerekhov/OrientDB-PHP( beta, 28 April 2010 )

Page 116: CMF: a pain in the F @ PHPDay 05-14-2011

and others

Page 117: CMF: a pain in the F @ PHPDay 05-14-2011
Page 118: CMF: a pain in the F @ PHPDay 05-14-2011

wrote the HTTP one

https://github.com/odino/Orient

Page 119: CMF: a pain in the F @ PHPDay 05-14-2011

$driver = new Orient\Http\Client\Curl();$orient = new Orient\Foundation\Binding( $driver, '127.0.0.1', '2480', 'admin', 'admin', 'demo');

$response = $orient->query("select from fellas where any() traverse(0,-1) ( @rid = 1:1 )");

$output = json_decode($response->getBody());foreach ($output->result as $friend){ echo $friend->name;

// other fun...}

Page 120: CMF: a pain in the F @ PHPDay 05-14-2011

you can start playing with a pure

GraphDB now

Page 121: CMF: a pain in the F @ PHPDay 05-14-2011

High-level PHP Component?

Page 122: CMF: a pain in the F @ PHPDay 05-14-2011

No

Page 123: CMF: a pain in the F @ PHPDay 05-14-2011

but we know that ;)

Page 124: CMF: a pain in the F @ PHPDay 05-14-2011

that's why in DNSEE we will build a basic

Object Graph Mapperfor OrientDB

Page 125: CMF: a pain in the F @ PHPDay 05-14-2011

...because...

Page 126: CMF: a pain in the F @ PHPDay 05-14-2011

hey, you remember about our CMF?

Page 127: CMF: a pain in the F @ PHPDay 05-14-2011

codename: ConGoW

Page 128: CMF: a pain in the F @ PHPDay 05-14-2011

codename: ConGoW

contents gone wild

( don't ask why )

Page 129: CMF: a pain in the F @ PHPDay 05-14-2011

ConGoW

soon the real kickstart

Page 130: CMF: a pain in the F @ PHPDay 05-14-2011

ConGoW

soon the real kickstart10 devs at the starting point

Page 131: CMF: a pain in the F @ PHPDay 05-14-2011

ConGoW

soon the real kickstart10 devs at the starting pointOSS on GitHub

Page 132: CMF: a pain in the F @ PHPDay 05-14-2011

ConGoW

soon the real kickstart10 devs at the starting pointOSS on GitHubStack

Symfony2

Page 133: CMF: a pain in the F @ PHPDay 05-14-2011

ConGoW

soon the real kickstart10 devs at the starting pointOSS on GitHubStack

Symfony2Orient

Page 134: CMF: a pain in the F @ PHPDay 05-14-2011

ConGoW

soon the real kickstart10 devs at the starting pointOSS on GitHubStack

Symfony2OrientDoctrine2

Page 135: CMF: a pain in the F @ PHPDay 05-14-2011

"My only friend, the end"

Page 136: CMF: a pain in the F @ PHPDay 05-14-2011

"My only friend, the end"

David [email protected]

Page 137: CMF: a pain in the F @ PHPDay 05-14-2011

"My only friend, the end"

David [email protected]

Alessandro Nadalin@_odino_

odino.org

Page 138: CMF: a pain in the F @ PHPDay 05-14-2011

"My only friend, the end"

David [email protected]

Alessandro Nadalin@_odino_

odino.org

Page 139: CMF: a pain in the F @ PHPDay 05-14-2011

"My only friend, the end"

David Funaro@ingdavidinohttp://davidfunaro.com

Alessandro Nadalin@_odino_

http://odino.org

http://joind.in/talk/view/3008

Page 140: CMF: a pain in the F @ PHPDay 05-14-2011

Creditshttp://www.flickr.com/photos/pagedooley/5313217918/sizes/l/in/photostream/

http://www.flickr.com/photos/zoetnet/5520594473/sizes/l/in/photostream/http://www.flickr.com/photos/mhxbhd/3962410821/sizes/o/in/photostream/

http://www.flickr.com/photos/labyrinthx/1955594336/sizes/z/in/photostream/http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis

http://www.flickr.com/photos/salim/19426192/sizes/o/in/photostream/http://www.flickr.com/photos/mybluevan/3780363712/sizes/l/in/photostream/

http://farm4.static.flickr.com/3064/3086258014_f1925639e0.jpg