29
Document Databases and Key-Value Stores a.k.a “pump it and dump it” Thursday, April 25, 13

Nosql kl-2013-04-25

Embed Size (px)

Citation preview

Page 1: Nosql kl-2013-04-25

Document Databases and Key-Value Stores

a.k.a “pump it and dump it”

Thursday, April 25, 13

Page 2: Nosql kl-2013-04-25

~/$ whoami

Thursday, April 25, 13

Page 3: Nosql kl-2013-04-25

@parasquid (also in fb/github)

works (here) at Mindvalley

helps organize KLMUG with Mark

did my rounds (from servers to frontend and back)

settled in as an app developer

Thursday, April 25, 13

Page 4: Nosql kl-2013-04-25

A MagicalHistory Tour

Thursday, April 25, 13

Page 5: Nosql kl-2013-04-25

Thursday, April 25, 13

Page 6: Nosql kl-2013-04-25

two years ago

joffrey was the first mongo-based prototype Mindvalley in Mindvalley

oathkeeper was the second

got used in production

still in production (unfortunately)

Thursday, April 25, 13

Page 7: Nosql kl-2013-04-25

Quick Review on Advantages of NoSQL over

Relational Databases

Thursday, April 25, 13

Page 8: Nosql kl-2013-04-25

Relational

Impedance Mismatch

An order, which looks like a single aggregate structure in the UI, is split into many rows from many tables

Thursday, April 25, 13

Page 9: Nosql kl-2013-04-25

NoSQLModel alignment

The storage data model closely resembles how the aggregate is represented in the domain (especially in document databases)

Thursday, April 25, 13

Page 10: Nosql kl-2013-04-25

RelationalProgrammer Productivity

Before you can modify your data model, you first have to think of how to tear it apart and make a migration

Thursday, April 25, 13

Page 11: Nosql kl-2013-04-25

NoSQL

Programmer Productivity

Most of the adjustments to the db are transparent; non-existent keys just return nil

Thursday, April 25, 13

Page 12: Nosql kl-2013-04-25

Quick Recap on the difference between Relational and NoSQL

(k-v and doc)

Thursday, April 25, 13

Page 13: Nosql kl-2013-04-25

Relational: blows up a model into small, constituent data

NoSQL (k-v and doc): stores and retrieves aggregates

Thursday, April 25, 13

Page 14: Nosql kl-2013-04-25

VS

Thursday, April 25, 13

Page 15: Nosql kl-2013-04-25

Key-Value Stores and Document Databases

Thursday, April 25, 13

Page 16: Nosql kl-2013-04-25

they actually are not that much different conceptually

mostly: you store and access a key-value store via a key (but not always)

mostly: you store and access a document database via a query (but not always)

Thursday, April 25, 13

Page 17: Nosql kl-2013-04-25

Thursday, April 25, 13

Page 18: Nosql kl-2013-04-25

Thursday, April 25, 13

Page 19: Nosql kl-2013-04-25

key-value store

aggregate is opaque to the database

db doesn’t care about the structure

document db

database knows the structure

db knows this field is a string/date/integer/etc

Difference

Thursday, April 25, 13

Page 20: Nosql kl-2013-04-25

Differencekey-value store

we can store whatever we like in the db

same field names may hold different types of objects

document db

defines allowable structures and types

structure supports flexibility

Thursday, April 25, 13

Page 21: Nosql kl-2013-04-25

I’ve never useda column db before sono comments on that :)

Thursday, April 25, 13

Page 22: Nosql kl-2013-04-25

But first, a word about “Schema-less”

Thursday, April 25, 13

Page 23: Nosql kl-2013-04-25

I actually prefer the term“schema-free”

once you start querying data, your data starts to have an implicit schema

“schema-free” is great for non-uniform data but you need some structure if you want to start querying for data

Thursday, April 25, 13

Page 24: Nosql kl-2013-04-25

NoSQL shifts the schema into the application code that accesses it

this can be a good thing or a bad thing

Thursday, April 25, 13

Page 25: Nosql kl-2013-04-25

Sample Use-cases

Thursday, April 25, 13

Page 26: Nosql kl-2013-04-25

Key-Value Storeswhen to use:

session data

user preferences

shopping cart data

when NOT to use:

relationships among data

multi-operation transactions

query by data

Thursday, April 25, 13

Page 27: Nosql kl-2013-04-25

Document Databaseswhen to use:

event logging

content management systems / blogging platforms

web analytics

e-commerce

when NOT to use:

complex transactions spanning different operations

queries against varying aggregate structure

Thursday, April 25, 13

Page 28: Nosql kl-2013-04-25

VS

Thursday, April 25, 13

Page 29: Nosql kl-2013-04-25

Conclusion

use the right tool for the right job

look at the tradeoffs and decide accordingly

in the end, it’s a business decision (supported by technical capabilities)

Thursday, April 25, 13