38
NON-RELATIONAL DATABASES Saturday, October 31, 2009

Non-Relational Databases & Key/Value Stores

Embed Size (px)

DESCRIPTION

A brief overview of currently popular & available key/value, column oriented & document oriented databases, along with implementation suggestions for the CakePHP web application framework.

Citation preview

Page 1: Non-Relational Databases & Key/Value Stores

NON-RELATIONAL DATABASES

Saturday, October 31, 2009

Page 2: Non-Relational Databases & Key/Value Stores

@JPERRAS - JOEL PERRASCanadian Geek

Blog: http://nerderati.com

GitHub: http://github.com/jperras

CakePHP Core since Early 2009, PHP dev. since 2001

McGill University, Montréal, Canada - Physics, Mathematics & Computer Science

Employer: Plank Design (http://plankdesign.com) (Twitter: @plankdesign)

Saturday, October 31, 2009

Page 3: Non-Relational Databases & Key/Value Stores

RELATIONAL DATABASES

Many different vendors: MySQL, PostgreSQL, SQLite, Oracle, ...

Same basic implementation:

B(+)-Trees for pages

B(+)-Trees or hash tables for secondary indexes

Possibly R-Trees for spatial indexes

Saturday, October 31, 2009

Page 4: Non-Relational Databases & Key/Value Stores

WHAT THEY’RE GOOD AT

Saturday, October 31, 2009

Page 5: Non-Relational Databases & Key/Value Stores

Schemas (relational models)

Familiar BCNF structure

Strong consistency

Transactions

Very “mature” & well tested (mostly)

Easy adoption/integration

Saturday, October 31, 2009

Page 6: Non-Relational Databases & Key/Value Stores

FriendFeed

Wikipedia

Google AdWords

Facebook

RDBMS’ES ARE NOT GOING ANYWHERE

Saturday, October 31, 2009

Page 7: Non-Relational Databases & Key/Value Stores

Most small to medium size applications willnever need to go beyond a single database server.

Saturday, October 31, 2009

Page 8: Non-Relational Databases & Key/Value Stores

Always try and follow the Golden Web ApplicationDevelopment Rule:

Saturday, October 31, 2009

Page 9: Non-Relational Databases & Key/Value Stores

DON’T TRY TO SOLVE A PROBLEM YOU DON’T

HAVE

Saturday, October 31, 2009

Page 10: Non-Relational Databases & Key/Value Stores

The web has created new problem domains in data storage and querying.

Saturday, October 31, 2009

Page 11: Non-Relational Databases & Key/Value Stores

Often use variable schemas

Optional fields: contact lists, addresses, favourite movies/books, etc.

NULL-itis: null values should not be permitted in BCNF, but are everywhere in web applications.

MODERN WEB APPS

Saturday, October 31, 2009

Page 12: Non-Relational Databases & Key/Value Stores

‘Social’ apps => high write/read ratios

Complex Many-to-Many relationships

Joins become a problem in federated architectures

Eventual consistency is usually acceptable

Downtime unacceptable

MODERN WEB APPS

Saturday, October 31, 2009

Page 13: Non-Relational Databases & Key/Value Stores

OTHER CONCERNS

Saturday, October 31, 2009

Page 14: Non-Relational Databases & Key/Value Stores

RULES OF APP AGINGhttp://push.cx/2009/rules-of-database-app-aging

1. All fields become optional2. All relationships become many-to-many3. Chatter (comments explaining hacks) grows with time.

Saturday, October 31, 2009

Page 15: Non-Relational Databases & Key/Value Stores

SOME GOOD PROBLEMS TO HAVE

Even if they are “Hard” ones to solve.

Saturday, October 31, 2009

Page 16: Non-Relational Databases & Key/Value Stores

Load Balancing(you can only live with one machine for so long)

Saturday, October 31, 2009

Page 17: Non-Relational Databases & Key/Value Stores

High Availability(because disks fail, and replication fails)

Saturday, October 31, 2009

Page 18: Non-Relational Databases & Key/Value Stores

What’s a web application developer to do?

Saturday, October 31, 2009

Page 19: Non-Relational Databases & Key/Value Stores

Alternative Data Storage Solutions

Saturday, October 31, 2009

Page 20: Non-Relational Databases & Key/Value Stores

Not a silver bullet.

These can solve some problems, but cause others and have their own limitations.

It’s up to you to weigh the cost/benefit of your chosen solution.

Saturday, October 31, 2009

Page 21: Non-Relational Databases & Key/Value Stores

THE LANDSCAPE

Key/Value Stores/Distributed Hash Tables (DHT)

Document-oriented databases

Column-oriented databases

Saturday, October 31, 2009

Page 22: Non-Relational Databases & Key/Value Stores

KEY/VALUE STORES

Voldemort

Scalaris

Tokyo Cabinet

Redis

MemcacheDB

Saturday, October 31, 2009

Page 23: Non-Relational Databases & Key/Value Stores

DOCUMENT ORIENTED DATA STORES

CouchDB <- (my favourite!)

MongoDB

SimpleDB (Amazon)

Saturday, October 31, 2009

Page 24: Non-Relational Databases & Key/Value Stores

COLUMN-ORIENTED STORES

BigTable (Google)

HBase (Hadoop Database)

Hypertable (BigTable Open Source clone)

Cassandra (Facebook)

Saturday, October 31, 2009

Page 25: Non-Relational Databases & Key/Value Stores

How do we use these technologiesalongside CakePHP ?

Saturday, October 31, 2009

Page 26: Non-Relational Databases & Key/Value Stores

This year’s magical word:

DataSources

Saturday, October 31, 2009

Page 27: Non-Relational Databases & Key/Value Stores

CASE STUDY - COUCHDB

http://github.com/jperras/divan(I will make zip/tar available when more stable - stay tuned)

Saturday, October 31, 2009

Page 28: Non-Relational Databases & Key/Value Stores

CASE STUDY - TOKYO CABINET/TYRANT

http://github.com/jperras/tyrannical(I will make zip/tar available when more stable - stay tuned)

Saturday, October 31, 2009

Page 29: Non-Relational Databases & Key/Value Stores

Non-relational stores are not relational.

Saturday, October 31, 2009

Page 30: Non-Relational Databases & Key/Value Stores

So don’t try to force the interface tobe relational.

Saturday, October 31, 2009

Page 31: Non-Relational Databases & Key/Value Stores

DESIGNING A NON-RELATIONAL DATASOURCE

Favour simplicity over transparency

Don’t try to implement everything that the MySQL driver implements

Use the strengths of the alternative store

Saturday, October 31, 2009

Page 32: Non-Relational Databases & Key/Value Stores

Example Use Cases

Saturday, October 31, 2009

Page 33: Non-Relational Databases & Key/Value Stores

KEY/VALUE STORES

Most have atomic increment/decrement operations

Great for API rate limiters (e.g. 300 API reqs/hour/account)

Counts & sums of normalized data

Most popular items, votes, ratings, some statistics

And more.

Saturday, October 31, 2009

Page 34: Non-Relational Databases & Key/Value Stores

DOCUMENT STORES

Filesystem objects (pdfs, images, excel sheets etc.) - stored as document attachments (size limited).

Allows you to reduce reliance on shared filesystems (NFS)

Address book

Volatile schema situations

CouchDB has a very interesting feature set

Saturday, October 31, 2009

Page 35: Non-Relational Databases & Key/Value Stores

There are many, many use cases.

Saturday, October 31, 2009

Page 36: Non-Relational Databases & Key/Value Stores

Thanks to the DataSource adapter implementation in CakePHP, creating a model-based interface is simple.

Saturday, October 31, 2009

Page 37: Non-Relational Databases & Key/Value Stores

Thank you!

@jperrashttp://nerderati.com

http://github.com/jperrasSaturday, October 31, 2009

Page 38: Non-Relational Databases & Key/Value Stores

CODE

Divan - CouchDB datasource

Yantra - State Machine component for application control flow

CakPHP TextMate Bundle

CakeMate - TextMate/Vim Plugin

Tyrannical - Tokyo Tyrant datasource

Originally by Martin Samson ([email protected])

Working to improve code - commits coming soon.

Currently working on a framework-agnostic, distributed, plugin/library server.

Saturday, October 31, 2009