Share
Embed
Getting Started with NoSQL with Couchbase
A generic presentation about NoSQL and Couchbase
Tugdual Grall
January 04, 2013
Transcript
88 slides
-
Technical Evangelist twi0er: @tgrall email: [email protected] Tugdual “Tug” Grall Introduc1on
to NoSQL using Couchbase Friday, January 4, 13 -
Technical Evangelist twi0er: @tgrall email: [email protected] Tugdual “Tug” Grall Introduc1on
to NoSQL using Couchbase Friday, January 4, 13 -
Agenda • Why RDBMS are not enough? • What are
the different NoSQL taxonomies? • Couchbase 2.0 • Quick Server Architecture Overview • Intro to Couchbase Operations • Intro to JSON Documents • Querying & Indexing • Demos... Friday, January 4, 13 -
Growth is the New Reality • Instagram gained nearly 1
million users overnight when then expanded to Android Friday, January 4, 13 -
Draw Something -‐ Social Game 35 million monthly active users
in 1 month !!! Friday, January 4, 13 -
By contrast.... The Simpson’s : Tapped Out Daily Active Users
(Millions) Friday, January 4, 13 -
How do you take this growth? RDBMS is good for
many thing, but hard to scale RDBMS Scales Up Get a bigger, more complex server Users Applica:on Scales Out Just add more commodity web servers Users System Cost Applica1on Performance Rela(onal Database Web/App Server Tier System Cost Applica1on Performance Won’t scale beyond this point Friday, January 4, 13 -
Scaling out RDBMS • Run Many SQL Servers • Data
could be shared -‐ Done by the applica1on code • Caching for faster response 1me Web/App Server Tier Memcached Tier MySQL Tier Friday, January 4, 13 -
Good Approach to Scale? • Lot of components to deploy
• Scale by Hand -‐ Caching -‐ Sharding Friday, January 4, 13 -
Good Approach to Scale? • Lot of components to deploy
• Scale by Hand -‐ Caching -‐ Sharding Learn from others: This scenario costs (me and money. Friday, January 4, 13 -
NoSQL Technology Scales Out Scaling out flaHens the cost and
performance curves NoSQL Database Scales Out Cost and performance mirrors app :er Users NoSQL Distributed Data Store Web/App Server Tier Applica:on Scales Out Just add more commodity web servers Users System Cost Applica1on Performance Applica1on Performance System Cost Friday, January 4, 13 -
A New Technology? Building new database to answer the following
requirements • No schema required before inser1ng data • No schema change required to change data format • Auto-‐sharding without applica1on par1cipa1on • Distributed queries • Integrated main memory caching • Data synchroniza1on ( mul1-‐datacenter) Dynamo October 2007 Cassandra August 2008 Bigtable November 2006 Voldemort February 2009 Very few organiza(ons want to (fewer can) build and maintain database soNware technology. But every organiza(on building interac(ve web applica(ons needs this technology. Friday, January 4, 13 -
What Is Biggest Data Management Problem Driving Use of
NoSQL in Coming Year? Lack of flexibility/ rigid schemas Inability to scale out data Performance challenges Cost All of these Other 49% 35% 29% 16% 12% 11% Source: Couchbase Survey, December 2011, n = 1351. Friday, January 4, 13 -
The foundaBon of NoSQL Key Value Store Key 101100101000100010011101 101100101000100010011101
101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 Opaque Binary Value Friday, January 4, 13 -
NoSQL Precursor Memcached Key 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101
101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 Opaque Binary Value Memcached • In Memory Only • Limited Set of opera:ons • Blob storage : Set, Add, Replace, CAS • Retrieval : Get • Structured Data : Append, Increment • “Simple and Fast” • Challenges : cold cache, disrup1ve elas1city Friday, January 4, 13 -
More “Structured Data” commands Redis • In Memory Only
• Vast Set of opera:ons • Blob storage : Set, Add, Replace, CAS • Retrieval : Get, Pub-‐Sub • Structured Data : Strings, Hashes, Lists, Sets, Sorted lists Redis Key 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 “Data Structures” Blob List Set Hash … Friday, January 4, 13 -
From key-‐value cache to database Membase • Disk based with
built-‐in memcached cache • Cache Refill on restart • Memcached compa:ble: drop in replacement • Highly-‐available: data replica1on • Add or remove capacity to live cluster “Simple, fast, elas:c.” Membase Key 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 Opaque Binary Value Friday, January 4, 13 -
NoSQL Catalog Key-‐Value Memcached Membase Redis Data Structure Cache (memory
only) Database (memory/disk) Friday, January 4, 13 -
Document Oriented Database Couchbase • Auto-‐sharding • Disk based with
built-‐in memcached cache • Cache Refill on restart • Memcached compa:ble: drop in replacement • Highly-‐available: data replica1on • Add or remove capacity to live cluster • When values are JSON objects : • Create indices, views and query against the views Couchbase Key { “string” : “string”, “string” : value, “string” : { “string” : “string”, “string” : value }, “string” : [ array ] } JSON OBJECT (“DOCUMENT”) Friday, January 4, 13 -
NoSQL Catalog Key-‐Value Memcached Membase Redis Data Structure Document Couchbase
Cache (memory only) Database (memory/disk) Friday, January 4, 13 -
Document Oriented Database MongoDB • Disk-‐based with in memory “caching”
• BSON (Binary JSON) format and wire protocol • Master-‐slave replica:on • Values are BSON objects • Supports ad hoc queries (best when indexed) MongoDB Key { “string” : “string”, “string” : value, “string” : { “string” : “string”, “string” : value }, “string” : [ array ] } JSON OBJECT (“DOCUMENT”) Friday, January 4, 13 -
Column Overlays Cassandra • Disk-‐based • Clustered • External caching
required for low-‐latency reads • “Columns” are overlaid on the data • Not all rows must have all columns • Support efficient queries on columns Cassandra Key 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 101100101000100010011101 Opaque Binary Value Column 1 Column 2 Column 3 (not present) Friday, January 4, 13 -
Graph Database Neo4J • Disk-‐based • External caching required for
low latency reads • Nodes, rela:onships and paths • Proper:es on nodes • No Sharding • Opera:ons: Insert, Delete, Traverse, … Neo4J Key Opaque Binary Value Key Opaque Binary Value Key Opaque Binary Value Key Opaque Binary Value Key Opaque Binary Value Key Opaque Binary Value Friday, January 4, 13 -
NoSQL Catalog Key-‐Value Memcached Membase Redis Data Structure Document Column
Graph MongoDB Couchbase Cassandra Cache (memory only) Database (memory/disk) Neo4j Friday, January 4, 13 -
NoSQL Catalog Key-‐Value Memcached Membase Redis Data Structure Document Column
Graph MongoDB Couchbase Cassandra Cache (memory only) Database (memory/disk) Neo4j Friday, January 4, 13 -
NoSQL Catalog Key-‐Value Memcached Membase Redis Data Structure Document Column
Graph MongoDB Couchbase Cassandra Cache (memory only) Database (memory/disk) Neo4j HBase InfiniteGraph Coherence Friday, January 4, 13 -
SubBtle Couchbase Server 2.0 Architecture Heartbeat Process monitor Global singleton
supervisor Configura1on manager on each node Rebalance orchestrator Node health monitor one per cluster vBucket state and replica1on manager hep REST management API/Web UI HTTP 8091 Erlang port mapper 4369 Distributed Erlang 21100 -‐ 21199 Erlang/OTP storage interface Couchbase EP Engine 11210 Memcapable 2.0 Moxi 11211 Memcapable 1.0 Memcached New Persistence Layer 8092 Query API Query Engine Data Manager Cluster Manager Friday, January 4, 13 -
Couchbase Server 2.0 Architecture New Persistence Layer Heartbeat Process monitor
Global singleton supervisor Configura1on manager on each node Rebalance orchestrator Node health monitor one per cluster vBucket state and replica1on manager hep REST management API/Web UI HTTP 8091 Erlang port mapper 4369 Distributed Erlang 21100 -‐ 21199 Erlang/OTP storage interface Couchbase EP Engine 11210 Memcapable 2.0 Moxi 11211 Memcapable 1.0 Object-‐level Cache New Persistence Layer 8092 Query API Query Engine Friday, January 4, 13 -
Cross Data Replica1on • Data close to users • Mul1ple
loca1ons for disaster recovery • Independently managed clusters serving local data US DATA CENTER EUROPE DATA CENTER ASIA DATA CENTER Replica:on Replica:on Replica:on Friday, January 4, 13 -
Install Couchbase Server 2.0 ✴ www.couchbase.com/couchbase-‐server/beta ✴ www.couchbase.com/download ✴ select
2.0.0 recent builds in dropdown OR, for the Latest 2.0 Build Ubuntu RedHat Mac OS X Windows Friday, January 4, 13 -
Install Couchbase Server 2.0 ✴ www.couchbase.com/couchbase-‐server/beta ✴ www.couchbase.com/download ✴ select
2.0.0 recent builds in dropdown OR, for the Latest 2.0 Build select 2.0.0 recent builds Ubuntu RedHat Mac OS X Windows Friday, January 4, 13 -
Install Couchbase Server 2.0 ✴ www.couchbase.com/couchbase-‐server/beta ✴ www.couchbase.com/download ✴ select
2.0.0 recent builds in dropdown OR, for the Latest 2.0 Build Ubuntu RedHat Mac OS X Windows Friday, January 4, 13 -
Install Couchbase Server 2.0 ✴ www.couchbase.com/couchbase-‐server/beta ✴ www.couchbase.com/download ✴ select
2.0.0 recent builds in dropdown OR, for the Latest 2.0 Build Ubuntu RedHat Mac OS X Windows Friday, January 4, 13 -
Basic Opera1ons COUCHBASE SERVER CLUSTER • Docs distributed evenly
across servers • Each server stores both ac:ve and replica docs Only one doc ac1ve at a 1me • 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 ACTIVE Doc 5 Doc 2 Doc Doc Doc SERVER 1 ACTIVE Doc 4 Doc 7 Doc Doc Doc SERVER 2 Doc 8 ACTIVE Doc 1 Doc 2 Doc Doc Doc SERVER 3 Doc 6 Doc 9 Friday, January 4, 13 -
Basic Opera1ons COUCHBASE SERVER CLUSTER • Docs distributed evenly
across servers • Each server stores both ac:ve and replica docs Only one doc ac1ve at a 1me • 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 ACTIVE Doc 5 Doc 2 Doc Doc Doc SERVER 1 ACTIVE Doc 4 Doc 7 Doc Doc Doc SERVER 2 Doc 8 ACTIVE Doc 1 Doc 2 Doc Doc Doc REPLICA Doc 4 Doc 1 Doc 8 Doc Doc Doc REPLICA Doc 6 Doc 3 Doc 2 Doc Doc Doc REPLICA Doc 7 Doc 9 Doc 5 Doc Doc Doc SERVER 3 Doc 6 Doc 9 Friday, January 4, 13 -
Basic Opera1ons COUCHBASE SERVER CLUSTER • Docs distributed evenly
across servers • Each server stores both ac:ve and replica docs Only one doc ac1ve at a 1me • 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 ACTIVE Doc 5 Doc 2 Doc Doc Doc SERVER 1 ACTIVE Doc 4 Doc 7 Doc Doc Doc SERVER 2 Doc 8 ACTIVE Doc 1 Doc 2 Doc Doc Doc REPLICA Doc 4 Doc 1 Doc 8 Doc Doc Doc REPLICA Doc 6 Doc 3 Doc 2 Doc Doc Doc REPLICA Doc 7 Doc 9 Doc 5 Doc Doc Doc SERVER 3 Doc 6 APP SERVER 1 COUCHBASE Client Library CLUSTER MAP COUCHBASE Client Library CLUSTER MAP APP SERVER 2 Doc 9 Friday, January 4, 13 -
Basic Opera1ons COUCHBASE SERVER CLUSTER • Docs distributed evenly
across servers • Each server stores both ac:ve and replica docs ACTIVE Doc 5 Doc 2 Doc Doc Doc SERVER 1 ACTIVE Doc 4 Doc 7 Doc Doc Doc SERVER 2 Doc 8 ACTIVE Doc 1 Doc 2 Doc Doc Doc REPLICA Doc 4 Doc 1 Doc 8 Doc Doc Doc REPLICA Doc 6 Doc 3 Doc 2 Doc Doc Doc REPLICA Doc 7 Doc 9 Doc 5 Doc Doc Doc SERVER 3 Doc 6 APP SERVER 1 COUCHBASE Client Library CLUSTER MAP COUCHBASE Client Library CLUSTER MAP APP SERVER 2 Doc 9 Friday, January 4, 13 -
Basic Opera1ons COUCHBASE SERVER CLUSTER • Docs distributed evenly
across servers • Each server stores both ac:ve and replica docs Only one doc ac1ve at a 1me ACTIVE Doc 5 Doc 2 Doc Doc Doc SERVER 1 ACTIVE Doc 4 Doc 7 Doc Doc Doc SERVER 2 Doc 8 ACTIVE Doc 1 Doc 2 Doc Doc Doc REPLICA Doc 4 Doc 1 Doc 8 Doc Doc Doc REPLICA Doc 6 Doc 3 Doc 2 Doc Doc Doc REPLICA Doc 7 Doc 9 Doc 5 Doc Doc Doc SERVER 3 Doc 6 APP SERVER 1 COUCHBASE Client Library CLUSTER MAP COUCHBASE Client Library CLUSTER MAP APP SERVER 2 Doc 9 Friday, January 4, 13 -
Basic Opera1ons COUCHBASE SERVER CLUSTER • Docs distributed evenly
across servers • Each server stores both ac:ve and replica docs Only one doc ac1ve at a 1me • Client library provides app with simple interface to database ACTIVE Doc 5 Doc 2 Doc Doc Doc SERVER 1 ACTIVE Doc 4 Doc 7 Doc Doc Doc SERVER 2 Doc 8 ACTIVE Doc 1 Doc 2 Doc Doc Doc REPLICA Doc 4 Doc 1 Doc 8 Doc Doc Doc REPLICA Doc 6 Doc 3 Doc 2 Doc Doc Doc REPLICA Doc 7 Doc 9 Doc 5 Doc Doc Doc SERVER 3 Doc 6 APP SERVER 1 COUCHBASE Client Library CLUSTER MAP COUCHBASE Client Library CLUSTER MAP APP SERVER 2 Doc 9 Friday, January 4, 13 -
Basic Opera1ons COUCHBASE SERVER CLUSTER • Docs distributed evenly
across servers • Each server stores both ac:ve and replica docs Only one doc ac1ve at a 1me • Client library provides app with simple interface to database • Cluster map provides map to which server doc is on ACTIVE Doc 5 Doc 2 Doc Doc Doc SERVER 1 ACTIVE Doc 4 Doc 7 Doc Doc Doc SERVER 2 Doc 8 ACTIVE Doc 1 Doc 2 Doc Doc Doc REPLICA Doc 4 Doc 1 Doc 8 Doc Doc Doc REPLICA Doc 6 Doc 3 Doc 2 Doc Doc Doc REPLICA Doc 7 Doc 9 Doc 5 Doc Doc Doc SERVER 3 Doc 6 APP SERVER 1 COUCHBASE Client Library CLUSTER MAP COUCHBASE Client Library CLUSTER MAP APP SERVER 2 Doc 9 Friday, January 4, 13 -
Basic Opera1ons COUCHBASE SERVER CLUSTER • Docs distributed evenly
across servers • Each server stores both ac:ve and replica docs Only one doc ac1ve at a 1me • Client library provides app with simple interface to database • Cluster map provides map to which server doc is on App never needs to know ACTIVE Doc 5 Doc 2 Doc Doc Doc SERVER 1 ACTIVE Doc 4 Doc 7 Doc Doc Doc SERVER 2 Doc 8 ACTIVE Doc 1 Doc 2 Doc Doc Doc REPLICA Doc 4 Doc 1 Doc 8 Doc Doc Doc REPLICA Doc 6 Doc 3 Doc 2 Doc Doc Doc REPLICA Doc 7 Doc 9 Doc 5 Doc Doc Doc SERVER 3 Doc 6 APP SERVER 1 COUCHBASE Client Library CLUSTER MAP COUCHBASE Client Library CLUSTER MAP APP SERVER 2 Doc 9 Friday, January 4, 13 -
Basic Opera1ons COUCHBASE SERVER CLUSTER • Docs distributed evenly
across servers • Each server stores both ac:ve and replica docs Only one doc ac1ve at a 1me • 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 ACTIVE Doc 5 Doc 2 Doc Doc Doc SERVER 1 ACTIVE Doc 4 Doc 7 Doc Doc Doc SERVER 2 Doc 8 ACTIVE Doc 1 Doc 2 Doc Doc Doc REPLICA Doc 4 Doc 1 Doc 8 Doc Doc Doc REPLICA Doc 6 Doc 3 Doc 2 Doc Doc Doc REPLICA Doc 7 Doc 9 Doc 5 Doc Doc Doc SERVER 3 Doc 6 APP SERVER 1 COUCHBASE Client Library CLUSTER MAP COUCHBASE Client Library CLUSTER MAP APP SERVER 2 Doc 9 Friday, January 4, 13 -
Basic Opera1ons COUCHBASE SERVER CLUSTER • Docs distributed evenly
across servers • Each server stores both ac:ve and replica docs Only one doc ac1ve at a 1me • 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 READ/WRITE/UPDATE ACTIVE Doc 5 Doc 2 Doc Doc Doc SERVER 1 ACTIVE Doc 4 Doc 7 Doc Doc Doc SERVER 2 Doc 8 ACTIVE Doc 1 Doc 2 Doc Doc Doc REPLICA Doc 4 Doc 1 Doc 8 Doc Doc Doc REPLICA Doc 6 Doc 3 Doc 2 Doc Doc Doc REPLICA Doc 7 Doc 9 Doc 5 Doc Doc Doc SERVER 3 Doc 6 APP SERVER 1 COUCHBASE Client Library CLUSTER MAP COUCHBASE Client Library CLUSTER MAP APP SERVER 2 Doc 9 Friday, January 4, 13 -
• get (key) – Retrieve a document • set (key,
value) – Store a document, overwrites if exists • add (key, value) – Store a document, error/excep1on if exists • replace (key, value) – Store a document, error/excep1on if doesn’t exist • cas (key, value, cas) – Compare and swap, mutate document only if it hasn’t changed while execu1ng this opera1on Basic Opera1ons Friday, January 4, 13 -
Atomic Counter Opera1ons These operaBons are always executed in order
atomically. • set (key, value) – Use set to iniBalize the counter •cb.set(“my_counter”, 1) • incr (key) – Increase an atomic counter value, default by 1 •cb.incr(“my_counter”) # now it’s 2 • decr (key) – Decrease an atomic counter value, default by 1 •cb.decr(“my_counter”) # now it’s 1 Friday, January 4, 13 -
Rela1onal vs Document Data Model Rela(onal data model Document data
model Collec1on of complex documents with arbitrary, nested data formats and varying “record” format. Highly-‐structured table organiza1on with rigidly-‐defined data formats and record structure. JSON JSON C1 C2 C3 C4 JSON { } Friday, January 4, 13 -
RDBMS Example: User Profile Address Info 1 DEN 30303 CO
2 MV 94040 CA 3 CHI 60609 IL User Info KEY First ZIP_id Last 4 NY 10010 NY 1 Frank 2 Weigel 2 Ali 2 Dodson 3 Mark 2 Azad 4 Steve 3 Yen ZIP_id CITY ZIP STATE 1 Frank 2 Weigel 2 MV 94040 CA To get info about specific user, you perform a join across 2 tables SELECT * FROM Users u INNER JOIN Addresses a ON u.zip_id = a.zip_id WHERE key=1 Friday, January 4, 13 -
RDBMS Example: User Profile Address Info 1 DEN 30303 CO
2 MV 94040 CA 3 CHI 60609 IL User Info KEY First ZIP_id Last 4 NY 10010 NY 1 Frank 2 Weigel 2 Ali 2 Dodson 3 Mark 2 Azad 4 Steve 3 Yen ZIP_id CITY ZIP STATE 1 Frank 2 Weigel 2 MV 94040 CA To get info about specific user, you perform a join across 2 tables SELECT * FROM Users u INNER JOIN Addresses a ON u.zip_id = a.zip_id WHERE key=1 Friday, January 4, 13 -
All data in a single document / Aggregate Oriented Database
Document Example: User Profile { “ID”: 1, “FIRST”: “Frank”, “LAST”: “Weigel”, “ZIP”: “94040”, “CITY”: “MV”, “STATE”: “CA” } JSON = + couchbase.get(“1”); Friday, January 4, 13 -
User ID First Last Zip 1 Frank Wiegel 94040 2
Joe Smith 94040 3 Ali Dodson 94040 4 Sarah Gorin NW1 5 Bob Young 30303 6 Nancy Baker 10010 7 Ray Jones 31311 8 Lee Chen V5V3M • • • • • • • • • • • • 50000 Doug Moore 04252 50001 Mary White SW195 50002 Lisa Clark 12425 User ID Photo ID Comment 2 d043 NYC 2 b054 Bday 5 c036 Miami 7 d072 Sunset 5002 e086 Spain Photo Table User ID Status ID Text 1 a42 At conf 4 b26 excited 5 c32 hockey 12 d83 Go A’s 5000 e34 sailing Status Table User ID Affl ID Affl Name 2 a42 Cal 4 b96 USC 7 c14 UW 8 e22 Oxford Affilia(ons Table User Table Making a Change Using RDBMS Friday, January 4, 13 -
User ID First Last Zip 1 Frank Wiegel 94040 2
Joe Smith 94040 3 Ali Dodson 94040 4 Sarah Gorin NW1 5 Bob Young 30303 6 Nancy Baker 10010 7 Ray Jones 31311 8 Lee Chen V5V3M • • • • • • • • • • • • 50000 Doug Moore 04252 50001 Mary White SW195 50002 Lisa Clark 12425 Country ID TEL3 001 Country ID Country name 001 USA 002 UK 003 Argen(na 004 Australia 005 Aruba 006 Austria 007 Brazil 008 Canada 009 Chile • • • • • • 130 Portugal 131 Romania 132 Russia 133 Spain 134 Sweden User ID Photo ID Comment 2 d043 NYC 2 b054 Bday 5 c036 Miami 7 d072 Sunset 5002 e086 Spain Photo Table 001 007 001 133 133 User ID Status ID Text 1 a42 At conf 4 b26 excited 5 c32 hockey 12 d83 Go A’s 5000 e34 sailing Status Table 134 007 008 001 005 Country Table User ID Affl ID Affl Name 2 a42 Cal 4 b96 USC 7 c14 UW 8 e22 Oxford Affilia(ons Table Country ID 001 001 001 002 Country ID Country ID 001 001 002 001 001 001 008 001 002 001 User Table . . . Making a Change Using RDBMS Friday, January 4, 13 -
Making the Same Change With a Document Database
{ “ID”: 1, “FIRST”: “Frank”, “LAST”: “Weigel”, “ZIP”: “94040”, “CITY”: “MV”, “STATE”: “CA”, “STATUS”: { “TEXT”: “At Conf” } JSON } Friday, January 4, 13 -
Making the Same Change With a Document Database
{ “ID”: 1, “FIRST”: “Frank”, “LAST”: “Weigel”, “ZIP”: “94040”, “CITY”: “MV”, “STATE”: “CA”, “STATUS”: { “TEXT”: “At Conf” } “GEO_LOC”: “134” }, “COUNTRY”: ”USA” Just add informa(on to a document JSON , Friday, January 4, 13 -
User ID First First Last Zip 1 Frank Frank
Wiegel 94040 2 Joe Joe Smith 94040 3 Ali Ali Dodson 94040 4 Sarah Sarah Gorin NW1 5 Bob Bob Young 30303 6 Nancy Nancy Baker 10010 7 Ray Ray Jones 31311 8 Lee Lee Chen V5V3 • • • • • • • • • • • • • • • 5000 5000 Doug Moore 04252 5001 5001 Mary White 41694 5002 5002 Lisa Clark 12425 User ID Photo ID Comment 2 d043 NYC 2 b054 Bday 5 c036 Miami 7 d072 Sunset 5002 e086 Spain User Table Photo Table User ID Status ID Text 1 a42 At conf 4 b26 excited 5 c32 hockey 12 d83 Go A’s 5000 e34 sailing Status Table User ID Affilia1ons ID Affilia1ons Name 2 a42 Cal 4 b96 USC 7 c14 UW 8 e22 Oxford Affilia(ons Table Rela1onal vs Document Performance JSON { } JSON { } JSON { } JSON { } JSON { } JSON { } JSON { } JSON { } JSON { } JSON { } Faster response (mes and higher throughput Friday, January 4, 13 -
User ID First First Last Zip 1 Frank Frank
Wiegel 94040 2 Joe Joe Smith 94040 3 Ali Ali Dodson 94040 4 Sarah Sarah Gorin NW1 5 Bob Bob Young 30303 6 Nancy Nancy Baker 10010 7 Ray Ray Jones 31311 8 Lee Lee Chen V5V3 • • • • • • • • • • • • • • • 5000 5000 Doug Moore 04252 5001 5001 Mary White 41694 5002 5002 Lisa Clark 12425 User ID Photo ID Comment 2 d043 NYC 2 b054 Bday 5 c036 Miami 7 d072 Sunset 5002 e086 Spain User Table Photo Table User ID Status ID Text 1 a42 At conf 4 b26 excited 5 c32 hockey 12 d83 Go A’s 5000 e34 sailing Status Table User ID Affilia1ons ID Affilia1ons Name 2 a42 Cal 4 b96 USC 7 c14 UW 8 e22 Oxford Affilia(ons Table Rela1onal vs Document Performance JSON { } JSON { } JSON { } JSON { } JSON { } Faster response (mes and higher throughput Friday, January 4, 13 -
JSON Only? Nope! Couchbase can store straight strings, binary blobs,
JSON Documents and a special structure called an Atomic Counter (a posi1ve integer value with its own special opera1ons). Maximum size of a Document is 20MB. Friday, January 4, 13 -
Indexing and Querying • Build in incremental map reduce •
Map funcBons are wri0en and executed on Java Script (V8) • Index is built incrementally as mutaBon streams in • Query in a sca0er/gather fashion Friday, January 4, 13 -
Reduce Func1ons • Built in reduce funcBons • _count
• _sum • _stats ({“sum”: 1411, “count”: 1411, “min”: 1, “max”: 1, “sumsqr”:1411}) • Developing procedure • Develop against a subset of the data • Built the index on the enBre cluster • Promote a dev_ view to producBon Friday, January 4, 13 -
GeoCouch R-‐Tree Index • Optimized for bulk loading of large
data sets • Simplified query model (bounding box, nearest neighbor) Friday, January 4, 13 -
Elas1c Search Adaptor • Elastic Search is good for ad-hoc
queries and faceted browsing • Our adapter is aware of changing Couchbase topology • Indexed by Elastic Search after stored to disk in Couchbase Elas(cSearch Friday, January 4, 13 -
I’m Excited to See What You Build, Q & A
Contact me on TwiHer @tgrall Contact me by Email [email protected] Learn More About Design PaHerns CouchbaseModels.com Sewng up for Ruby on Rails CouchbaseOnRails.com Coming Soon... CouchbaseOnNode.com Couchbase Docs www.couchbase.com/docs/index-‐full.html Couchbase Forums www.couchbase.com/forums IRC #couchbase #libcouchbase French Meetup www.meetup.com/Couchbase-‐France Friday, January 4, 13