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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 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
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
• _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
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
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