1. To SQL
OR
No (T) SQL?
PHPNW 2012 Jeroen van Dijk
Sunday, October 7, 12
2. JEROEN VAN DIJK
∂ Nerd chief @ ENRISE
∂ PHPBenelux board member
∂ Zend Certified Engineer
∂ Web technology freak
∂ Open source addict
JEROEN@ENRISE.COM @NEOREY
Sunday, October 7, 12
3. THE ENRISE RESTAURANT
∂ We want to prepare the best dishes
∂ With the best ingredients
∂ To create a magical client experience!
∂ You engineers are our top chefs!
Sunday, October 7, 12
14. HAVE TO USE NOSQL?
SCALABILITY
&
PERFORMANCE
Sunday, October 7, 12
15. HAVE TO USE NOSQL?
SCALABILITY
&
PERFORMANCE
Sunday, October 7, 12
16. 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
24. CAP THEOREM
AVAILABILITY
A
C P
CONSISTENCY PARTITION TOLERANCE
Sunday, October 7, 12
25. CAP THEOREM
AVAILABILITY
A
CA AP
PICK
TWO
C P
CONSISTENCY PARTITION TOLERANCE
CP
Sunday, October 7, 12
26. CAP THEOREM
AVAILABILITY
MySQL (InnoDB, not MyISAM) A Dynamo Voldemort
PostgreSQL SQL Server Cassandra CouchDB
CA AP
Oracle RAC Neo4J SimpleDB Riak
PICK
TWO
C P
CONSISTENCY PARTITION TOLERANCE
CP
Hypertable Hbase
BigTable MongoDB Terrastore
Couchbase Memcache Redis
Sunday, October 7, 12
27. RELATIONAL DATABASES
USERS COMMUNITIES
ID FIRST LAST ID NAME
1 Jeroen van
Dijk 1 PHPNorthWest
2 Paul Borgermans 2 PHPBenelux
3 Thijs Feryn
4 Mike van
Dam MEMBERS
5 Jeremy Coates ID COM_ID USER_ID PRIMARY NICK
6 Jenny Wong 1 2 1 T
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
Sunday, October 7, 12
33. 4 NOSQL TYPES
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
∂ 122 known NoSQL databases
Sunday, October 7, 12
34. 4 NOSQL TYPES
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
∂ Focus from Redis, Riak, Neo4J, MongoDB
Sunday, October 7, 12
35. KEY - VALUE
KEY-VALUE ∂ Schema-less design
∂ Just strings of data
∂ Hard to query
COLUMN
∂ Mostly in memory
GRAPH
DOCUMENT
Sunday, October 7, 12
36. KEY - VALUE
KEY-VALUE
USER_1 USER_2
COLUMN
“Jeroen van Dijk” {
id: 3,
first: “Thijs”,
GRAPH
last: “Feryn”
}
DOCUMENT
Sunday, October 7, 12
37. REDIS
KEY-VALUE
∂ Blazing fast key-value implementation
∂ Master - slave replication
∂ Lots of methods to query data
COLUMN
∂ Notable options
∂ Data types : Strings, hashes, lists, sets
GRAPH ∂ Data expiration
∂ Pub/Sub for messaging
DOCUMENT
∂ Reconsider when using Memcached
Sunday, October 7, 12
38. COLUMN
KEY-VALUE ∂ BigTable or Dynamo style
∂ Consistent hashing
∂ Vector clocks
COLUMN
∂ Hinted hand off
GRAPH
DOCUMENT
Sunday, October 7, 12
39. COLUMN
KEY-VALUE DATABASE
USERS (COLUMN)
USER_5
COLUMN FIRST LAST GROUP
Jeremy Coates PHPNW
GRAPH USER_6
NAME NICK
Jenny
Wong @miss_jwo
DOCUMENT
Sunday, October 7, 12
40. COLUMN
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
∂ Data stored in a ring
Sunday, October 7, 12
41. COLUMN
D
KEY-VALUE
COLUMN
C A
GRAPH
DOCUMENT
B
∂ Consistent hashing with 4 nodes
Sunday, October 7, 12
42. COLUMN
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
∂ Partitioning as done by Riak
Sunday, October 7, 12
43. COLUMN
KEY-VALUE
COLUMN
GRAPH
DOCUMENT
∂ First node joins the cluster, claims all partitions
Sunday, October 7, 12
44. COLUMN
KEY-VALUE N=3 A
B
C
COLUMN
GRAPH
DOCUMENT
∂ Reading / writing is done to 3 nodes
Sunday, October 7, 12
45. COLUMN
KEY-VALUE N=3 A
B
W=2 C
COLUMN
R=2
GRAPH
DOCUMENT
∂ Reading / writing succeeds with 2 valid responses
Sunday, October 7, 12
46. COLUMN
KEY-VALUE N=3 A
[ Ov1,v2 ]
B
W=2 C [ Ov1 ]
COLUMN
R=2
D
[ Ov1,v2 ]
GRAPH
DOCUMENT
∂ Node C down, while new write action
Sunday, October 7, 12
47. COLUMN
KEY-VALUE N=3 A
[ Ov1,v2 ]
B
W=2 C [ Ov1,v2 ]
COLUMN
R=2
D
[ Ov1,v2 ]
GRAPH
DOCUMENT
∂ Node D hands the new version off
Sunday, October 7, 12
58. NEO4J
KEY-VALUE ∂ ACID compliant
∂ Enterprise product for HA ($$$)
∂ Custom query language
COLUMN
∂ Notable options
§ Self contained web admin
GRAPH
DOCUMENT
Sunday, October 7, 12
59. DOCUMENT
KEY-VALUE ∂ Largest resemblance with RDBMS
∂ Familiar query language
§ $select->where(‘id’, $this->getId());
COLUMN
∂ Software architect more important
GRAPH
DOCUMENT
Sunday, October 7, 12
61. MONGODB
KEY-VALUE ∂ MySQL of its generation?!
∂ Replicas structure
∂ MapReduce
COLUMN
∂ Notable options
§ Geo indexes
GRAPH
DOCUMENT
SMALLEST LEARNING CURVE!
Sunday, October 7, 12
62. USE CASES
∂ Rapid changing data which fits in memory
KEY-VALUE
∂ Analytics, logging, real-time data collection
COLUMN
GRAPH
DOCUMENT
Sunday, October 7, 12
63. USE CASES
∂ Rapid changing data which fits in memory
KEY-VALUE
∂ Analytics, logging, real-time data collection
∂ Very good availability & fault tolerance
COLUMN
∂ Applications where seconds of downtime hurt
GRAPH
DOCUMENT
Sunday, October 7, 12
64. USE CASES
∂ Rapid changing data which fits in memory
KEY-VALUE
∂ Analytics, logging, real-time data collection
∂ Very good availability & fault tolerance
COLUMN
∂ Applications where seconds of downtime hurt
∂ For rich interconnected data
GRAPH
∂ Social relational data, geo & maps data
DOCUMENT
Sunday, October 7, 12
65. USE CASES
∂ Rapid changing data which fits in memory
KEY-VALUE
∂ Analytics, logging, real-time data collection
∂ Very good availability & fault tolerance
COLUMN
∂ Applications where seconds of downtime hurt
∂ For rich interconnected data
GRAPH
∂ Social relational data, geo & maps data
∂ MySQL like usage with indexes
DOCUMENT
∂ Any type of data you’d fit in MySQL
Sunday, October 7, 12
66. NOSQL IS HERE TO STAY
THE
REPLACEMENTS
Sunday, October 7, 12
67. NOSQL IS HERE TO STAY
THE
REPLACEMENTS
Sunday, October 7, 12