To SQL or No(t)SQL - PHPNW12
-
Upload
jeroen-van-dijk -
Category
Technology
-
view
1.847 -
download
0
description
Transcript of To SQL or No(t)SQL - PHPNW12
PHPNW 2012 Jeroen van Dijk
To SQL
OR
No T SQL?( )
Sunday, October 7, 12
JEROEN VAN DIJK
∂Nerd chief @ ENRISE
∂PHPBenelux board member∂Zend Certified Engineer∂Web technology freak∂Open source addict
[email protected] @NEOREY
Sunday, October 7, 12
∂ You engineers are our top chefs!
THE ENRISE RESTAURANT
∂ We want to prepare the best dishes∂ With the best ingredients∂ To create a magical client experience!
Sunday, October 7, 12
Sunday, October 7, 12
WHAT IS
ACID?Sunday, October 7, 12
Sunday, October 7, 12
EVER HEARD OF
THEOREM?CAP
Sunday, October 7, 12
KNOW
ABC?∂ Courtesy of Tim Anglade
Sunday, October 7, 12
Always
∂ Courtesy of Tim Anglade
Sunday, October 7, 12
AlwaysBe
∂ Courtesy of Tim Anglade
Sunday, October 7, 12
AlwaysBeCaching
∂ Courtesy of Tim Anglade
Sunday, October 7, 12
AlwaysBeCaching
∂ Courtesy of Tim Anglade
Sunday, October 7, 12
JOIN THE HYPE?
WANT!==HAVE
Sunday, October 7, 12
HAVE TO USE NOSQL?
SCALABILITY&
PERFORMANCE
Sunday, October 7, 12
HAVE TO USE NOSQL?
SCALABILITY&
PERFORMANCE
Sunday, October 7, 12
RECAP RDBMS GREATNESS
∂ Standard Query Language∂ ACID: Atomicity, Consistency, Isolation, Durability∂ Supported by everyone and everything∂ Tuning options∂ Battle tested!∂ Open source?!
NOT ENOUGH?
Sunday, October 7, 12
MAKING LOADS OF MONEY?
Sunday, October 7, 12
BUY A BIGGER BOX
18
Sunday, October 7, 12
∂ Vertical scalability
NOT SO GREAT RDBMS FEATURES
Sunday, October 7, 12
NOT SO GREAT RDBMS FEATURES
∂ Vertical scalability
∂ Horizontal scalability
Sunday, October 7, 12
∂ Vertical scalability
∂ Horizontal scalability
∂ Schema changes!
NOT SO GREAT RDBMS FEATURES
Sunday, October 7, 12
SINCE 2004
DATA++++++
Sunday, October 7, 12
WHO NEEDS
ACID!?Sunday, October 7, 12
CAP THEOREM
PC
A
CONSISTENCY PARTITION TOLERANCE
AVAILABILITY
Sunday, October 7, 12
CAP THEOREM
P
CA AP
CP
C
AAVAILABILITY
PICKTWO
CONSISTENCY PARTITION TOLERANCE
Sunday, October 7, 12
CAP THEOREM
P
CA AP
CP
C
A
PARTITION TOLERANCE
PICKTWO
CONSISTENCY
MySQL (InnoDB, not MyISAM)
PostgreSQL SQL Server
Dynamo Voldemort
Cassandra
SimpleDB
CouchDB
Riak
BigTable
Hypertable Hbase
MongoDB Terrastore
Couchbase Memcache Redis
AVAILABILITY
Oracle RAC Neo4J
Sunday, October 7, 12
RELATIONAL DATABASES
ID FIRST LAST1 Jeroen van Dijk
2 Paul Borgermans
3 Thijs Feryn
4 Mike van Dam
5 Jeremy Coates
6 Jenny Wong
USERS
ID NAME1 PHPNorthWest
2 PHPBenelux
COMMUNITIES
ID COM_ID USER_ID PRIMARYT
NICK1 2 1 1 neorey
2 2 2 1 paulb
3 2 3 1 thijs
4 1 4 0 dragonbe
5 2 4 1 dragonbe
6 1 5 1 coates
7 1 6 1 miss_jwo
MEMBERS
Sunday, October 7, 12
NOSQL TYPES4
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
4 NOSQL MODELS
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
4 NOSQL TYPES
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
4 NOSQL TYPES
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
4 NOSQL TYPES
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
∂ 122 known NoSQL databases
4 NOSQL TYPES
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
∂ Focus from Redis, Riak, Neo4J, MongoDB
4 NOSQL TYPES
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
KEY - VALUE
∂ Schema-less design∂ Just strings of data∂ Hard to query∂ Mostly in memory
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
KEY - VALUE
USER_1
“Jeroen van Dijk”
USER_2
{ id: 3, first: “Thijs”, last: “Feryn”}
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
REDIS
∂ Blazing fast key-value implementation∂ Master - slave replication∂ Lots of methods to query data∂ Notable options∂ Data types : Strings, hashes, lists, sets∂ Data expiration∂ Pub/Sub for messaging
∂ Reconsider when using Memcached
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
COLUMN
∂ BigTable or Dynamo style∂ Consistent hashing∂ Vector clocks∂ Hinted hand off
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
COLUMN
DATABASE
USERS (COLUMN)
USER_5
USER_6
FIRST LAST GROUP
Jeremy Coates PHPNW
NAME NICK
Jenny Wong @miss_jwo
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
COLUMN
∂ Data stored in a ring
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
COLUMN
A
B
C
D
∂ Consistent hashing with 4 nodes
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
COLUMN
∂ Partitioning as done by Riak
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
COLUMN
∂ First node joins the cluster, claims all partitions
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
COLUMN
A
B
C
∂ Reading / writing is done to 3 nodes
N = 3
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
COLUMN
A
B
C
N = 3W = 2
R = 2
∂ Reading / writing succeeds with 2 valid responses
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
COLUMN
A
B
C
D
N = 3W = 2
R = 2[ Ov1 ]
[ Ov1,v2 ]
∂ Node C down, while new write action
[ Ov1,v2 ]
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
COLUMN
A
B
C
D
[ Ov1,v2 ]
N = 3
∂ Node D hands the new version off
N = 3W = 2
R = 2
[ Ov1,v2 ]
[ Ov1,v2 ]
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
RIAK
∂ Dynamo implementation∂ MapReduce query style∂ Multiple storage backends∂ Notable options
§ Link walking (like Graph solutions)§ Solr-like search interface§ Secondary indexes
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
∂ Relations more important than entities∂ From RDBMS perspective: SELF JOINS
GRAPH
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
∂ Facebook style
GRAPH
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
GRAPH
∂ Betweenness centrality
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
GRAPH
∂ Degree centrality
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
GRAPH
∂ Closeness centrality
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
GRAPH
∂ Twitter style
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
GRAPH
∂ TomTom style
2
1
1
33
92
31
2
2
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
GRAPH
2
1
1
33
92
31
2
2
∂ TomTom style
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
GRAPH
2
1
1
33
92
31
2
2
∂ TomTom style
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
NEO4J
∂ ACID compliant∂ Enterprise product for HA ($$$)∂ Custom query language∂ Notable options
§ Self contained web admin
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
DOCUMENT
∂ Largest resemblance with RDBMS∂ Familiar query language
§ $select->where(‘id’, $this->getId());
∂ Software architect more important
Sunday, October 7, 12
USER_2
{ first: “Paul”, last: “Borgermans”}
USER_4
{ first: “Michelangelo”, last: “van Dam”, communities: [ “PHPNW”: { id: 1, name: “PHPNW” }, “PHPBNL”: { id: 2, name: “PHPBenelux” } ]}
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
MONGODB
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
MONGODB
∂ MySQL of its generation?!∂ Replicas structure∂ MapReduce∂ Notable options
§ Geo indexes
SMALLEST LEARNING CURVE!
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
∂ Rapid changing data which fits in memory∂ Analytics, logging, real-time data collection
USE CASES
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
∂ Rapid changing data which fits in memory∂ Analytics, logging, real-time data collection
∂ Very good availability & fault tolerance ∂ Applications where seconds of downtime hurt
USE CASES
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
∂ Rapid changing data which fits in memory∂ Analytics, logging, real-time data collection
∂ Very good availability & fault tolerance ∂ Applications where seconds of downtime hurt
∂ For rich interconnected data∂ Social relational data, geo & maps data
USE CASES
Sunday, October 7, 12
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
∂ Rapid changing data which fits in memory∂ Analytics, logging, real-time data collection
∂ Very good availability & fault tolerance ∂ Applications where seconds of downtime hurt
∂ For rich interconnected data∂ Social relational data, geo & maps data
∂ MySQL like usage with indexes∂ Any type of data you’d fit in MySQL
USE CASES
Sunday, October 7, 12
NOSQL IS HERE TO STAY
THEREPLACEMENTS
Sunday, October 7, 12
NOSQL IS HERE TO STAY
THEREPLACEMENTS
Sunday, October 7, 12
ONE USEFUL INGREDIENT
Sunday, October 7, 12
MORE GREAT TASTES
Sunday, October 7, 12
∂ KLIK VOOR FOOTER
70
Sunday, October 7, 12
∂ KLIK VOOR FOOTER
71
Polyglot persistence?
Sunday, October 7, 12
∂ THANK YOU! FEEDBACK? JOIND.IN/6976
Sunday, October 7, 12
∂ MORE DETAILS? SCAN THIS CODE.Sunday, October 7, 12