social gaming & gambling summit - london chris anderson

81
@jchris Chris Anderson NoSQL Landscape & Grid Compu7ng 1 Saturday, October 6, 12

Upload: mediabistro

Post on 12-May-2015

309 views

Category:

Documents


1 download

DESCRIPTION

#sgsconf

TRANSCRIPT

Page 1: Social Gaming & Gambling Summit - London Chris Anderson

@jchrisChris  Anderson

NoSQL  Landscape&  Grid  Compu7ng

1Saturday, October 6, 12

Page 2: Social Gaming & Gambling Summit - London Chris Anderson

• 2.2  Billion  internet  users• 50%  Americans  use  smartphones

• Your  app  can  grow  overnight

• Are  you  ready?

2

Growth  is  the  New  Reality

Saturday, October 6, 12

Page 3: Social Gaming & Gambling Summit - London Chris Anderson

Instagrowth:  Android  Launch

• Instagram  gained  nearly  1  million  users  overnight  when  they  expanded  to  Android

Example

3Saturday, October 6, 12

Page 4: Social Gaming & Gambling Summit - London Chris Anderson

1  Instagram=

7.5M  MAU*

4

Instagrowth:  Android  Launch

Example

Saturday, October 6, 12

Page 5: Social Gaming & Gambling Summit - London Chris Anderson

Draw  Something  -­‐  Social  Game

5

35 million monthly active users in 1 monthabout 5 Instagrams

(Instagram today is waaaay more than 1 Instagram)

Saturday, October 6, 12

Page 6: Social Gaming & Gambling Summit - London Chris Anderson

Goes  Viral  3  Weeks  aOer  Launch

6

191715131197533/12826242220181614121082/6

Draw  Something  by  OMGPOPDaily  Ac)ve  Users  (millions)

21

2

4

6

8

10

12

14

16

35+M  MAUat  peak

Saturday, October 6, 12

Page 7: Social Gaming & Gambling Summit - London Chris Anderson

By  Contrast,  at  1/2  an  Instagram

7

The  Simpson’s:  Tapped  OutDaily  Ac)ve  Users  (millions)

Saturday, October 6, 12

Page 8: Social Gaming & Gambling Summit - London Chris Anderson

GETTING  IT  RIGHT

8Saturday, October 6, 12

Page 9: Social Gaming & Gambling Summit - London Chris Anderson

Scalable  Data  Layer

9

●On-­‐demand  cluster  sizing●Grow  or  shrink  with  workload

●Easy  node  provisioning●All  nodes  are  the  same

●MulA-­‐master  Cross-­‐Datacenter  ReplicaAon●For  a  fast  and  reliable  user  experience  worldwide

●EffecAve  Auto-­‐sharding●Should  avoid  cluster  hot  spots

Saturday, October 6, 12

Page 10: Social Gaming & Gambling Summit - London Chris Anderson

Old  School  Hits  a  Scale  Wall

10

Application Scales OutJust add more commodity web servers

Database Scales UpGet a bigger, more complex server

Expensive & disruptive sharding, doesn’t perform at web scale

Saturday, October 6, 12

Page 11: Social Gaming & Gambling Summit - London Chris Anderson

Tradi^onal  MySQL  +  Memcached  Architecture

11

●Run as many MySQL machines as you need

●Data sharded evenly across the machines using client code

●Memcached used to provide faster response time for users and reduce load on the database Memcached  Tier

MySQL  Tier

App  Servers

www.example.com

Saturday, October 6, 12

Page 12: Social Gaming & Gambling Summit - London Chris Anderson

Limita^ons  of  MySQL  +  Memcached

12

● To scale you need to start using MySQL more simply

● Scale by hand

● Replication / Sharding is a black art

● Code overhead to manage keeping memcache and mysql in sync

● Lots of components to deploy

Learn  From  Others  -­‐  This  Scenario  Costs  Time  and  Money.  Scaling  SQL  is  poten^ally  disastrous  when  going  Viral:  very  risky  ^me  for  major  code  changes  and  migra^ons...  you  have  no  Time  when  skyrocke^ng  up.

Saturday, October 6, 12

Page 13: Social Gaming & Gambling Summit - London Chris Anderson

NoSQL  Architectural  Promise

13

Couchbase  Database  Servers

App  Servers

www.example.com

•High Performance data access

• Scale Up/Down Horizontally

• 24x7x365 Always-On Availability

• Flexible Schema Document Model

Saturday, October 6, 12

Page 14: Social Gaming & Gambling Summit - London Chris Anderson

14

NOSQL  TAXONOMY

Saturday, October 6, 12

Page 15: Social Gaming & Gambling Summit - London Chris Anderson

15

The Key-Value Store – the foundation of NoSQL

Key

101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101

101100101000100010011101101100101000100010011101

101100101000100010011101101100101000100010011101101100101000100010011101

OpaqueBinaryValue

Saturday, October 6, 12

Page 16: Social Gaming & Gambling Summit - London Chris Anderson

16

Memcached – the NoSQL precursor

Key

101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101

101100101000100010011101101100101000100010011101

101100101000100010011101101100101000100010011101101100101000100010011101

OpaqueBinaryValue

memcached

In-­‐memory  onlyLimited  set  of  opera^onsBlob  Storage:  Set,  Add,  Replace,  CASRetrieval:  GetStructured  Data:  Append,  Increment

“Simple  and  fast.”

Challenges:  cold  cache,  disrup^ve  elas^city

Saturday, October 6, 12

Page 17: Social Gaming & Gambling Summit - London Chris Anderson

17

Redis  –  More  “Structured  Data”  commands

Key

101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101

101100101000100010011101101100101000100010011101

101100101000100010011101101100101000100010011101101100101000100010011101

“Data  Structures”BlobListSetHash…

redis

In-­‐memory  onlyVast  set  of  opera^onsBlob  Storage:  Set,  Add,  Replace,  CASRetrieval:  Get,  Pub-­‐SubStructured  Data:  Strings,  Hashes,  Lists,  Sets,Sorted  lists

Example  opera7ons  for  a  SetAdd,  count,  subtract  sets,  intersec^on,  is  member?,  atomic  move  from  one  set  to  another

Saturday, October 6, 12

Page 18: Social Gaming & Gambling Summit - London Chris Anderson

18

NoSQL  catalog

Key-­‐Value

memcached redis

Data  Structure Document Column Graph

Cache

(mem

ory  on

ly)

Saturday, October 6, 12

Page 19: Social Gaming & Gambling Summit - London Chris Anderson

19

Membase  –  From  key-­‐value  cache  to  database

Disk-­‐based  with  built-­‐in  memcached  cacheCache  refill  on  restartMemcached  compa^ble  (drop  in  replacement)Highly-­‐available  (data  replica^on)Add  or  remove  capacity  to  live  cluster

“Simple,  fast,  elas^c.”

membaseKey

101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101101100101000100010011101

101100101000100010011101101100101000100010011101

101100101000100010011101101100101000100010011101101100101000100010011101

OpaqueBinaryValue

Saturday, October 6, 12

Page 20: Social Gaming & Gambling Summit - London Chris Anderson

20

NoSQL  catalog

Key-­‐Value

memcached

membase

redis

Data  Structure Document Column Graph

Cache

(mem

ory  on

ly)

Database

(mem

ory/disk)

Saturday, October 6, 12

Page 21: Social Gaming & Gambling Summit - London Chris Anderson

21

Couchbase  –  document-­‐oriented  database

Key

{        “string”  :  “string”,        “string”  :  value,        “string”  :                        {    “string”  :  “string”,                              “string”  :  value  },        “string”  :  [  array  ]}

Auto-­‐shardingDisk-­‐based  with  built-­‐in  memcached  cacheCache  refill  on  restartMemcached  compa^ble  (drop  in  replace)Highly-­‐available  (data  replica^on)Add  or  remove  capacity  to  live  cluster

When  values  are  JSON  objects  (“documents”):Create  indices,  views  and  query  against  the  views

JSONOBJECT

(“DOCUMENT”)

Couchbase

Saturday, October 6, 12

Page 22: Social Gaming & Gambling Summit - London Chris Anderson

22

NoSQL  catalog

Key-­‐Value

memcached

membase

redis

Data  Structure Document Column Graph

Cache

(mem

ory  on

ly)

Database

(mem

ory/disk)

membase couchbase

Saturday, October 6, 12

Page 23: Social Gaming & Gambling Summit - London Chris Anderson

23

MongoDB  –  Document-­‐oriented  database

Key

{        “string”  :  “string”,        “string”  :  value,        “string”  :                        {    “string”  :  “string”,                              “string”  :  value  },        “string”  :  [  array  ]}

Disk-­‐based  with  in-­‐memory  “caching”BSON  (“binary  JSON”)  format  and  wire  protocolMaster-­‐slave  replica^onAuto-­‐shardingValues  are  BSON  objectsSupports  ad  hoc  queries  –  best  when  indexed

BSONOBJECT

(“DOCUMENT”)

MongoDB

Saturday, October 6, 12

Page 24: Social Gaming & Gambling Summit - London Chris Anderson

24

NoSQL  catalog

Key-­‐Value

memcached

membase

redis

Data  Structure Document Column Graph

mongoDB

couchbase

Cache

(mem

ory  on

ly)

Database

(mem

ory/disk)

Saturday, October 6, 12

Page 25: Social Gaming & Gambling Summit - London Chris Anderson

25

Cassandra  –  Column  overlays

Disk-­‐based  systemClustered  External  caching  required  for  low-­‐latency  reads“Columns”  are  overlaid  on  the  dataNot  all  rows  must  have  all  columnsSupports  efficient  queries  on  columnsRestart  required  when  adding  columnsGood  cross-­‐datacenter  support

CassandraColumn  1

Column  2

Column  3  (not  present)  

Saturday, October 6, 12

Page 26: Social Gaming & Gambling Summit - London Chris Anderson

26

NoSQL  catalog

Key-­‐Value

memcached

membase

redis

Data  Structure Document Column Graph

mongoDB

couchbase cassandra

Cache

(mem

ory  on

ly)

Database

(mem

ory/disk)

Saturday, October 6, 12

Page 27: Social Gaming & Gambling Summit - London Chris Anderson

27

Neo4j  –  Graph  database

Disk-­‐based  systemExternal  caching  required  for  low-­‐latency  readsNodes,  rela^onships  and  pathsProper^es  on  nodesDelete,  Insert,  Traverse,  etc.

Neo4j

Saturday, October 6, 12

Page 28: Social Gaming & Gambling Summit - London Chris Anderson

28

NoSQL  catalog

Key-­‐Value

memcached

membase

redis

Data  Structure Document Column Graph

mongoDB

couchbase cassandra

Cache

(mem

ory  on

ly)

Database

(mem

ory/disk)

Neo4j

Saturday, October 6, 12

Page 29: Social Gaming & Gambling Summit - London Chris Anderson

The  Landscape

29

Speed

ScaleCouchbase

Redis

S3

Cassandra

MongoDB

Riak

HBase

CouchDB

Neo4j

SimpleDB

memcached

RDBMSDatomic

Saturday, October 6, 12

Page 30: Social Gaming & Gambling Summit - London Chris Anderson

Datomic  -­‐  immutable  func^onal  data

30Saturday, October 6, 12

Page 31: Social Gaming & Gambling Summit - London Chris Anderson

Hello  Couchbase  Server  2.0

31Saturday, October 6, 12

Page 32: Social Gaming & Gambling Summit - London Chris Anderson

Couchbase  Server  2.0  beta

32Saturday, October 6, 12

Page 33: Social Gaming & Gambling Summit - London Chris Anderson

33

Couchbase  handles  real  world  scale

Saturday, October 6, 12

Page 34: Social Gaming & Gambling Summit - London Chris Anderson

(Really)  High  Performance

34

Latencyless than 1/2 ms

Throughputgrows linearly with cluster size

5 Nodes -- 1.75M operations per second

Cisco and Solarflare benchmark of Couchbase Server

Saturday, October 6, 12

Page 35: Social Gaming & Gambling Summit - London Chris Anderson

How  fast?

35hrp://www.slideshare.net/renatko/couchbase-­‐performance-­‐benchmarking

Saturday, October 6, 12

Page 36: Social Gaming & Gambling Summit - London Chris Anderson

Latency

Saturday, October 6, 12

Page 37: Social Gaming & Gambling Summit - London Chris Anderson

Latency

Saturday, October 6, 12

Page 38: Social Gaming & Gambling Summit - London Chris Anderson

COMPLEXITY  IS  THE  ENEMY

37Saturday, October 6, 12

Page 39: Social Gaming & Gambling Summit - London Chris Anderson

38

Couchbase  Server  Basic  Opera^on

COUCHBASE  CLIENT  LIBRARY

§Docs  distributed  evenly  across  servers  in  the  cluster

§Each  server  stores  both  ac)ve  &  replica  docs§Only  one  server  ac^ve  at  a  ^me

§Client  library  provides  app  with  simple  interface  to  database

§Cluster  map  provides  map  to  which  server  doc  is  on§App  never  needs  to  know

§ App  reads,  writes,  updates  docs§ Mul^ple  App  Servers  can  access  same  document  at  same  ^me

Doc  2

Doc  5

SERVER  1

Doc  4

SERVER  2

Doc  1

SERVER  3

COUCHBASE  CLIENT  LIBRARY

Doc  9

Doc  7

Doc  8 Doc  6

Doc  3

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

Ac^ve  Docs Ac^ve  Docs Ac^ve  Docs

CLUSTER  MAP CLUSTER  MAP

APP  SERVER  1 APP  SERVER  2

COUCHBASE  SERVER  CLUSTER

Saturday, October 6, 12

Page 40: Social Gaming & Gambling Summit - London Chris Anderson

38

Couchbase  Server  Basic  Opera^on

COUCHBASE  CLIENT  LIBRARY

§Docs  distributed  evenly  across  servers  in  the  cluster

§Each  server  stores  both  ac)ve  &  replica  docs§Only  one  server  ac^ve  at  a  ^me

§Client  library  provides  app  with  simple  interface  to  database

§Cluster  map  provides  map  to  which  server  doc  is  on§App  never  needs  to  know

§ App  reads,  writes,  updates  docs§ Mul^ple  App  Servers  can  access  same  document  at  same  ^me

Doc  4

Doc  2

Doc  5

SERVER  1

Doc  6

Doc  4

SERVER  2

Doc  7

Doc  1

SERVER  3

Doc  3

COUCHBASE  CLIENT  LIBRARY

Doc  9

Doc  7

Doc  8 Doc  6

Doc  3

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

Doc  9

Doc  5

DOC

DOC

DOC

Doc  1

Doc  8 Doc  2

Replica  Docs Replica  Docs Replica  Docs

Ac^ve  Docs Ac^ve  Docs Ac^ve  Docs

CLUSTER  MAP CLUSTER  MAP

APP  SERVER  1 APP  SERVER  2

COUCHBASE  SERVER  CLUSTER

Saturday, October 6, 12

Page 41: Social Gaming & Gambling Summit - London Chris Anderson

38

Couchbase  Server  Basic  Opera^on

COUCHBASE  CLIENT  LIBRARY

§Docs  distributed  evenly  across  servers  in  the  cluster

§Each  server  stores  both  ac)ve  &  replica  docs§Only  one  server  ac^ve  at  a  ^me

§Client  library  provides  app  with  simple  interface  to  database

§Cluster  map  provides  map  to  which  server  doc  is  on§App  never  needs  to  know

§ App  reads,  writes,  updates  docs§ Mul^ple  App  Servers  can  access  same  document  at  same  ^me

Doc  4

Doc  2

Doc  5

SERVER  1

Doc  6

Doc  4

SERVER  2

Doc  7

Doc  1

SERVER  3

Doc  3

Read/Write/Update

COUCHBASE  CLIENT  LIBRARY

Read/Write/Update

Doc  9

Doc  7

Doc  8 Doc  6

Doc  3

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

Doc  9

Doc  5

DOC

DOC

DOC

Doc  1

Doc  8 Doc  2

Replica  Docs Replica  Docs Replica  Docs

Ac^ve  Docs Ac^ve  Docs Ac^ve  Docs

CLUSTER  MAP CLUSTER  MAP

APP  SERVER  1 APP  SERVER  2

COUCHBASE  SERVER  CLUSTER

Saturday, October 6, 12

Page 42: Social Gaming & Gambling Summit - London Chris Anderson

39

Add  Nodes  to  the  Cluster

§ Two  servers  added  to  cluster§ One-­‐click  opera^on

§ Docs  automa^cally  rebalanced  across  cluster§ Even  distribu^on  of  docs§ Minimum  doc  movement

§ Cluster  map  updated§ App  database  calls  now  distributed  over  larger  #  of  servers

Doc  7

Doc  9

Doc  3

Ac^ve  Docs

Replica  Docs

Doc  6

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

APP  SERVER  1

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

APP  SERVER  2

Doc  4

Doc  2

Doc  5

SERVER  1

Doc  6

Doc  4

SERVER  2

Doc  7

Doc  1

SERVER  3

Doc  3

Doc  9

Doc  7

Doc  8 Doc  6

Doc  3

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

Doc  9

Doc  5

DOC

DOC

DOC

Doc  1

Doc  8 Doc  2

Replica  Docs Replica  Docs Replica  Docs

Ac^ve  Docs Ac^ve  Docs Ac^ve  Docs

COUCHBASE  SERVER  CLUSTER

Saturday, October 6, 12

Page 43: Social Gaming & Gambling Summit - London Chris Anderson

39

Add  Nodes  to  the  Cluster

§ Two  servers  added  to  cluster§ One-­‐click  opera^on

§ Docs  automa^cally  rebalanced  across  cluster§ Even  distribu^on  of  docs§ Minimum  doc  movement

§ Cluster  map  updated§ App  database  calls  now  distributed  over  larger  #  of  servers

Doc  7

Doc  9

Doc  3

Ac^ve  Docs

Replica  Docs

Doc  6

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

APP  SERVER  1

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

APP  SERVER  2

Doc  4

Doc  2

Doc  5

SERVER  1

Doc  6

Doc  4

SERVER  2

Doc  7

Doc  1

SERVER  3

Doc  3

Doc  9

Doc  7

Doc  8 Doc  6

Doc  3

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

DOC

Doc  9

Doc  5

DOC

DOC

DOC

Doc  1

Doc  8 Doc  2

Replica  Docs Replica  Docs Replica  Docs

Ac^ve  Docs Ac^ve  Docs Ac^ve  Docs

SERVER  4 SERVER  5

Ac^ve  Docs Ac^ve  Docs

Replica  Docs Replica  Docs

COUCHBASE  SERVER  CLUSTER

Saturday, October 6, 12

Page 44: Social Gaming & Gambling Summit - London Chris Anderson

39

Add  Nodes  to  the  Cluster

§ Two  servers  added  to  cluster§ One-­‐click  opera^on

§ Docs  automa^cally  rebalanced  across  cluster§ Even  distribu^on  of  docs§ Minimum  doc  movement

§ Cluster  map  updated§ App  database  calls  now  distributed  over  larger  #  of  servers

Doc  7

Doc  9

Doc  3

Ac^ve  Docs

Replica  Docs

Doc  6

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

APP  SERVER  1

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

APP  SERVER  2

Doc  4

Doc  2

Doc  5

SERVER  1

Doc  6

Doc  4

SERVER  2

Doc  7

Doc  1

SERVER  3

Doc  3

Doc  9

Doc  7 Doc  8

Doc  6

Doc  3

DOC

DOC

DOCDOC

DOC DOC

DOC

DOC

DOC

DOC

DOC DOC

DOC

DOC

DOC

Doc  9

Doc  5DOC

DOC

DOC

Doc  1

Doc  8

Doc  2

Replica  Docs Replica  Docs Replica  Docs

Ac^ve  Docs Ac^ve  Docs Ac^ve  Docs

SERVER  4 SERVER  5

Ac^ve  Docs Ac^ve  Docs

Replica  Docs Replica  Docs

COUCHBASE  SERVER  CLUSTER

Saturday, October 6, 12

Page 45: Social Gaming & Gambling Summit - London Chris Anderson

39

Add  Nodes  to  the  Cluster

§ Two  servers  added  to  cluster§ One-­‐click  opera^on

§ Docs  automa^cally  rebalanced  across  cluster§ Even  distribu^on  of  docs§ Minimum  doc  movement

§ Cluster  map  updated§ App  database  calls  now  distributed  over  larger  #  of  servers

Read/Write/Update Read/Write/Update

Doc  7

Doc  9

Doc  3

Ac^ve  Docs

Replica  Docs

Doc  6

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

APP  SERVER  1

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

APP  SERVER  2

Doc  4

Doc  2

Doc  5

SERVER  1

Doc  6

Doc  4

SERVER  2

Doc  7

Doc  1

SERVER  3

Doc  3

Doc  9

Doc  7 Doc  8

Doc  6

Doc  3

DOC

DOC

DOCDOC

DOC DOC

DOC

DOC

DOC

DOC

DOC DOC

DOC

DOC

DOC

Doc  9

Doc  5DOC

DOC

DOC

Doc  1

Doc  8

Doc  2

Replica  Docs Replica  Docs Replica  Docs

Ac^ve  Docs Ac^ve  Docs Ac^ve  Docs

SERVER  4 SERVER  5

Ac^ve  Docs Ac^ve  Docs

Replica  Docs Replica  Docs

COUCHBASE  SERVER  CLUSTER

Saturday, October 6, 12

Page 46: Social Gaming & Gambling Summit - London Chris Anderson

40

Fail  Over  Node

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

Doc  4

Doc  2

Doc  5

SERVER  1

Doc  6

Doc  4

SERVER  2 SERVER  3

Doc  3

Doc  9

Doc  7 Doc  8

Doc  6DOC

DOC

DOCDOC

DOC

DOC

DOC

DOC

DOC DOC

DOCDoc  5DOC

DOC

DOC

Doc  1

Doc  8

Doc  2

Replica  Docs Replica  Docs Replica  Docs

Ac^ve  Docs Ac^ve  Docs Ac^ve  Docs

SERVER  4 SERVER  5

Ac^ve  Docs Ac^ve  Docs

Replica  Docs Replica  Docs

COUCHBASE  SERVER  CLUSTER

§ App  servers  happily  accessing  docs  on  Server  3

§ Server  fails§ App  server  requests  to  server  3  fail§ Cluster  detects  server  has  failed

§ Promotes  replicas  of  docs  to  ac)ve§ Updates  cluster  map

§ App  server  requests  for  docs  now  go  to  appropriate  server

§ Typically  rebalance  would  follow

Doc  7

Doc  9

Doc  3

Ac^ve  Docs

Replica  Docs

Doc  6

Doc  7

Doc  1

Doc  3

DOC

DOCDoc  9

DOC

DOC

Saturday, October 6, 12

Page 47: Social Gaming & Gambling Summit - London Chris Anderson

40

Fail  Over  Node

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

Doc  4

Doc  2

Doc  5

SERVER  1

Doc  6

Doc  4

SERVER  2 SERVER  3

Doc  3

Doc  9

Doc  7 Doc  8

Doc  6DOC

DOC

DOCDOC

DOC

DOC

DOC

DOC

DOC DOC

DOCDoc  5DOC

DOC

DOC

Doc  1

Doc  8

Doc  2

Replica  Docs Replica  Docs Replica  Docs

Ac^ve  Docs Ac^ve  Docs Ac^ve  Docs

SERVER  4 SERVER  5

Ac^ve  Docs Ac^ve  Docs

Replica  Docs Replica  Docs

COUCHBASE  SERVER  CLUSTER

§ App  servers  happily  accessing  docs  on  Server  3

§ Server  fails§ App  server  requests  to  server  3  fail§ Cluster  detects  server  has  failed

§ Promotes  replicas  of  docs  to  ac)ve§ Updates  cluster  map

§ App  server  requests  for  docs  now  go  to  appropriate  server

§ Typically  rebalance  would  follow

Doc  7

Doc  9

Doc  3

Ac^ve  Docs

Replica  Docs

Doc  6

Doc  7

Doc  1

Doc  3

DOC

DOCDoc  9

DOC

DOC

Saturday, October 6, 12

Page 48: Social Gaming & Gambling Summit - London Chris Anderson

40

Fail  Over  Node

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

Doc  4

Doc  2

Doc  5

SERVER  1

Doc  6

Doc  4

SERVER  2 SERVER  3

Doc  3

Doc  9

Doc  7 Doc  8

Doc  6DOC

DOC

DOCDOC

DOC

DOC

DOC

DOC

DOC DOC

DOCDoc  5DOC

DOC

DOC

Doc  1

Doc  8

Doc  2

Replica  Docs Replica  Docs Replica  Docs

Ac^ve  Docs Ac^ve  Docs Ac^ve  Docs

SERVER  4 SERVER  5

Ac^ve  Docs Ac^ve  Docs

Replica  Docs Replica  Docs

COUCHBASE  SERVER  CLUSTER

§ App  servers  happily  accessing  docs  on  Server  3

§ Server  fails§ App  server  requests  to  server  3  fail§ Cluster  detects  server  has  failed

§ Promotes  replicas  of  docs  to  ac)ve§ Updates  cluster  map

§ App  server  requests  for  docs  now  go  to  appropriate  server

§ Typically  rebalance  would  follow

Doc  7

Doc  9

Doc  3

Ac^ve  Docs

Replica  Docs

Doc  6

Doc  7

Doc  1

Doc  3

DOC

DOCDoc  9

DOC

DOC

Saturday, October 6, 12

Page 49: Social Gaming & Gambling Summit - London Chris Anderson

40

Fail  Over  Node

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

Doc  4

Doc  2

Doc  5

SERVER  1

Doc  6

Doc  4

SERVER  2 SERVER  3

Doc  3

Doc  9

Doc  7 Doc  8

Doc  6DOC

DOC

DOCDOC

DOC

DOC

DOC

DOC

DOC DOC

DOCDoc  5DOC

DOC

DOC

Doc  1

Doc  8

Doc  2

Replica  Docs Replica  Docs Replica  Docs

Ac^ve  Docs Ac^ve  Docs Ac^ve  Docs

SERVER  4 SERVER  5

Ac^ve  Docs Ac^ve  Docs

Replica  Docs Replica  Docs

COUCHBASE  SERVER  CLUSTER

§ App  servers  happily  accessing  docs  on  Server  3

§ Server  fails§ App  server  requests  to  server  3  fail§ Cluster  detects  server  has  failed

§ Promotes  replicas  of  docs  to  ac)ve§ Updates  cluster  map

§ App  server  requests  for  docs  now  go  to  appropriate  server

§ Typically  rebalance  would  follow

Doc  7

Doc  9

Doc  3

Ac^ve  Docs

Replica  Docs

Doc  6

Doc  7

Doc  1

Doc  3

DOC

DOCDoc  9

DOC

DOC

Saturday, October 6, 12

Page 50: Social Gaming & Gambling Summit - London Chris Anderson

40

Fail  Over  Node

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

COUCHBASE  CLIENT  LIBRARYCLUSTER  MAP

Doc  4

Doc  2

Doc  5

SERVER  1

Doc  6

Doc  4

SERVER  2 SERVER  3

Doc  3

Doc  9

Doc  7 Doc  8

Doc  6DOC

DOC

DOCDOC

DOC

DOC

DOC

DOC

DOC DOC

DOCDoc  5DOC

DOC

DOC

Doc  1

Doc  8

Doc  2

Replica  Docs Replica  Docs Replica  Docs

Ac^ve  Docs Ac^ve  Docs Ac^ve  Docs

SERVER  4 SERVER  5

Ac^ve  Docs Ac^ve  Docs

Replica  Docs Replica  Docs

COUCHBASE  SERVER  CLUSTER

§ App  servers  happily  accessing  docs  on  Server  3

§ Server  fails§ App  server  requests  to  server  3  fail§ Cluster  detects  server  has  failed

§ Promotes  replicas  of  docs  to  ac)ve§ Updates  cluster  map

§ App  server  requests  for  docs  now  go  to  appropriate  server

§ Typically  rebalance  would  follow

Saturday, October 6, 12

Page 51: Social Gaming & Gambling Summit - London Chris Anderson

41

●Suddenly, disk writes all began to time out●Many services experienced outages:●FourSquare, Reddit, Quora, among others

●With memory buffered writes, a scalable data layer keeps working●When EBS came back online, Couchbase wrote all the updated data to disk without missing a beat.

War  Story:  EBS  Outage

Saturday, October 6, 12

Page 52: Social Gaming & Gambling Summit - London Chris Anderson

42

Cross  Data  Center  Replica^on

§Data  close  to  users§Mul^ple  loca^ons  for  disaster  recovery§Independently  managed  clusters  serving  local  data

US  DATA  CENTER EUROPE  DATA  CENTER ASIA  DATA  CENTER

Replica7on Replica7on

Replica7on

Saturday, October 6, 12

Page 53: Social Gaming & Gambling Summit - London Chris Anderson

43

Built  for  Produc^on

Saturday, October 6, 12

Page 54: Social Gaming & Gambling Summit - London Chris Anderson

JSON  DOCUMENT  DATABASE

44Saturday, October 6, 12

Page 55: Social Gaming & Gambling Summit - London Chris Anderson

45

Document  Database  as  Aggregate  Database

hrp://mar^nfowler.com/bliki/AggregateOrientedDatabase.html

Saturday, October 6, 12

Page 56: Social Gaming & Gambling Summit - London Chris Anderson

46

Document  Database

This synergy between the programming model and the distribution model is very valuable. It allows the database to use its knowledge of how the application programmer clusters the data to help performance across the cluster.

hrp://mar^nfowler.com/bliki/AggregateOrientedDatabase.html

o::1001{

uid:  ji22jd,customer:  Ann,line_items:  [  

{  sku:  0321293533,  quan:  3,    unit_price:  48.0  },{  sku:  0321601912,  quan:  1,  unit_price:  39.0  },{  sku:  0131495054,  quan:  1,  unit_price:  51.0  }  

],payment:  {  type:  Amex,  expiry:  04/2001,  

last5:  12345  }}

Saturday, October 6, 12

Page 57: Social Gaming & Gambling Summit - London Chris Anderson

Developers  <3  JSON

47Saturday, October 6, 12

Page 58: Social Gaming & Gambling Summit - London Chris Anderson

48

LET’S  GET  POST-­‐RELATIONAL!

Saturday, October 6, 12

Page 59: Social Gaming & Gambling Summit - London Chris Anderson

49

JSON  Documents

• Maps  more  closely  to  external  API• CRUD  Opera^ons,  lightweight  schema

• Stored  under  an  iden^fier  key

{ “fields” : [“with basic types”, 3.14159, true], “like” : “your favorite language”}

client.set(“mydocumentid”, myDocument);mySavedDocument = client.get(“mydocumentid”);

Saturday, October 6, 12

Page 60: Social Gaming & Gambling Summit - London Chris Anderson

Meta  +  Document  Body

50

{      "brewery":  "New  Belgium  Brewing",      "name":  "1554  Enlightened  Black  Ale",      "abv":  5.5,      "descrip7on":  "Born  of  a  flood...",      "category":  "Belgian  and  French  Ale",      "style":  "Other  Belgian-­‐Style  Ales",      "updated":  "2010-­‐07-­‐22  20:00:20"}

{      "id"  :  "beer_Enlightened_Black_Ale”,          ...{

Documentuser data,

can be anything

unique ID

Metadataidentifier,

expiration, etc

“vintage” date format from an SQL dump >_<

Saturday, October 6, 12

Page 61: Social Gaming & Gambling Summit - London Chris Anderson

{      "brewery":  "New  Belgium  Brewing",      "name":  "1554  Enlightened  Black  Ale",      "abv":  5.5,      "descrip7on":  "Born  of  a  flood...",      "category":  "Belgian  and  French  Ale",      "style":  "Other  Belgian-­‐Style  Ales",      "updated":  "2010-­‐07-­‐22  20:00:20",    “ra7ngs”  :  {        “525”  :  5,        “30”  :  4,        “1044”  :  2  },    “comment_ids”  :  [          “f1e62”,          “6ad8c”      ]}

Add  comments  to  the  beer

{      "type":  "comment",      "about_id":  "beer_Enlightened_Black_Ale",      "user_id":  525,      "text":  "tastes  like  college!",      "updated":  "2010-­‐07-­‐22  20:00:20"}

link to comments

link to beer

{      "id":  "f1e62"}

Saturday, October 6, 12

Page 62: Social Gaming & Gambling Summit - London Chris Anderson

52

How  to:  look  up  comments  from  a  beer

• SERIALIZED  LOOP  

figure  hrp://www.ibm.com/developerworks/webservices/library/ws-­‐sdoarch/

beer = client.get(“beer:A_cold_one”);beer.comment_ids.each { |id| comments.push(client.get(id));}

• FAST  MULTI-­‐KEY  LOOKUPbeer = client.get(“beer:A_cold_one”);comments = client.multiGet(beer.comment_ids)

• ASYNC  VIEW  QUERYcomments = client.query(“myapp”,“by_comment_on”, {:key => “beer:A_cold_one”});

Saturday, October 6, 12

Page 63: Social Gaming & Gambling Summit - London Chris Anderson

53

Emergent  Schema

JSON.org

Github  API

Twiqer  API

"Capture  the  user's  intent"

• The  database  can  handle  it• Your  app  controls  the  schema

Saturday, October 6, 12

Page 64: Social Gaming & Gambling Summit - London Chris Anderson

Audience  par^cipa^on!  *that  means  you

54

npm install twitterfightnpm start twitterfight

Saturday, October 6, 12

Page 65: Social Gaming & Gambling Summit - London Chris Anderson

@jchrishrp://www.couchbase.com/

Chris  Anderson

Thank  You!

55Saturday, October 6, 12

Page 66: Social Gaming & Gambling Summit - London Chris Anderson

56

INCREMENTAL  MAP-­‐REDUCEFOR  REALTIME  ANALYTICS

Saturday, October 6, 12

Page 67: Social Gaming & Gambling Summit - London Chris Anderson

What  do  you  mean  “Incremental?”

like:CREATE INDEX city ON brewery city;

57Saturday, October 6, 12

Page 68: Social Gaming & Gambling Summit - London Chris Anderson

58

QUERY  PATTERN:FIND  BY  ATTRIBUTE

Saturday, October 6, 12

Page 69: Social Gaming & Gambling Summit - London Chris Anderson

59

Find  documents  by  a  specific  arribute

• Lets  find  beers  by  brewery_id!

Saturday, October 6, 12

Page 70: Social Gaming & Gambling Summit - London Chris Anderson

60

The  index  defini^on

Saturday, October 6, 12

Page 71: Social Gaming & Gambling Summit - London Chris Anderson

61

The  result  set:  beers  keyed  by  brewery_id

Saturday, October 6, 12

Page 72: Social Gaming & Gambling Summit - London Chris Anderson

62

QUERY  PATTERN:BASIC  AGGREGATIONS

Saturday, October 6, 12

Page 73: Social Gaming & Gambling Summit - London Chris Anderson

63

Use  a  built-­‐in  reduce  func^on  with  a  group  query

• Lets  find  average  abv  for  each  brewery!

Saturday, October 6, 12

Page 74: Social Gaming & Gambling Summit - London Chris Anderson

64

We  are  reducing  doc.abv  with  _stats

Saturday, October 6, 12

Page 75: Social Gaming & Gambling Summit - London Chris Anderson

65

Group  reduce  (reduce  by  unique  key)

Saturday, October 6, 12

Page 76: Social Gaming & Gambling Summit - London Chris Anderson

66

QUERY  PATTERN:TIME-­‐BASED  ROLLUPSWITH  KEY  GROUPING

Saturday, October 6, 12

Page 77: Social Gaming & Gambling Summit - London Chris Anderson

group_level=3  -­‐  daily  results  -­‐  great  for  graphing

67

• Daily,  hourly,  minute  or  second  rollup  all  possible  with  the  same  index.

• hrp://crate.im/posts/couchbase-­‐views-­‐reddit-­‐data/

Saturday, October 6, 12

Page 78: Social Gaming & Gambling Summit - London Chris Anderson

68

GEO  INDEX  &  FULL  TEXT  INTEGRATION

Saturday, October 6, 12

Page 79: Social Gaming & Gambling Summit - London Chris Anderson

69

GeoCouch  R-­‐Tree  Index

• Op^mized  for  bulk  loading  of  large  data  sets• Simplified  query  model  (bounding  box,  nearest  neighbor)

Saturday, October 6, 12

Page 80: Social Gaming & Gambling Summit - London Chris Anderson

Elas^c  Search  Adapter

70

• Elas^c  Search  is  good  for  ad-­‐hoc  queries  and  faceted  browsing• Our  adapter  is  aware  of  changing  Couchbase  topology• Indexed  by  Elas^c  Search  aOer  stored  to  disk  in  Couchbase

Saturday, October 6, 12

Page 81: Social Gaming & Gambling Summit - London Chris Anderson

@jchrishrp://www.couchbase.com/

Chris  Anderson

Thank  You!

71Saturday, October 6, 12