PHP perspective
Tim Juravich
@timjuravich
October 4th, 2011 - Tim Juravich
Who Am I?
Developer, Startup Junky
Lead projects in .NET, Ruby, and PHP
Book on PHP & CouchDB development out early next year from Packt Publishing
Data Models
A data model defines how your application stores data and how it
makes associations.
addresses
id
address
city
state
zip
user_id
123 Main
Street
Seattle
WA
98101
Seattle
WA
98101
Seattle
WA
98101
2
3
120 Pike
Street
321 2nd
Ave
phone numbers
id
number
primary
user_id
1
2
555-867-5309
555-867-5309
1
0
1
1
555-867-5309
2
October 4th, 2011 - Tim Juravich
id
first_name last_name
John
Doe
Jane
Doe
NoSQL
The Good News
- Different tools for different situations
- Flexible (Schema-less)
- Focused on scalability out of the box
- New data models
Scale To Size
Column Stores
Document Database
Graph Database
Typical RDMBS
RDMBS Performance Line
Scale To Complexity
October 4th, 2011 - Tim Juravich
user_2
John Doe
Redis
Strengths
- Incredibly Fast
- Pub/Sub support
- Simple CLI
Weaknesses
Use it for
- Rapidly changing data.
- Stocks, Analytics, Real-time collection/communication
<?php
$redis = new Predis\Client();
$redis->set('foo', 'bar');
$value = $redis->get('foo');
Twitter clone to play with: (http://redis.io/topics/twitter-clone)
Column Stores
Definition
- 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 a
stream. 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
Column Stores
example-db (Keyspace)
users (Column Family)
johndoe (key)
name (column)
email (column)
phone (column)
John Doe
john@example.com
5558675309
janedoe (key)
name (column)
email (column)
Jane Doe
jane@example.com
Cassandra
Strengths
- 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.
// Create User
$users->insert('2, array('name' => 'Jane Doe',
'email' => 'jane@example.com'));
// Get User
$users->get('2');
Document Databases
Definition
- 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
Document Databases
{ id: 'johndoe',
name: 'John Doe',
email : john@example.com,
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 : jane@example.com,
}
MongoDB
Strengths
$post->where('id',
$this->getID());
Weaknesses
- Sharding can be a pain
Use it for
- Things you might do with MySQL, but schemas are getting in the way.
CouchDB
Strengths
- Bi-lateral replication (master-master)
- Slick RESTful JSON API, easy to use
Weaknesses
- Need some Javascript chops
- Slower writes
Use it for
- Mobile, CRM, CMS systems, multi-site deployments
Graph Databases
Definition
- Instead of tables, rows, columns, it's a flexible graph model that contains
nodes. Nodes have properties and relationships to other nodes.
Graph Databases
Neo4j
Strengths
- Fully transactional
- Flexible API
Weaknesses
- A completely different way of thinking
- Complex
Use it for
- Social relations, road maps, network topologies
Thanks!
Feel free to reach out with any questions:
tim.juravich@gmail.com
@timjuravich