I have a No SQL Toaster Why would

  • Slides: 74
Download presentation
I have a No. SQL Toaster. Why would I want a No. SQL database?

I have a No. SQL Toaster. Why would I want a No. SQL database? Matthew D. Groves @mgroves #Couchbase Original slides by Matthew Revell - @matthewrevell

© 2017 Couchbase Inc. 2

© 2017 Couchbase Inc. 2

Where am I? • QCon New York • https: //qconnewyork. com/ © 2017 Couchbase

Where am I? • QCon New York • https: //qconnewyork. com/ © 2017 Couchbase Inc. 3

Who am I? • • • Matthew D. Groves Developer Advocate for Couchbase @mgroves

Who am I? • • • Matthew D. Groves Developer Advocate for Couchbase @mgroves on Twitter Podcast and blog: http: //crosscuttingconcerns. com “I am not an expert, but I am an enthusiast. ” – Alan Stevens © 2017 Couchbase Inc. 4

SQL is the norm, right? © 2017 Couchbase Inc. 5 https: //commons. wikimedia. org/wiki/File:

SQL is the norm, right? © 2017 Couchbase Inc. 5 https: //commons. wikimedia. org/wiki/File: George_Wendt_at_the_41 st_Emmy_Awards_cropped. jpg

~3200 BC: invention of writing in Mesopotamia ~300 BC: Library of Alexandria ~1041 AD:

~3200 BC: invention of writing in Mesopotamia ~300 BC: Library of Alexandria ~1041 AD: Movable type invented in China 1450: Movable type invented in Europe 1822: Babbage’s paper on the application of difference engines 1943: Colossus, the first programmable digital computer 1957 -1960: IBM SABRE, the first commercial use of a database 1970: EF Codd proposes the relational database model 1974: Ingres released 1979: Commercial launch of Oracle database 1988: Object databases appear 1989: Microsoft SQL Server version 1 1991: HTTP v 0. 9 1995: My. SQL’s initial release 2005: Couch. DB released 2006: Google’s Big Table paper 2007: Amazon’s Dynamo paper 2008 -2009: The No. SQL Cambrian explosion: Riak, Mongo. DB, Cassandra, Redis 2010: Couchbase arrives on the scene

No. SQL isn’t a very useful term

No. SQL isn’t a very useful term

Scalable? © 2017 Couchbase Inc. 8 https: //commons. wikimedia. org/wiki/File: Dagwood_sandwich. jpg

Scalable? © 2017 Couchbase Inc. 8 https: //commons. wikimedia. org/wiki/File: Dagwood_sandwich. jpg

Easy? Flexible? © 2017 Couchbase Inc. 10

Easy? Flexible? © 2017 Couchbase Inc. 10

ACID vs BASE? Atomic Consistent Isolated Durable © 2017 Couchbase Inc. Basic Availability Soft-state

ACID vs BASE? Atomic Consistent Isolated Durable © 2017 Couchbase Inc. Basic Availability Soft-state Eventual consistency 11 https: //commons. wikimedia. org/wiki/File: PH_Scale. svg

Schemaless © 2017 Couchbase Inc. 12 https: //en. wikipedia. org/wiki/File: Star-schema-example. png

Schemaless © 2017 Couchbase Inc. 12 https: //en. wikipedia. org/wiki/File: Star-schema-example. png

Normalized Denormalized © 2017 Couchbase Inc. 13 https: //commons. wikimedia. org/wiki/File: Frown. JPG

Normalized Denormalized © 2017 Couchbase Inc. 13 https: //commons. wikimedia. org/wiki/File: Frown. JPG

First: Why No. SQL? © 2017 Couchbase Inc. 14 https: //www. flickr. com/photos/wonderlane/13067014944

First: Why No. SQL? © 2017 Couchbase Inc. 14 https: //www. flickr. com/photos/wonderlane/13067014944

Round pegs, square holes © 2017 Couchbase Inc. 15 http: //www. timesofbook. com/2013/09/blobfish-image-gallery. html#.

Round pegs, square holes © 2017 Couchbase Inc. 15 http: //www. timesofbook. com/2013/09/blobfish-image-gallery. html#. V 6 i. Xwbgr. Jh. E

Perhaps SQL is right for this project © 2017 Couchbase Inc. 16

Perhaps SQL is right for this project © 2017 Couchbase Inc. 16

Scaling can be hard © 2017 Couchbase Inc. 17

Scaling can be hard © 2017 Couchbase Inc. 17

© 2017 Couchbase Inc. 18

© 2017 Couchbase Inc. 18

Availability is hard © 2017 Couchbase Inc. 19

Availability is hard © 2017 Couchbase Inc. 19

© 2017 Couchbase Inc. 20

© 2017 Couchbase Inc. 20

Schemas can be hard © 2017 Couchbase Inc. 21 https: //commons. wikimedia. org/wiki/File: Media.

Schemas can be hard © 2017 Couchbase Inc. 21 https: //commons. wikimedia. org/wiki/File: Media. Wiki_database_schema_1 -17_(r 82044). svg

Types of No. SQL databases Document Key/Value Columnar Graph © 2017 Couchbase Inc. 22

Types of No. SQL databases Document Key/Value Columnar Graph © 2017 Couchbase Inc. 22

Document { name: “Matt Groves”, shoe. Size: 13, children: [ { name: “Matthew”, age:

Document { name: “Matt Groves”, shoe. Size: 13, children: [ { name: “Matthew”, age: 8 }, { name: “Emma”, age: 6 } ] } © 2017 Couchbase Inc. 24

What makes it a document database? { name: “Matt Groves”, shoe. Size: 13, children:

What makes it a document database? { name: “Matt Groves”, shoe. Size: 13, children: [ { name: “Matthew”, age: 8 }, { name: “Emma”, age: 6 } ] } © 2017 Couchbase Inc. 26

JSON BSON XML

JSON BSON XML

JSON

JSON

The document database understands the format of the document © 2017 Couchbase Inc. 29

The document database understands the format of the document © 2017 Couchbase Inc. 29

It can do server-side stuff © 2017 Couchbase Inc. 30

It can do server-side stuff © 2017 Couchbase Inc. 30

Buckets Documents N 1 QL

Buckets Documents N 1 QL

"Client. Product. Code", "Title", "Quantity" "TShirt. CBS", "Couchbase logo t-shirt (small)", 29 "TShirt. CBM",

"Client. Product. Code", "Title", "Quantity" "TShirt. CBS", "Couchbase logo t-shirt (small)", 29 "TShirt. CBM", "Couchbase logo t-shirt (medium)", 72 "TShirt. CBL", "Couchbase logo t-shirt (large)", 34 "TShirt. CBXL", "Couchbase logo t-shirt (extra large)", 12 "Sticker. CBLogo", "Couchbase logo sticker", 256 "Pen. CBLogo", "Couchbase logo pen", 365

private static void Setup. Couchbase() { Client. Configuration config = new Client. Configuration(); config.

private static void Setup. Couchbase() { Client. Configuration config = new Client. Configuration(); config. Servers = new List<Uri> {new Uri("couchbase: //localhost") }; Cluster. Helper. Initialize(config); _bucket = Cluster. Helper. Get. Bucket("default"); }

private static void Load. Stock. List() { var csv = new Csv. Reader(File. Open.

private static void Load. Stock. List() { var csv = new Csv. Reader(File. Open. Text("swag. csv")); while (csv. Read()) { var record = csv. Get. Record<dynamic>(); var document = new Document<dynamic> { Id = record. Client. Product. Code, Content = new { record. Title, record. Quantity } }; _bucket. Insert(document); Console. Write. Line($"Added document '{record. Client. Product. Code}'"); } }

private static void Get. Document() { var doc = _bucket. Get<dynamic>("Sticker. CBLogo"); Console. Write.

private static void Get. Document() { var doc = _bucket. Get<dynamic>("Sticker. CBLogo"); Console. Write. Line($"Document Key: {doc. Id}"); Console. Write. Line($"Title: {doc. Value. title}"); Console. Write. Line($"Quantity: {doc. Value. quantity}"); }

Typical Document Database Core Operations • Upsert (aka set) • Inserts document if key

Typical Document Database Core Operations • Upsert (aka set) • Inserts document if key doesn’t exist, replaces otherwise • Insert (aka add) • Inserts document, error if it already exists • Update (aka replace) • Updates document, error if it doesn’t exist • Delete • Get © 2017 Couchbase Inc. 39

N 1 QL SELECT m. * FROM `default` m WHERE META(m). id = ‘Sticker.

N 1 QL SELECT m. * FROM `default` m WHERE META(m). id = ‘Sticker. CBLogo’ SELECT m. * FROM `default` m WHERE m. quantity > 10 © 2017 Couchbase Inc. 40

Great for Dev Scales Easily Consistently Fast SQL for No. SQL

Great for Dev Scales Easily Consistently Fast SQL for No. SQL

© 2017 Couchbase Inc. 42

© 2017 Couchbase Inc. 42

Use cases for Document Databases • User profiles • Session stores • Content management

Use cases for Document Databases • User profiles • Session stores • Content management • Others: http: //info. couchbase. com/15 Q 1 Top. Ten. UC. html © 2017 Couchbase Inc. 43

Key/Value Database © 2017 Couchbase Inc. 44

Key/Value Database © 2017 Couchbase Inc. 44

Doesn’t care what your data is (mostly) KEY 1 { type: “json” } KEY

Doesn’t care what your data is (mostly) KEY 1 { type: “json” } KEY 2 <data type=“xml”></data> KEY 3 Lorem ipsum … 0010010100101 KEYN © 2017 Couchbase Inc. 47 https: //www. flickr. com/photos/dcmot/23168680069

Buckets Key-Value Pairs

Buckets Key-Value Pairs

C# Riak private static void Do. Stuff. With. Riak() { var cluster = Riak.

C# Riak private static void Do. Stuff. With. Riak() { var cluster = Riak. Cluster. From. Config("riak. Config"); var client = cluster. Create. Client(); var actor = new Riak. Object("actors", "James Bond", "Sean Connery"); client. Put(actor); var actor. Back. Out = client. Get("actors", "James Bond"); var str = System. Text. Encoding. UTF 8. Get. String(actor. Back. Out. Value); Console. Write. Line($"Value: {str}"); } © 2017 Couchbase Inc. 49

Introducing: Eventual Consistency! © 2017 Couchbase Inc. 51

Introducing: Eventual Consistency! © 2017 Couchbase Inc. 51

Eventual Consistency © 2017 Couchbase Inc. https: //www. flickr. com/photos/scottchene/7046992749 https: //commons. wikimedia. org/wiki/File:

Eventual Consistency © 2017 Couchbase Inc. https: //www. flickr. com/photos/scottchene/7046992749 https: //commons. wikimedia. org/wiki/File: Timothy_Dalton_1987. jpg 52 https: //commons. wikimedia. org/wiki/File: Sir_Roger_Moore_crop. jpg

There can be only one! © 2017 Couchbase Inc. 53 https: //en. wikipedia. org/wiki/File:

There can be only one! © 2017 Couchbase Inc. 53 https: //en. wikipedia. org/wiki/File: Highlander_film_Connor_Mac. Leod. jpg

© 2017 Couchbase Inc. 54

© 2017 Couchbase Inc. 54

Scales Well Highly Available Data Agnostic

Scales Well Highly Available Data Agnostic

Use Cases for K/V • Data variability • Object caching • Session storage •

Use Cases for K/V • Data variability • Object caching • Session storage • Large object storage © 2017 Couchbase Inc. 56

Columnar © 2017 Couchbase Inc. 57

Columnar © 2017 Couchbase Inc. 57

Keyspaces Column Families Rows Columns

Keyspaces Column Families Rows Columns

Keyspace © 2017 Couchbase Inc. 60

Keyspace © 2017 Couchbase Inc. 60

Column Family © 2017 Couchbase Inc. 61

Column Family © 2017 Couchbase Inc. 61

CREATE KEYSPACE mykeyspace WITH replication = { 'class': 'Simple. Strategy', 'replication_factor': '1'}; CREATE TABLE

CREATE KEYSPACE mykeyspace WITH replication = { 'class': 'Simple. Strategy', 'replication_factor': '1'}; CREATE TABLE users (firstname text, lastname text, age int, email text, city text, PRIMARY KEY (lastname));

private static void Do. Stuff. With. Data. Stax() { var cluster = Cluster. Builder().

private static void Do. Stuff. With. Data. Stax() { var cluster = Cluster. Builder(). Add. Contact. Point("127. 0. 0. 1"). Build(); var session = cluster. Connect("mykeyspace"); session. Execute("insert into users (lastname, age, city, email, firstname) values ('Jones', 35, 'Austin', 'bob@example. com', 'Bob')"); var user. Back. Out = session. Execute("select * from users where lastname='Jones'"). First(); Console. Write. Line($"{user. Back. Out["firstname"]} {user. Back. Out["age"]}"); }

Impedance Mismatch Scales Well (Ops Headache) Suited to Analytics

Impedance Mismatch Scales Well (Ops Headache) Suited to Analytics

© 2017 Couchbase Inc. 66

© 2017 Couchbase Inc. 66

Use cases for Columnar • Metering data • Really big data • Analytics ©

Use cases for Columnar • Metering data • Really big data • Analytics © 2017 Couchbase Inc. 67

Graph © 2017 Couchbase Inc. 68 https: //commons. wikimedia. org/wiki/File: The_protein_interaction_network_of_Treponema_pallidum. png

Graph © 2017 Couchbase Inc. 68 https: //commons. wikimedia. org/wiki/File: The_protein_interaction_network_of_Treponema_pallidum. png

Leonhard Euler © 2017 Couchbase Inc. 69

Leonhard Euler © 2017 Couchbase Inc. 69

7 Bridges of Königsberg © 2017 Couchbase Inc. 70

7 Bridges of Königsberg © 2017 Couchbase Inc. 70

pilo y enem my ene my y n si ar pe ap ars in

pilo y enem my ene my y n si ar pe ap ars in appe enem ars in from appe ts appears in ap ars pe in

Gremlin © 2017 Couchbase Inc. 73

Gremlin © 2017 Couchbase Inc. 73

Use cases for Graph databases • • Social networks / dating sites Fraud detection

Use cases for Graph databases • • Social networks / dating sites Fraud detection Parcel routing Shopping recommendations © 2017 Couchbase Inc. 74

Say what? Relational Document Key/Value Columnar Graph Object others… © 2017 Couchbase Inc. 75

Say what? Relational Document Key/Value Columnar Graph Object others… © 2017 Couchbase Inc. 75

Box arrow box arrow Web Service Transactions SQL Ca che / T / Pro

Box arrow box arrow Web Service Transactions SQL Ca che / T / Pro ext file Se arc Data h Another Service Couchbase Cluster Bin Mobile © 2017 Couchbase Inc. ari es Riak S 2 76

Couchbase, everybody! © 2017 Couchbase Inc. 77

Couchbase, everybody! © 2017 Couchbase Inc. 77

Where do you find us? • blog. couchbase. com • @couchbasedev • @mgroves ©

Where do you find us? • blog. couchbase. com • @couchbasedev • @mgroves © 2017 Couchbase Inc. 78

Frequently Asked Questions 1. How is Couchbase different than Mongo? 2. Is Couchbase the

Frequently Asked Questions 1. How is Couchbase different than Mongo? 2. Is Couchbase the same thing as Couch. Db? 3. How did you get to be both incredibly handsome and tremendously intelligent? 4. What is the Couchbase licensing situation? 5. Is Couchbase a Managed Cloud Service? © 2017 Couchbase Inc. 79