nosql @ codemash 2010

98
bensco’ield – viget labs codemash 14 january 2010 NoSQL Death to Relational Databases(?) 1

Upload: ben-scofield

Post on 17-May-2015

6.082 views

Category:

Technology


0 download

DESCRIPTION

Overview of the NoSQL movement, given at CodeMash 2010

TRANSCRIPT

Page 1: NoSQL @ CodeMash 2010

bensco'ield  –  viget  labscodemash14  january  2010

NoSQLDeath  to  Relational  Databases(?)

1

Page 2: NoSQL @ CodeMash 2010

Motivations

2

Page 3: NoSQL @ CodeMash 2010

Performance

3

Page 4: NoSQL @ CodeMash 2010

Scalability

4

Page 5: NoSQL @ CodeMash 2010

Meh

5

Page 6: NoSQL @ CodeMash 2010

Flexibility

6

Page 7: NoSQL @ CodeMash 2010

Complexity

7

Page 8: NoSQL @ CodeMash 2010

“Comics”  Is  Hard

8

Page 9: NoSQL @ CodeMash 2010

9

Page 10: NoSQL @ CodeMash 2010

Functionality

10

Page 11: NoSQL @ CodeMash 2010

Charlie  Chaplin

Jet  Li

Marian  Collier

Hank  Mann

11

Page 12: NoSQL @ CodeMash 2010

Taxonomy

12

Page 13: NoSQL @ CodeMash 2010

Key-­‐Value  Stores

13

Page 14: NoSQL @ CodeMash 2010

distributed  hash  tables

14

Page 15: NoSQL @ CodeMash 2010

PerformanceScalabilityFlexibilityComplexityFunctionality

highhighhighnonevariable  (none)

15

Page 16: NoSQL @ CodeMash 2010

DynamoGT.MPStoreRedis

16

Page 17: NoSQL @ CodeMash 2010

Column-­‐Oriented  Stores

17

Page 18: NoSQL @ CodeMash 2010

semi-­‐structured

18

Page 19: NoSQL @ CodeMash 2010

PerformanceScalabilityFlexibilityComplexityFunctionality

highhighmoderatelowminimal

19

Page 20: NoSQL @ CodeMash 2010

BigTableCassandraHBase

20

Page 21: NoSQL @ CodeMash 2010

Document-­‐Oriented  Stores

21

Page 22: NoSQL @ CodeMash 2010

also  semi-­‐structured

22

Page 23: NoSQL @ CodeMash 2010

PerformanceScalabilityFlexibilityComplexityFunctionality

highvariable  (high)highlowvariable  (low)

23

Page 24: NoSQL @ CodeMash 2010

CouchDBMongoDBRDDBRiak

24

Page 25: NoSQL @ CodeMash 2010

Graph  Databases

25

Page 26: NoSQL @ CodeMash 2010

graph  theory

26

Page 27: NoSQL @ CodeMash 2010

PerformanceScalabilityFlexibilityComplexityFunctionality

variablevariablehighhighgraph  theory

27

Page 28: NoSQL @ CodeMash 2010

ActiveRDF  AllegroGraphNeo4J

28

Page 29: NoSQL @ CodeMash 2010

Relational  Databases

29

Page 30: NoSQL @ CodeMash 2010

PerformanceScalabilityFlexibilityComplexityFunctionality

variablevariablelowmoderaterelational  algebra

30

Page 31: NoSQL @ CodeMash 2010

Examples

31

Page 32: NoSQL @ CodeMash 2010

Redis

32

Page 33: NoSQL @ CodeMash 2010

Data  Typesstringslistssetssorted  sets

33

Page 34: NoSQL @ CodeMash 2010

In-­‐Memoryperiodic  snapshots  /  append  only  'ilemaster-­‐slave  replicationmemory-­‐bound

34

Page 35: NoSQL @ CodeMash 2010

require 'redis'

gl = Redis.new

# A stringgl['name'] = 'Kyle Rayner'gl['name']gl.delete('name')

# A listgl.push_tail 'to-dos', 'Lose Ion power'gl.push_tail 'to-dos', 'Mourn dead loved ones'gl.push_tail 'to-dos', 'Blow up zombie lanterns'

gl.list_range('to-dos', 0, -1)

35

Page 36: NoSQL @ CodeMash 2010

Tokyo  Cabinet

36

Page 37: NoSQL @ CodeMash 2010

Data  Typesbinary  datastrings

37

Page 38: NoSQL @ CodeMash 2010

Tables!?

38

Page 39: NoSQL @ CodeMash 2010

Related  Projectstyrantdystopiapromenade

39

Page 40: NoSQL @ CodeMash 2010

require 'rufus/tokyo'

# Key-valuejli = Rufus::Tokyo::Cabinet.new('jl.tch')jli['members'] = [ 'Batman', 'Black Canary', 'Blue Beetle', 'Captain Marvel', 'Doctor Light', 'Doctor Fate', 'Guy Gardner', 'Martian Manhunter', 'Mister Miracle'].to_yaml

YAML.load(jli['members'])

40

Page 41: NoSQL @ CodeMash 2010

require 'rufus/tokyo'

# Tablebig7 = Rufus::Tokyo::Table.new('big7.tct')

big7['s'] = {'name' => 'Superman', 'role' => 'deus ex machina'}big7['b'] = {'name' => 'Batman', 'role' => 'mastermind'}big7['gl'] = {'name' => 'Green Lantern', 'role' => 'space cop'}big7['f'] = {'name' => 'Flash', 'role' => 'speedster'}big7['mm'] = {'name' => 'Martian Manhunter', 'role' => '?'}big7['ww'] = {'name' => 'Wonder Woman', 'role' => 'hitter'}big7['a'] = {'name' => 'Aquaman', 'role' => 'fish-talking'}

big7.query {|q| q.add_condition 'role', :streq, 'fish-talking'}

41

Page 42: NoSQL @ CodeMash 2010

Cassandra

42

Page 43: NoSQL @ CodeMash 2010

GenealogyDynamoBigTable

43

Page 44: NoSQL @ CodeMash 2010

Column-­‐Orientedcolumnssupercolumnscolumn  families

44

Page 45: NoSQL @ CodeMash 2010

Distributedautomatic  replicationeventual  consistencyeasy  expansion

45

Page 46: NoSQL @ CodeMash 2010

Availabilityweak  readsquorum  reads

46

Page 47: NoSQL @ CodeMash 2010

require 'cassandra'

op = Cassandra.new('OnePiece')

op.insert(:People, '1', {'name' => 'Luffy'})op.insert(:People, '2', {'name' => 'Crocodile'})op.insert(:People, '3', {'name' => 'Mr. 3'})

op.insert(:Fights, '1', {'opponents' => {UUID.new => '2'}})op.insert(:Fights, '1', {'opponents' => {UUID.new => '3'}})

luffy_fights = op.get(:Fights, '1', 'opponents')luffy_fights.map {|t, opp| op.get(:People, opp, 'name')}

47

Page 48: NoSQL @ CodeMash 2010

CouchDB

48

Page 49: NoSQL @ CodeMash 2010

Web-­‐InspiredJSON  storageHTTP  /  RESTful  interface

49

Page 50: NoSQL @ CodeMash 2010

Viewsprede'ined,  updated  incrementallyjavascript  for  map/reduce

50

Page 51: NoSQL @ CodeMash 2010

Updatesfull,  including  embedded  documents

51

Page 52: NoSQL @ CodeMash 2010

require 'couchrest'

konoha = CouchRest.database!('http://127.0.0.1:5984/konoha')naruto = konoha.save_doc { 'name' => 'Naruto Uzumaki', 'chakra' => 'wind'}shikamaru = konoha.save_doc { 'name' => 'Shikamaru Nara', 'chunin' => true}

konoha.save_doc { '_id' => '_design/first', :views => { :chunin => { :map => 'function(doc){if(doc.chunin){emit(null, doc);}}' } }}

puts konoha.views('first/chunin')['rows'].inspect

52

Page 53: NoSQL @ CodeMash 2010

MongoDB

53

Page 54: NoSQL @ CodeMash 2010

Storagebinary  JSON  documents

54

Page 55: NoSQL @ CodeMash 2010

Accessnative  clients

55

Page 56: NoSQL @ CodeMash 2010

Queriesdynamicindex-­‐based

56

Page 57: NoSQL @ CodeMash 2010

Updatesallows  partial  updates

57

Page 58: NoSQL @ CodeMash 2010

require 'mongo'

avengers = Mongo::Connection.new.db('avengers')members = avengers.collection('members')

members.insert {'name' => 'Ant-Man'}members.insert {'name' => 'Hulk'}members.insert {'name' => 'Iron Man'}members.insert {'name' => 'Thor'}members.insert {'name' => 'Wasp'}

members.create_index('name')

pym = members.find {'name' => 'Ant-Man'}pym['name'] = 'Giant-Man'pym.save

members.remove {'name' => 'Hulk'}

members.insert {'name' => 'Captain America'}

58

Page 59: NoSQL @ CodeMash 2010

Riak

59

Page 60: NoSQL @ CodeMash 2010

also  Web-­‐InspiredJSON  storageHTTP  /  RESTful  interfacelinks  for  relationships

60

Page 61: NoSQL @ CodeMash 2010

Decentralizedno  privileged  nodes

61

Page 62: NoSQL @ CodeMash 2010

Con'igurablestore  /  read  /  write

62

Page 63: NoSQL @ CodeMash 2010

require 'jiak'

jc = JiakClient.new('127.0.0.1', 8098)jc.set_bucket_schema('supervillains', { 'allowed_fields' => ['name', 'alias', 'power']})

jc.store({ 'bucket' => 'supervillains', 'key' => 'Normie', 'object' => { 'name' => 'Norman Osborn', 'alias' => 'Green Goblin', 'power' => 'Supreme jerkfacedness' }, 'links' => []})

kth = jc.fetch('supervillains', 'Normie')

63

Page 64: NoSQL @ CodeMash 2010

Neo4J

64

Page 65: NoSQL @ CodeMash 2010

Structurenodes  and  edgeskey-­‐value  pairs

65

Page 66: NoSQL @ CodeMash 2010

Querieslucenegremlin

66

Page 67: NoSQL @ CodeMash 2010

require 'neo4j'

class Person include Neo4j::NodeMixin property :name, :mutant index :name, :mutant has_n :crushes has_n :hookups has_n :marriages def initialize(name, mutant = true) name = name mutant = mutant endend

67

Page 68: NoSQL @ CodeMash 2010

Neo4j::Transaction.run do magneto = Person.new('Magneto') esme = Person.new('Esme') rogue = Person.new('Rogue') magda = Person.new('Magda', false) wasp = Person.new('Wasp', false) magneto.crushes << wasp magneto.hookups << rogue magneto.marriages << magda esme.crushes << magneto rogue.hookups << magneto magda.marriages << magnetoend

68

Page 69: NoSQL @ CodeMash 2010

magneto = Person.find(:name => 'Magneto')

# Who likes Magneto?magneto.relationships.incoming(:crushes).nodes

# Which non-mutants has Magneto dated?magneto.hookups{ !mutant? }.to_a

69

Page 70: NoSQL @ CodeMash 2010

Simulations

70

Page 71: NoSQL @ CodeMash 2010

Structure

71

Page 72: NoSQL @ CodeMash 2010

people{ ‘name’:‘Jimmy Olsen’ ‘title’:‘Superman’s Pal’ ‘company_id’:12441}

companies{ _id:12441 ‘name’:‘Daily Planet’}

72

Page 73: NoSQL @ CodeMash 2010

Lack  of  Structure

73

Page 74: NoSQL @ CodeMash 2010

mysql> SELECT * FROM people LIMIT 1 \G*************************** 1. row *************************** id: 1content: --- company: Daily Planetname: Jimmy Olsentitle: Superman’s Pal

74

Page 75: NoSQL @ CodeMash 2010

But  wait!friendfeedfriendly

75

Page 76: NoSQL @ CodeMash 2010

mysql> desc people;+-------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+-------+-------------+------+-----+---------+-------+| id | int(11) | YES | | NULL | || name | varchar(50) | YES | | NULL | |+-------+-------------+------+-----+---------+-------+

mysql> desc attributes;+-----------+--------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+-----------+--------------+------+-----+---------+-------+| id | int(11) | YES | | NULL | || person_id | int(11) | YES | | NULL | || attribute | varchar(50) | YES | | NULL | || value | varchar(100) | YES | | NULL | |+-----------+--------------+------+-----+---------+-------+

76

Page 77: NoSQL @ CodeMash 2010

Not  Only  SQL

77

Page 78: NoSQL @ CodeMash 2010

Polyglot  Persistence

78

Page 79: NoSQL @ CodeMash 2010

Caching

79

Page 80: NoSQL @ CodeMash 2010

Already  in  Usememcached

80

Page 81: NoSQL @ CodeMash 2010

Queues

81

Page 82: NoSQL @ CodeMash 2010

Long-­‐running  processesresque

82

Page 83: NoSQL @ CodeMash 2010

Logging

83

Page 84: NoSQL @ CodeMash 2010

Rails  Log  Replacementhttp://github.com/peburrows/mongo_db_logger

84

Page 85: NoSQL @ CodeMash 2010

Hybrid  Domains

85

Page 86: NoSQL @ CodeMash 2010

different  domains

86

Page 87: NoSQL @ CodeMash 2010

Publishinge-­‐commercedocuments

87

Page 88: NoSQL @ CodeMash 2010

Datinge-­‐commercesocial  graph

88

Page 89: NoSQL @ CodeMash 2010

different  scales

89

Page 90: NoSQL @ CodeMash 2010

Photo  Sharinguser  accountsuploaded  photos

90

Page 91: NoSQL @ CodeMash 2010

Next  Steps

91

Page 92: NoSQL @ CodeMash 2010

Explore

92

Page 93: NoSQL @ CodeMash 2010

Database  Listhttp://internetmindmap.com/database_software

NoSQL  Google  Grouphttp://groups.google.com/group/nosql-­‐discussion

93

Page 94: NoSQL @ CodeMash 2010

Ignore  the  Database

94

Page 95: NoSQL @ CodeMash 2010

Logical  Modeling  Firstbe  mindful

95

Page 96: NoSQL @ CodeMash 2010

Change  the  Default

96

Page 97: NoSQL @ CodeMash 2010

Application  Templatesstart  with  something  new

97

Page 98: NoSQL @ CodeMash 2010

@bsco'ieldben.sco'[email protected]://spkr8.com/bsco'ieldhttp://viget.com/extendhttp:  //bensco'ield.com

bensco'ield

98