8/10/2019 Presentation 111005001354 Phpapp02
1/32
MySQL & NoSQL from a
PHP perspective
October 4th, 2011 - Tim Juravich
Tim Juravich@timjuravich
8/10/2019 Presentation 111005001354 Phpapp02
2/32
MySQL & NoSQL from a PHP perspective
Developer, Startup Junky
Lead projects in .NET, Ruby, and PHP
Book on PHP & CouchDB development out early next year from Packt Publishing
October 4th, 2011 - Tim Juravich
Who Am I?
8/10/2019 Presentation 111005001354 Phpapp02
3/32
MySQL & NoSQL from a PHP perspective
A high level discussion on NoSQL databases from the PHP developer POV
Well focus on Data Models
What we wont be able to talk about:- How each database scales, stores its data.
- CAP Theorem (http://tinyurl.com/nosql-cap)
Well touch on tools for us PHP Developers
October 4th, 2011 - Tim Juravich
What well talk about today
http://tinyurl.com/nosql-caphttp://tinyurl.com/nosql-cap8/10/2019 Presentation 111005001354 Phpapp02
4/32
MySQL & NoSQL from a PHP perspective
A data model defines how your application stores data and how it
makes associations.
If you force an incorrect data model into your application...youre
probably going to have a hard time.
October 4th, 2011 - Tim Juravich
Data Models
8/10/2019 Presentation 111005001354 Phpapp02
5/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
Traditional relational Model (MySQL)
id first_name last_name
1 John Doe
2 Jane Doe
users
id address city state zip user_id
1 123 MainStreet
Seattle WA 98101 1
2 120 PikeStreet
Seattle WA 98101 1
3 321 2ndAve
Seattle WA 98101 2
addresses
id number primary user_id
1 555-867-5309 1 1
2 555-867-5309 0 1
3 555-867-5309 1 2
phone numbers
8/10/2019 Presentation 111005001354 Phpapp02
6/32
MySQL & NoSQL from a PHP perspective
Nothing really...there are just limitations
- Due to normalization as your data grows so does the complexity of your
database
- As your database grows, writing becomes a bottleneck
- Difficult to scale horizontally
- Sometimes tables are just too limiting
October 4th, 2011 - Tim Juravich
Whats wrong with this?
8/10/2019 Presentation 111005001354 Phpapp02
7/32
MySQL & NoSQL from a PHP perspective
History
- Some NoSQL databases have been around forever
- In 2004 & 2005 they explode
NoSQL really means Not Only SQL
October 4th, 2011 - Tim Juravich
NoSQL databases are born
8/10/2019 Presentation 111005001354 Phpapp02
8/32
MySQL & NoSQL from a PHP perspective
The Good News
- Different tools for different situations
- Flexible (Schema-less)
- Focused on scalability out of the box
- New data models
The Bad News
- No common standards
- Relatively immature
- New data models
October 4th, 2011 - Tim Juravich
NoSQL
8/10/2019 Presentation 111005001354 Phpapp02
9/32
8/10/2019 Presentation 111005001354 Phpapp02
10/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
Size vs. Complexity
Typical RDMBS
Key/value Stores
Column Stores
Document Database
Graph Database
RDMBS Performance Line
Scale To Complexity
ScaleTo
Size
8/10/2019 Presentation 111005001354 Phpapp02
11/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
Key Value StoresDefinition
- Access to a value based on a unique key
- Think of this in terms of a hash-table, or in PHP an associative array.
John Doe
user_1
{ name: John Doe,email: [email protected],
phone: 8675309}
user_2
mailto:[email protected]:[email protected]8/10/2019 Presentation 111005001354 Phpapp02
12/32
MySQL & NoSQL from a PHP perspective
Strengths
- Incredibly Fast
- Pub/Sub support- Simple CLI
Weaknesses
- It can feel limiting with a complex use case
Use it for
- Rapidly changing data.
- Stocks, Analytics, Real-time collection/communication
October 4th, 2011 - Tim Juravich
Redis
redis> set im.a.key "im.a.value"OK
redis> get im.a.key
"im.a.value"
8/10/2019 Presentation 111005001354 Phpapp02
13/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
Redis & PHPThere are a variety of Redis & PHP toolkits (http://tinyurl.com/redis-php)
My favorite is Predis (https://github.com/nrk/predis)
Twitter clone to play with: (http://redis.io/topics/twitter-clone)
8/10/2019 Presentation 111005001354 Phpapp02
14/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
Column StoresDefinition
- Similar to relational database, but it flips it all around. Instead of storing
records, column stores store all of the values for a column together in astream. From there, you can use an index to get column values for a particular
record.
- Can handle 4 or 5 dimensions
Keyspace, Column Family, Column Family Row, Column
Keyspace, Column Family, Column Family Row, Super Column, Column
8/10/2019 Presentation 111005001354 Phpapp02
15/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
Column Stores
users (Column Family)
johndoe (key)
John Doe
name(column) email(column) phone(column)
[email protected] 5558675309
janedoe (key)
Jane Doe
name(column) email(column)
example-db (Keyspace)
8/10/2019 Presentation 111005001354 Phpapp02
16/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
CassandraStrengths
- Can handle some serious data
- Writes are much faster than reads
- Hadoop integration
Weaknesses
- Complex for its offering and bloated
Use it for
- Apps with a lot of writing. Serious applications.
8/10/2019 Presentation 111005001354 Phpapp02
17/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
Cassandra & PHPThrift
There are a few PHP libraries (http://tinyurl.com/cassandra-php)
My favorite is phpcassa (https://github.com/thobbs/phpcassa)
https://github.com/thobbs/phpcassahttps://github.com/thobbs/phpcassa8/10/2019 Presentation 111005001354 Phpapp02
18/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
Cassandra & PHP (phpcassa)
8/10/2019 Presentation 111005001354 Phpapp02
19/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
Document DatabasesDefinition
- Documents provide access to structured data, without a schema.
- Buckets of key-value pairs inside of a self contained object.- Friendliest NoSQL databases for PHP developers
8/10/2019 Presentation 111005001354 Phpapp02
20/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
Document Databases{ id: 'johndoe',
name: 'John Doe',
email : [email protected],
phone : 5558675309
addresses : [ address1 : {address: '123 main street',
city: 'seattle',
state: 'WA',
zip: 98101 },
address2 : {
address: '123 main street',
city: 'seattle',
state: 'WA',
zip: 98101 }
]
}
{ id: 'janedoe',
name: 'Jane Doe',
email : [email protected],
}
mailto:[email protected]:[email protected]:[email protected]:[email protected]8/10/2019 Presentation 111005001354 Phpapp02
21/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
MongoDBStrengths
- Familiar Query Language
- A lot of developer toolkits
Weaknesses
- Sharding can be a pain
Use it for
- Things you might do with MySQL, but schemas are getting in the way.
$post->where('id', $this->getID());
8/10/2019 Presentation 111005001354 Phpapp02
22/32
8/10/2019 Presentation 111005001354 Phpapp02
23/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
MongoDB & PHP (Active Mongo)
8/10/2019 Presentation 111005001354 Phpapp02
24/32
8/10/2019 Presentation 111005001354 Phpapp02
25/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
CouchDB & PHPNot as many as MongoDB (http://tinyurl.com/couch-php)
- Doctrine
- Variety of standalone libraries
My favorite is Sag (https://github.com/sbisbee/sag)
https://github.com/crodas/ActiveMongohttps://github.com/crodas/ActiveMongohttp://tinyurl.com/couch-phphttp://tinyurl.com/couch-php8/10/2019 Presentation 111005001354 Phpapp02
26/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
CouchDB & PHP (Sag)
8/10/2019 Presentation 111005001354 Phpapp02
27/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
Graph DatabasesDefinition
- Instead of tables, rows, columns, it's a flexible graph model that contains
nodes. Nodes have properties and relationships to other nodes.
8/10/2019 Presentation 111005001354 Phpapp02
28/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
Graph Databases
8/10/2019 Presentation 111005001354 Phpapp02
29/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
Neo4jStrengths
- Fully transactional
- Flexible APIWeaknesses
- A completely different way of thinking
- Complex
Use it for
- Social relations, road maps, network topologies
8/10/2019 Presentation 111005001354 Phpapp02
30/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
Neo4j & PHPThere are a few of options (http://tinyurl.com/neo4j-php)
- REST API
- ThriftIts pretty complex...
http://tinyurl.com/neo4j-phphttp://tinyurl.com/neo4j-php8/10/2019 Presentation 111005001354 Phpapp02
31/32
MySQL & NoSQL from a PHP perspective
October 4th, 2011 - Tim Juravich
So which DB should you use?Dont rule out relational databases
Do your homework
Every project is differentNoSQL probably should be avoided in these areas
- Transactions, orders, anything where money changes hands
- Business critical data or line of business applications
8/10/2019 Presentation 111005001354 Phpapp02
32/32
Thanks!Feel free to reach out with any questions:
@timjuravich
mailto:[email protected]:[email protected]Top Related