SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Downloaden Sie, um offline zu lesen
MySQL & NoSQL from a
PHP perspective



                                            Tim Juravich
                                            @timjuravich
         October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




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




                               October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




What we’ll talk about today
• A high level discussion on NoSQL databases from the PHP developer POV
• We’ll focus on Data Models
• What we won’t be able to talk about:
  - How each database scales, stores it’s data.
  - CAP Theorem (http://tinyurl.com/nosql-cap)

• We’ll touch on tools for us PHP Developers




                                October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




Data Models
A data model defines how your application stores data and how it
makes associations.


If you force an incorrect data model into your application...you’re
probably going to have a hard time.




                                 October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




 Traditional relational Model (MySQL)
          addresses                                                                          users
id    address      city      state     zip        user_id                               id   first_name last_name
      123 Main
1                 Seattle     WA      98101         1
       Street                                                                           1       John       Doe
      120 Pike
2                 Seattle     WA      98101         1
       Street                                                                           2       Jane       Doe
      321 2nd
3                 Seattle     WA      98101         2
        Ave


      phone numbers
 id      number             primary      user_id

 1    555-867-5309            1               1
 2    555-867-5309            0               1
 3    555-867-5309            1               2


                                                     October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




What’s wrong with this?
• 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
MySQL & NoSQL from a PHP perspective




NoSQL databases are born
• History
  - Some NoSQL databases have been around forever
  - In 2004 & 2005 they explode

• NoSQL really means “Not Only SQL”




                              October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




NoSQL
• 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
MySQL & NoSQL from a PHP perspective




There are no silver bullets!




          October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




Size vs. Complexity
                 Key/value Stores
                                     Column Stores
                                                                       Document Database
 Scale To Size




                                                                                  Graph Database


                           Typical RDMBS


                                    RDMBS Performance Line



                                Scale To Complexity
                                    October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




Key Value Stores
• Definition
   - Access to a value based on a unique key
   - Think of this in terms of a hash-table, or in PHP an associative array.


                 user_1                                            user_2
               “John Doe”                         { name: “John Doe”,
                                                    email: john@example.com”,
                                                    phone: “8675309”
                                                  }




                                October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




Redis
• Strengths
   - Incredibly Fast
   - Pub/Sub support      redis> set im.a.key "im.a.value"
                          OK
   - Simple CLI           redis> get im.a.key
                          "im.a.value"
• 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
MySQL & NoSQL from a PHP perspective




Redis & PHP
• There are a variety of Redis & PHP toolkits (http://tinyurl.com/redis-php)
• My favorite is Predis (https://github.com/nrk/predis)

          <?php
          $redis = new PredisClient();
          $redis->set('foo', 'bar');
          $value = $redis->get('foo');


• Twitter clone to play with: (http://redis.io/topics/twitter-clone)



                                 October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




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




                                  October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




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




                        October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




Cassandra
• Strengths
   - Can handle some serious data
   - Writes are much faster than reads

   - Hadoop integration

• Weaknesses
   - Complex for it’s offering and bloated

• Use it for
   - Apps with a lot of writing. Serious applications.




                                  October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




Cassandra & PHP
• Thrift
• There are a few PHP libraries (http://tinyurl.com/cassandra-php)
• My favorite is phpcassa (https://github.com/thobbs/phpcassa)




                               October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




Cassandra & PHP (phpcassa)
<?php

// Connect to Keyspace
$pool = new ConnectionPool('example-db');


// Create ColumnFamily
$users = new ColumnFamily($pool, 'users');


// Create User
$users->insert('2’, array('name' => 'Jane Doe',
                          'email' => 'jane@example.com'));

// Get User
$users->get('2');



                          October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




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




                                October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




    Document Databases
{ id: 'johndoe',                                                   { id: 'janedoe',
  name: 'John Doe',                                                  name: 'Jane Doe',
  email : ‘john@example.com’,                                        email : ‘jane@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’ }
              ]
}




                                      October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




MongoDB
• Strengths
   - Familiar Query Language                     $post->where('id',       $this->getID());


   - 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.




                                   October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




MongoDB & PHP
• A TON of libraries (http://tinyurl.com/mongo-php)
   - Doctrine
   - Cake

   - Code Ignitor
   - Symfony
   - Zend

   - etc.

• My favorite is ActiveMongo (https://github.com/crodas/ActiveMongo)



                              October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




MongoDB & PHP (Active Mongo)
<?php
ActiveMongo::connect('example-db', 'localhost');

class User extends ActiveMongo
{
  public $name;
  public $email;
}

$user = new User();
$user->name = 'John Doe';
$user->email = 'john@example.com';

// Insert
$user->save();

// Update
$user->email = 'john@example.org';
$user->save();

                          October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




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




                                October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




CouchDB & PHP
• Not as many as MongoDB (http://tinyurl.com/couch-php)
   - Doctrine
   - Variety of standalone libraries

• My favorite is Sag (https://github.com/sbisbee/sag)




                                 October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




CouchDB & PHP (Sag)
<?php
class User
{
  public $name;
  public $email;
}

$user = new User();
$user->name = 'John Doe';
$user->email = 'john@example.com';

$sag = new Sag('127.0.0.1', '5984');
$sag->setDatabase('example-db');
$sag->post($user);




                          October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




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.




                                October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




Graph Databases




           October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




Neo4j
• Strengths
   - Fully transactional
   - Flexible API

• Weaknesses
   - A completely different way of thinking
   - Complex

• Use it for
   - Social relations, road maps, network topologies




                               October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




Neo4j & PHP
• There are a few of options (http://tinyurl.com/neo4j-php)
   - REST API
   - Thrift

• It’s pretty complex...




                               October 4th, 2011 - Tim Juravich
MySQL & NoSQL from a PHP perspective




So which DB should you use?
• Don’t rule out relational databases
• Do your homework
• Every project is different
• NoSQL probably should be avoided in these areas
   - Transactions, orders, anything where money changes hands
   - Business critical data or line of business applications




                                 October 4th, 2011 - Tim Juravich
Thanks!
Feel free to reach out with any questions:
        tim.juravich@gmail.com
              @timjuravich




            October 4th, 2011 - Tim Juravich

Weitere ähnliche Inhalte

Andere mochten auch

Speed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisSpeed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisRicard Clau
 
Database Management System Introduction
Database Management System IntroductionDatabase Management System Introduction
Database Management System IntroductionSmriti Jain
 
CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationGuru Ji
 
1. Introduction to DBMS
1. Introduction to DBMS1. Introduction to DBMS
1. Introduction to DBMSkoolkampus
 
Alphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQLAlphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQLAlphorm
 
Database Management Systems (DBMS)
Database Management Systems (DBMS)Database Management Systems (DBMS)
Database Management Systems (DBMS)Dimara Hakim
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHPBradley Holt
 
Database management system presentation
Database management system presentationDatabase management system presentation
Database management system presentationsameerraaj
 

Andere mochten auch (13)

Extensible Data Modeling
Extensible Data ModelingExtensible Data Modeling
Extensible Data Modeling
 
Speed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisSpeed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with Redis
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQL
 
Introduction to Mysql
Introduction to MysqlIntroduction to Mysql
Introduction to Mysql
 
Database Management System Introduction
Database Management System IntroductionDatabase Management System Introduction
Database Management System Introduction
 
CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL Presentation
 
1. Introduction to DBMS
1. Introduction to DBMS1. Introduction to DBMS
1. Introduction to DBMS
 
Alphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQLAlphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQL
 
Database Management Systems (DBMS)
Database Management Systems (DBMS)Database Management Systems (DBMS)
Database Management Systems (DBMS)
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Database management system presentation
Database management system presentationDatabase management system presentation
Database management system presentation
 

Ähnlich wie MySQL & NoSQL from a PHP Perspective

New Persistence Features in Spring Roo 1.1
New Persistence Features in Spring Roo 1.1New Persistence Features in Spring Roo 1.1
New Persistence Features in Spring Roo 1.1Stefan Schmidt
 
flickr's architecture & php
flickr's architecture & php flickr's architecture & php
flickr's architecture & php coolpics
 
Nashville analytics summit aug9 no sql mike king dell v1.5
Nashville analytics summit aug9 no sql mike king dell v1.5Nashville analytics summit aug9 no sql mike king dell v1.5
Nashville analytics summit aug9 no sql mike king dell v1.5Mike King
 
Scaling with Riak at Showyou
Scaling with Riak at ShowyouScaling with Riak at Showyou
Scaling with Riak at ShowyouJohn Muellerleile
 
SQL or NoSQL, that is the question!
SQL or NoSQL, that is the question!SQL or NoSQL, that is the question!
SQL or NoSQL, that is the question!Andraz Tori
 
No sql and sql - open analytics summit
No sql and sql - open analytics summitNo sql and sql - open analytics summit
No sql and sql - open analytics summitOpen Analytics
 
Introduction to Graph databases and Neo4j (by Stefan Armbruster)
Introduction to Graph databases and Neo4j (by Stefan Armbruster)Introduction to Graph databases and Neo4j (by Stefan Armbruster)
Introduction to Graph databases and Neo4j (by Stefan Armbruster)barcelonajug
 
Microsoft Openness Mongo DB
Microsoft Openness Mongo DBMicrosoft Openness Mongo DB
Microsoft Openness Mongo DBHeriyadi Janwar
 
Big Data technology Landscape
Big Data technology LandscapeBig Data technology Landscape
Big Data technology LandscapeShivanandaVSeeri
 
Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyBlazing Cloud
 
Combine Spring Data Neo4j and Spring Boot to quickl
Combine Spring Data Neo4j and Spring Boot to quicklCombine Spring Data Neo4j and Spring Boot to quickl
Combine Spring Data Neo4j and Spring Boot to quicklNeo4j
 
Solr cloud the 'search first' nosql database extended deep dive
Solr cloud the 'search first' nosql database   extended deep diveSolr cloud the 'search first' nosql database   extended deep dive
Solr cloud the 'search first' nosql database extended deep divelucenerevolution
 
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...OpenBlend society
 
Fb talk arch_summit
Fb talk arch_summitFb talk arch_summit
Fb talk arch_summitdrewz lin
 
Data massage! databases scaled from one to one million nodes (ulf wendel)
Data massage! databases scaled from one to one million nodes (ulf wendel)Data massage! databases scaled from one to one million nodes (ulf wendel)
Data massage! databases scaled from one to one million nodes (ulf wendel)Zhang Bo
 
A review of the state of the art in Machine Learning on the Semantic Web
A review of the state of the art in Machine Learning on the Semantic WebA review of the state of the art in Machine Learning on the Semantic Web
A review of the state of the art in Machine Learning on the Semantic WebSimon Price
 

Ähnlich wie MySQL & NoSQL from a PHP Perspective (20)

NoSQL databases
NoSQL databasesNoSQL databases
NoSQL databases
 
New Persistence Features in Spring Roo 1.1
New Persistence Features in Spring Roo 1.1New Persistence Features in Spring Roo 1.1
New Persistence Features in Spring Roo 1.1
 
NoSQL or not NoSQL?
NoSQL or not NoSQL?NoSQL or not NoSQL?
NoSQL or not NoSQL?
 
flickr's architecture & php
flickr's architecture & php flickr's architecture & php
flickr's architecture & php
 
Nashville analytics summit aug9 no sql mike king dell v1.5
Nashville analytics summit aug9 no sql mike king dell v1.5Nashville analytics summit aug9 no sql mike king dell v1.5
Nashville analytics summit aug9 no sql mike king dell v1.5
 
Scaling with Riak at Showyou
Scaling with Riak at ShowyouScaling with Riak at Showyou
Scaling with Riak at Showyou
 
SQL or NoSQL, that is the question!
SQL or NoSQL, that is the question!SQL or NoSQL, that is the question!
SQL or NoSQL, that is the question!
 
No sql and sql - open analytics summit
No sql and sql - open analytics summitNo sql and sql - open analytics summit
No sql and sql - open analytics summit
 
Introduction to Graph databases and Neo4j (by Stefan Armbruster)
Introduction to Graph databases and Neo4j (by Stefan Armbruster)Introduction to Graph databases and Neo4j (by Stefan Armbruster)
Introduction to Graph databases and Neo4j (by Stefan Armbruster)
 
Microsoft Openness Mongo DB
Microsoft Openness Mongo DBMicrosoft Openness Mongo DB
Microsoft Openness Mongo DB
 
Big Data technology Landscape
Big Data technology LandscapeBig Data technology Landscape
Big Data technology Landscape
 
NOsql Presentation.pdf
NOsql Presentation.pdfNOsql Presentation.pdf
NOsql Presentation.pdf
 
Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_many
 
Combine Spring Data Neo4j and Spring Boot to quickl
Combine Spring Data Neo4j and Spring Boot to quicklCombine Spring Data Neo4j and Spring Boot to quickl
Combine Spring Data Neo4j and Spring Boot to quickl
 
Solr cloud the 'search first' nosql database extended deep dive
Solr cloud the 'search first' nosql database   extended deep diveSolr cloud the 'search first' nosql database   extended deep dive
Solr cloud the 'search first' nosql database extended deep dive
 
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
 
Fb talk arch_summit
Fb talk arch_summitFb talk arch_summit
Fb talk arch_summit
 
Data massage! databases scaled from one to one million nodes (ulf wendel)
Data massage! databases scaled from one to one million nodes (ulf wendel)Data massage! databases scaled from one to one million nodes (ulf wendel)
Data massage! databases scaled from one to one million nodes (ulf wendel)
 
A review of the state of the art in Machine Learning on the Semantic Web
A review of the state of the art in Machine Learning on the Semantic WebA review of the state of the art in Machine Learning on the Semantic Web
A review of the state of the art in Machine Learning on the Semantic Web
 
NoSQL databases
NoSQL databasesNoSQL databases
NoSQL databases
 

Kürzlich hochgeladen

Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 

Kürzlich hochgeladen (20)

Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 

MySQL & NoSQL from a PHP Perspective

  • 1. MySQL & NoSQL from a PHP perspective Tim Juravich @timjuravich October 4th, 2011 - Tim Juravich
  • 2. MySQL & NoSQL from a PHP perspective 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 October 4th, 2011 - Tim Juravich
  • 3. MySQL & NoSQL from a PHP perspective What we’ll talk about today • A high level discussion on NoSQL databases from the PHP developer POV • We’ll focus on Data Models • What we won’t be able to talk about: - How each database scales, stores it’s data. - CAP Theorem (http://tinyurl.com/nosql-cap) • We’ll touch on tools for us PHP Developers October 4th, 2011 - Tim Juravich
  • 4. MySQL & NoSQL from a PHP perspective Data Models A data model defines how your application stores data and how it makes associations. If you force an incorrect data model into your application...you’re probably going to have a hard time. October 4th, 2011 - Tim Juravich
  • 5. MySQL & NoSQL from a PHP perspective Traditional relational Model (MySQL) addresses users id address city state zip user_id id first_name last_name 123 Main 1 Seattle WA 98101 1 Street 1 John Doe 120 Pike 2 Seattle WA 98101 1 Street 2 Jane Doe 321 2nd 3 Seattle WA 98101 2 Ave phone numbers id number primary user_id 1 555-867-5309 1 1 2 555-867-5309 0 1 3 555-867-5309 1 2 October 4th, 2011 - Tim Juravich
  • 6. MySQL & NoSQL from a PHP perspective What’s wrong with this? • 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
  • 7. MySQL & NoSQL from a PHP perspective NoSQL databases are born • History - Some NoSQL databases have been around forever - In 2004 & 2005 they explode • NoSQL really means “Not Only SQL” October 4th, 2011 - Tim Juravich
  • 8. MySQL & NoSQL from a PHP perspective NoSQL • 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
  • 9. MySQL & NoSQL from a PHP perspective There are no silver bullets! October 4th, 2011 - Tim Juravich
  • 10. MySQL & NoSQL from a PHP perspective Size vs. Complexity Key/value Stores Column Stores Document Database Scale To Size Graph Database Typical RDMBS RDMBS Performance Line Scale To Complexity October 4th, 2011 - Tim Juravich
  • 11. MySQL & NoSQL from a PHP perspective Key Value Stores • Definition - Access to a value based on a unique key - Think of this in terms of a hash-table, or in PHP an associative array. user_1 user_2 “John Doe” { name: “John Doe”, email: john@example.com”, phone: “8675309” } October 4th, 2011 - Tim Juravich
  • 12. MySQL & NoSQL from a PHP perspective Redis • Strengths - Incredibly Fast - Pub/Sub support redis> set im.a.key "im.a.value" OK - Simple CLI redis> get im.a.key "im.a.value" • 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
  • 13. MySQL & NoSQL from a PHP perspective Redis & PHP • There are a variety of Redis & PHP toolkits (http://tinyurl.com/redis-php) • My favorite is Predis (https://github.com/nrk/predis) <?php $redis = new PredisClient(); $redis->set('foo', 'bar'); $value = $redis->get('foo'); • Twitter clone to play with: (http://redis.io/topics/twitter-clone) October 4th, 2011 - Tim Juravich
  • 14. MySQL & NoSQL from a PHP perspective 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 October 4th, 2011 - Tim Juravich
  • 15. MySQL & NoSQL from a PHP perspective 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 October 4th, 2011 - Tim Juravich
  • 16. MySQL & NoSQL from a PHP perspective Cassandra • Strengths - Can handle some serious data - Writes are much faster than reads - Hadoop integration • Weaknesses - Complex for it’s offering and bloated • Use it for - Apps with a lot of writing. Serious applications. October 4th, 2011 - Tim Juravich
  • 17. MySQL & NoSQL from a PHP perspective Cassandra & PHP • Thrift • There are a few PHP libraries (http://tinyurl.com/cassandra-php) • My favorite is phpcassa (https://github.com/thobbs/phpcassa) October 4th, 2011 - Tim Juravich
  • 18. MySQL & NoSQL from a PHP perspective Cassandra & PHP (phpcassa) <?php // Connect to Keyspace $pool = new ConnectionPool('example-db'); // Create ColumnFamily $users = new ColumnFamily($pool, 'users'); // Create User $users->insert('2’, array('name' => 'Jane Doe', 'email' => 'jane@example.com')); // Get User $users->get('2'); October 4th, 2011 - Tim Juravich
  • 19. MySQL & NoSQL from a PHP perspective 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 October 4th, 2011 - Tim Juravich
  • 20. MySQL & NoSQL from a PHP perspective Document Databases { id: 'johndoe', { id: 'janedoe', name: 'John Doe', name: 'Jane Doe', email : ‘john@example.com’, email : ‘jane@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’ } ] } October 4th, 2011 - Tim Juravich
  • 21. MySQL & NoSQL from a PHP perspective MongoDB • Strengths - Familiar Query Language $post->where('id', $this->getID()); - 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. October 4th, 2011 - Tim Juravich
  • 22. MySQL & NoSQL from a PHP perspective MongoDB & PHP • A TON of libraries (http://tinyurl.com/mongo-php) - Doctrine - Cake - Code Ignitor - Symfony - Zend - etc. • My favorite is ActiveMongo (https://github.com/crodas/ActiveMongo) October 4th, 2011 - Tim Juravich
  • 23. MySQL & NoSQL from a PHP perspective MongoDB & PHP (Active Mongo) <?php ActiveMongo::connect('example-db', 'localhost'); class User extends ActiveMongo { public $name; public $email; } $user = new User(); $user->name = 'John Doe'; $user->email = 'john@example.com'; // Insert $user->save(); // Update $user->email = 'john@example.org'; $user->save(); October 4th, 2011 - Tim Juravich
  • 24. MySQL & NoSQL from a PHP perspective 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 October 4th, 2011 - Tim Juravich
  • 25. MySQL & NoSQL from a PHP perspective CouchDB & PHP • Not as many as MongoDB (http://tinyurl.com/couch-php) - Doctrine - Variety of standalone libraries • My favorite is Sag (https://github.com/sbisbee/sag) October 4th, 2011 - Tim Juravich
  • 26. MySQL & NoSQL from a PHP perspective CouchDB & PHP (Sag) <?php class User { public $name; public $email; } $user = new User(); $user->name = 'John Doe'; $user->email = 'john@example.com'; $sag = new Sag('127.0.0.1', '5984'); $sag->setDatabase('example-db'); $sag->post($user); October 4th, 2011 - Tim Juravich
  • 27. MySQL & NoSQL from a PHP perspective 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. October 4th, 2011 - Tim Juravich
  • 28. MySQL & NoSQL from a PHP perspective Graph Databases October 4th, 2011 - Tim Juravich
  • 29. MySQL & NoSQL from a PHP perspective Neo4j • Strengths - Fully transactional - Flexible API • Weaknesses - A completely different way of thinking - Complex • Use it for - Social relations, road maps, network topologies October 4th, 2011 - Tim Juravich
  • 30. MySQL & NoSQL from a PHP perspective Neo4j & PHP • There are a few of options (http://tinyurl.com/neo4j-php) - REST API - Thrift • It’s pretty complex... October 4th, 2011 - Tim Juravich
  • 31. MySQL & NoSQL from a PHP perspective So which DB should you use? • Don’t rule out relational databases • Do your homework • Every project is different • NoSQL probably should be avoided in these areas - Transactions, orders, anything where money changes hands - Business critical data or line of business applications October 4th, 2011 - Tim Juravich
  • 32. Thanks! Feel free to reach out with any questions: tim.juravich@gmail.com @timjuravich October 4th, 2011 - Tim Juravich