Laraval London Meetup March 2016
Alternatives to SQL?
a Laravel perpective
Laraval London Meetup March 2016
Peter Coles
Chief Technology Officer - YOYODATA
Founder - Kuroi Web Development
Laraval London Meetup March 2016
Alternatives
Key-Value Stores Document Stores
Search EnginesGraph DatabasesEvent Stores
Wide Column /
Extensible Stores
Laraval London Meetup March 2016
Tonight’s Focus
Laraval London Meetup March 2016
Sportsperson Encyclopaedia
A Practical Example
Laraval London Meetup March 2016
Sportsperson Encyclopedia SQL DB Structure
Athletics
Football
People
Cricket
migration
model
repository / service class
view
Laraval London Meetup March 2016
Sportsperson Encyclopedia Doc Store DB Structure
service class
view
model / repository
Laraval London Meetup March 2016
Using MongoDB
Laraval London Meetup March 2016
high availability
reliability
scalability
flexibility
affordability
What are we looking for?
“users can get at their stuff anytime”
“I don’t have to keep fixing it”
“it can grow with the business”
“working with it isn’t too expensive”
“easy to make structural changes”
Laraval London Meetup March 2016
Database Scaling
Horizontal ScalingVertical Scaling
Laraval London Meetup March 2016
Replicas
NoSQL DB Architecture
Nodes
Shards
Laraval London Meetup March 2016
Document store
Proprietary API using JSON
Client for PHP (+ almost 30 others)
Switchable storage engines
Server-side scripts in Javascript
MongoDB
Laraval London Meetup March 2016
Search Engine
Often used as a secondary store
Java API + RESTful API HTTP/JSON
Client for PHP (+ almost 15 others)
Indexes content by default
Server-side scripts possible (Java?)
Elastic
Laraval London Meetup March 2016
Key-Value Store / Document store
Proprietary RESTful API
Client for PHP (+ almost 10 others)
Hosted so no server-side scripting
Proprietary hardware
Really, really fast at scale
DynamoDB
Laraval London Meetup March 2016
Hosting
Local
Installation
with some
limitations
Database as
a Service
ElasticCloud
AWS ElasticSearch
AWS DynamoDB
mLab
MongoHQ
Self-managed
Laraval London Meetup March 2016
Install PHP driver
Add jenssegers/mongodb aka Moloquent to your project
Configure mongodb connection
Use Moloquent in place of Eloquent as your base model
Use as you would Eloquent (with extras)
Using MongoDB with Laravel
Laraval London Meetup March 2016
Using MongoDB with Laravel
Laraval London Meetup March 2016
Using MongoDB with Laravel
Laraval London Meetup March 2016
Using MongoDB with Laravel
Laraval London Meetup March 2016
Using Elastic with Laravel
Add Elasticquent to your project
Configure connection (i.e. give it API endpoints)
Add the Elasticquent trait to your models
Populate Elastic from your primary store
Search
Laraval London Meetup March 2016
Using Elastic with Laravel
Laraval London Meetup March 2016
Using Elastic with Laravel
Laraval London Meetup March 2016
Using Elastic with Laravel
• totalHits
• shards
• maxScore
• timedOut
• took
Laraval London Meetup March 2016
Using DynamoDB with Laravel
Add aws/aws-sdk-php-laravel or baopham/laravel-dynamodb to your project
Set up .env entries for AWS “key”, “secret” and “region”
Wrap API methods in a base model or repository
Laraval London Meetup March 2016
Using DynamoDB with Laravel
PutItem
UpdateItem
GetItem
DeleteItem
BatchGetItem
BatchWriteItem
Query
Scan
Laraval London Meetup March 2016
Using DynamoDB with Laravel
Laraval London Meetup March 2016
Gotchas
Pagination
Pagination
Becoming too “Laravelised”
Unexpected exceptions
Consistency
Limits on record size
Limits on records returned
Limits on resultset size
Laraval London Meetup March 2016
Do consider alternatives to SQL
Be mindful as to who will support your infrastructure
Perform deep analysis on how your data is / will be used and index
Prototype important functionality
Monitor performance
Experiment and have fun
Conclusion

Alternatives to SQL - a Laravel Perspective

  • 1.
    Laraval London MeetupMarch 2016 Alternatives to SQL? a Laravel perpective
  • 2.
    Laraval London MeetupMarch 2016 Peter Coles Chief Technology Officer - YOYODATA Founder - Kuroi Web Development
  • 3.
    Laraval London MeetupMarch 2016 Alternatives Key-Value Stores Document Stores Search EnginesGraph DatabasesEvent Stores Wide Column / Extensible Stores
  • 4.
    Laraval London MeetupMarch 2016 Tonight’s Focus
  • 5.
    Laraval London MeetupMarch 2016 Sportsperson Encyclopaedia A Practical Example
  • 6.
    Laraval London MeetupMarch 2016 Sportsperson Encyclopedia SQL DB Structure Athletics Football People Cricket migration model repository / service class view
  • 7.
    Laraval London MeetupMarch 2016 Sportsperson Encyclopedia Doc Store DB Structure service class view model / repository
  • 8.
    Laraval London MeetupMarch 2016 Using MongoDB
  • 9.
    Laraval London MeetupMarch 2016 high availability reliability scalability flexibility affordability What are we looking for? “users can get at their stuff anytime” “I don’t have to keep fixing it” “it can grow with the business” “working with it isn’t too expensive” “easy to make structural changes”
  • 10.
    Laraval London MeetupMarch 2016 Database Scaling Horizontal ScalingVertical Scaling
  • 11.
    Laraval London MeetupMarch 2016 Replicas NoSQL DB Architecture Nodes Shards
  • 12.
    Laraval London MeetupMarch 2016 Document store Proprietary API using JSON Client for PHP (+ almost 30 others) Switchable storage engines Server-side scripts in Javascript MongoDB
  • 13.
    Laraval London MeetupMarch 2016 Search Engine Often used as a secondary store Java API + RESTful API HTTP/JSON Client for PHP (+ almost 15 others) Indexes content by default Server-side scripts possible (Java?) Elastic
  • 14.
    Laraval London MeetupMarch 2016 Key-Value Store / Document store Proprietary RESTful API Client for PHP (+ almost 10 others) Hosted so no server-side scripting Proprietary hardware Really, really fast at scale DynamoDB
  • 15.
    Laraval London MeetupMarch 2016 Hosting Local Installation with some limitations Database as a Service ElasticCloud AWS ElasticSearch AWS DynamoDB mLab MongoHQ Self-managed
  • 16.
    Laraval London MeetupMarch 2016 Install PHP driver Add jenssegers/mongodb aka Moloquent to your project Configure mongodb connection Use Moloquent in place of Eloquent as your base model Use as you would Eloquent (with extras) Using MongoDB with Laravel
  • 17.
    Laraval London MeetupMarch 2016 Using MongoDB with Laravel
  • 18.
    Laraval London MeetupMarch 2016 Using MongoDB with Laravel
  • 19.
    Laraval London MeetupMarch 2016 Using MongoDB with Laravel
  • 20.
    Laraval London MeetupMarch 2016 Using Elastic with Laravel Add Elasticquent to your project Configure connection (i.e. give it API endpoints) Add the Elasticquent trait to your models Populate Elastic from your primary store Search
  • 21.
    Laraval London MeetupMarch 2016 Using Elastic with Laravel
  • 22.
    Laraval London MeetupMarch 2016 Using Elastic with Laravel
  • 23.
    Laraval London MeetupMarch 2016 Using Elastic with Laravel • totalHits • shards • maxScore • timedOut • took
  • 24.
    Laraval London MeetupMarch 2016 Using DynamoDB with Laravel Add aws/aws-sdk-php-laravel or baopham/laravel-dynamodb to your project Set up .env entries for AWS “key”, “secret” and “region” Wrap API methods in a base model or repository
  • 25.
    Laraval London MeetupMarch 2016 Using DynamoDB with Laravel PutItem UpdateItem GetItem DeleteItem BatchGetItem BatchWriteItem Query Scan
  • 26.
    Laraval London MeetupMarch 2016 Using DynamoDB with Laravel
  • 27.
    Laraval London MeetupMarch 2016 Gotchas Pagination Pagination Becoming too “Laravelised” Unexpected exceptions Consistency Limits on record size Limits on records returned Limits on resultset size
  • 28.
    Laraval London MeetupMarch 2016 Do consider alternatives to SQL Be mindful as to who will support your infrastructure Perform deep analysis on how your data is / will be used and index Prototype important functionality Monitor performance Experiment and have fun Conclusion