40
What Does NoSQL Mean for You? Chris Lea (mt) Media Temple FOWA Dublin 2010

Chris Lea - What does NoSQL Mean for You

  • View
    11.235

  • Download
    3

Embed Size (px)

DESCRIPTION

From FOWA Dublin 2010 Video: http://www.ustream.tv/myvideos/1/6906682

Citation preview

Page 1: Chris Lea - What does NoSQL Mean for You

What Does NoSQL Mean for You?

Chris Lea(mt) Media Temple

FOWA Dublin 2010

Page 2: Chris Lea - What does NoSQL Mean for You

For Starters: What does it mean at all?

Page 3: Chris Lea - What does NoSQL Mean for You

For Starters: What does it mean at all?

“NoSQL is a blanket term used to describestructured storage that doesn’t rely on SQL

to be accessed in a useful way”.

-- Chris Lea

Page 4: Chris Lea - What does NoSQL Mean for You

For Starters: What does it mean at all?

“NoSQL” DOES NOT mean “SQL is Bad”

Page 5: Chris Lea - What does NoSQL Mean for You

MySQL does what I need, why should I care?

Page 6: Chris Lea - What does NoSQL Mean for You

MySQL does what I need, why should I care?

“If I’d asked my customers what they wanted, they’d have said a faster horse.” -- Henry Ford

Page 7: Chris Lea - What does NoSQL Mean for You

MySQL does what I need, why should I care?

RDBMS NoSQL

Designed for generic workloads

Designed to solve specific problems

Large (and growing) feature sets

Trades features for performance

Page 8: Chris Lea - What does NoSQL Mean for You

(the NoSQL umbrella)

Page 9: Chris Lea - What does NoSQL Mean for You

(the NoSQL umbrella)

Key / Value Caches

•Redis•Memcached

Page 10: Chris Lea - What does NoSQL Mean for You

(the NoSQL umbrella)

Key / Value Caches

•Redis•Memcached

Key / Value Stores

•Tokyo cabinet•Memcachedb•Project Voldemort•Cassandra

Page 11: Chris Lea - What does NoSQL Mean for You

(the NoSQL umbrella)

Key / Value Caches

•Redis•Memcached

Key / Value Stores

•Tokyo cabinet•Memcachedb•Project Voldemort•Cassandra

Tabular

•HBase•Hypertable

Page 12: Chris Lea - What does NoSQL Mean for You

(the NoSQL umbrella)

Key / Value Caches

•Redis•Memcached

Key / Value Stores

•Tokyo cabinet•Memcachedb•Project Voldemort•Cassandra

Tabular

•HBase•Hypertable

Document

•CouchDB•MongoDB• Jackrabbit

Page 13: Chris Lea - What does NoSQL Mean for You

(the NoSQL umbrella)

Key / Value Caches

•Redis•Memcached

Key / Value Stores

•Tokyo cabinet•Memcachedb•Project Voldemort•Cassandra

Tabular

•HBase•Hypertable

Document

•CouchDB•MongoDB• Jackrabbit

Page 14: Chris Lea - What does NoSQL Mean for You

Should I be Thinking aboutNoSQL?

Page 15: Chris Lea - What does NoSQL Mean for You

Should I be Thinking aboutNoSQL?

Do you needtransactions?

Think aboutNoSQL.

Probably needRDBMS.

No

Yes Can you sanely dowhat you need in the app? No

Yes

Page 16: Chris Lea - What does NoSQL Mean for You

NoSQL Systems TypicallyDon’t do Transactions

or Joins

Page 17: Chris Lea - What does NoSQL Mean for You

NoSQL Systems TypicallyDon’t do Transactions

or Joins

• If you really need transactions, stick with RDBMS•Not having joins turns out to be not such a big deal

Page 18: Chris Lea - What does NoSQL Mean for You

NoSQL Systems TypicallyDon’t do Transactions

or Joins

MongoDB is an excellent use case example

Page 19: Chris Lea - What does NoSQL Mean for You

Why MongoDB?• Comfortable if you are coming from MySQL

• Written in C++ means all machine code

• no Erlang / Java / virtual machines

• Tools like mongo (shell), mongodump, mongostat,

mongoimport

• Native drives in languages you care about

• no Thrift / REST / code generation steps

Page 20: Chris Lea - What does NoSQL Mean for You

Why MongoDB?

• No complex transactions

• If you don’t use them, this is a non-issue

• No joins

• This turns out to not be a big deal generally, because

we’re going to rethink our data modeling

Page 21: Chris Lea - What does NoSQL Mean for You

Why MongoDB?

• No complex transactions

• If you don’t use them, this is a non-issue

• No joins

• This turns out to not be a big deal generally, because

we’re going to rethink our data modeling

Transactions and joins are a huge computationaloverhead, even if you don’t use them!

Page 22: Chris Lea - What does NoSQL Mean for You

Why MongoDB?

• No complex transactions

• If you don’t use them, this is a non-issue

• No joins

• This turns out to not be a big deal generally, because

we’re going to rethink our data modeling

Transactions and joins are a huge computationaloverhead, even if you don’t use them!

Page 23: Chris Lea - What does NoSQL Mean for You

Thinking About Your Data (RDBMS)

•Look at data, determine logical groupings• (hope structure never changes)

•Make tables based on groups, link with ID fields•Break up data on insert, put into appropriate tables•Use joins on select to re-assemble data•Create indexes as needed for fast queries

Page 24: Chris Lea - What does NoSQL Mean for You

Thinking About Your Data (RDBMS)

user_t

user_id

user_name

post_t

post_id

user_id

post_title

post_body

comment_t

comment_id

post_id

comment_body

Page 25: Chris Lea - What does NoSQL Mean for You

Thinking About Your Data (RDBMS)

This leads to queries such as:

SELECT post_title,post_body,post_id FROM post_t,user_t WHERE user_t.user_name = “Lorraine” AND post_t.user_id = user_t.user_id LIMIT 1;

SELECT comment_body FROM comment_t WHERE comment_t.post_id = $post_id;

Page 26: Chris Lea - What does NoSQL Mean for You

Thinking About Your Data (MongoDB)

•Figure out how you will eventually use the data•Store it that way•Create indexes as needed for fast queries

Page 27: Chris Lea - What does NoSQL Mean for You

Thinking About Your Data (MongoDB)

from pymongo import Connectionconnection = Connection()db = connection['blog']

posts = db['posts']

post = {"author": "Lorraine", "title": "Who on Earth lets Chris Lea Talk on Stage?", "post": "Seriously. That's just not cool.", "comments": ["Is he really that bad?", "Yes, he really is."], "date": datetime.datetime.utcnow()}

posts.insert(post)

Page 28: Chris Lea - What does NoSQL Mean for You

Thinking About Your Data (MongoDB)

from pymongo import Connectionconnection = Connection()db = connection['blog']

posts = db['posts']

post = posts.find_one({“author”: “Lorraine”})

Page 29: Chris Lea - What does NoSQL Mean for You

Say Goodbye to Schemas

from pymongo import Connectionconnection = Connection()db = connection['blog']

posts = db['posts']

post = {"author": "Lorraine", "title": "Who on Earth lets Chris Lea Talk on Stage?", "post": "Seriously. That's just not cool.", "comments": ["Is he really that bad?", "Yes, he really is."], "date": datetime.datetime.utcnow()}

posts.insert(post)

Page 30: Chris Lea - What does NoSQL Mean for You

Say Goodbye to Schemas

from pymongo import Connectionconnection = Connection()db = connection['blog']

posts = db['posts']

post = {"author": "Lorraine", "title": "Who on Earth lets Chris Lea Talk on Stage?", "post": "Seriously. That's just not cool.", "comments": ["Is he really that bad?", "Yes, he really is."], "tags": ["fowa", "nosql", "nerds"], "date": datetime.datetime.utcnow()}

posts.insert(post)

Page 31: Chris Lea - What does NoSQL Mean for You

Say Goodbye to Schemas

from pymongo import Connectionconnection = Connection()db = connection['blog']

posts = db['posts']

post = {"author": "Lorraine", "title": "Who on Earth lets Chris Lea Talk on Stage?", "post": "Seriously. That's just not cool.", "comments": ["Is he really that bad?", "Yes, he really is."], "tags": ["fowa", "nosql", "nerds"], "date": datetime.datetime.utcnow()}

posts.insert(post)

If you want new fields... just startusing them!

Page 32: Chris Lea - What does NoSQL Mean for You

Enjoy a Wealth of Query Options

from pymongo import Connectionconnection = Connection()db = connection['blog']

posts = db['posts']

posts.find_one({“author”: “Lorraine”})

Page 33: Chris Lea - What does NoSQL Mean for You

Enjoy a Wealth of Query Options

from pymongo import Connectionconnection = Connection()db = connection['blog']

posts = db['posts']

posts.find({“author”: “Lorraine”}).limit(5)

Page 34: Chris Lea - What does NoSQL Mean for You

Enjoy a Wealth of Query Options

from pymongo import Connectionconnection = Connection()db = connection['blog']

posts = db['posts']

posts.find({“author”: /^Lor/})

Page 35: Chris Lea - What does NoSQL Mean for You

Enjoy a Wealth of Query Options

from pymongo import Connectionconnection = Connection()db = connection['blog']

posts = db['posts']

posts.find({“author”: {$not: “Lorraine”} })

Page 36: Chris Lea - What does NoSQL Mean for You

Enjoy a Massive Performance Jump

•Mileage will vary, but 10x is not uncommon•For reads and writes

•Writes happen at near disk native speed•Logging to MongoDB is perfectly acceptable

•Reads for active data near Memcached speeds

Page 37: Chris Lea - What does NoSQL Mean for You

Enjoy a Massive Performance Jump

Ability to write bad queries isenormously reduced!

Page 38: Chris Lea - What does NoSQL Mean for You

Ability to write bad queries isenormously reduced!

• No joins means need for complex indexes reduced• Chances of index / query mismatches vastly lower• Disk I/O much less complex, and therefore much faster

Page 39: Chris Lea - What does NoSQL Mean for You

Caveats for MongoDB

•Really should use 64bit machines for production•32bit has 2G limit per collection (table)

•Happiest with lots of RAM relative to active data•Under heavy development

•Features / drivers / docs changing rapidly

Page 40: Chris Lea - What does NoSQL Mean for You

Questions?