SlideShare a Scribd company logo
I Have a NoSQL Toaster - Troy .NET User Group - July 2017
©2017 Couchbase Inc. 2
©2017 Couchbase Inc. 3
Where am I?
• Troy .NET User Group
• https://www.meetup.com/Troy-NET-User-Group/
©2017 Couchbase Inc. 4
Who am I?
• Matthew D. Groves
• Developer Advocate for Couchbase
• @mgroves onTwitter
• Podcast and blog: http://crosscuttingconcerns.com
• “I am not an expert, but I am an enthusiast.” – Alan Stevens
©2017 Couchbase Inc. 5
SQL is the norm, right?
https://commons.wikimedia.org/wiki/File:George_Wendt_at_the_41st_Emmy_Awards_cropped.jpg
~3200 BC: invention of writing in Mesopotamia
~300 BC: Library of Alexandria
~1041AD: Movable type invented inChina
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 v0.9
1995: MySQL’s initial release
2005: CouchDB released
2006: Google’s BigTable paper
2007: Amazon’s Dynamo paper
2008-2009: The NoSQL Cambrian explosion: Riak, MongoDB,Cassandra, Redis
2010: Couchbase arrives on the scene
NoSQL isn’t a very useful term
©2017 Couchbase Inc. 8
Scalable?
https://commons.wikimedia.org/wiki/File:Dagwood_sandwich.jpg
©2017 Couchbase Inc. 9
Easy? Flexible?
©2017 Couchbase Inc. 10
ACID vs BASE?
https://commons.wikimedia.org/wiki/File:PH_Scale.svg
Atomic
Consistent
Isolated
Durable
Basic Availability
Soft-state
Eventual consistency
©2017 Couchbase Inc. 11
Schema Schemaless
https://en.wikipedia.org/wiki/File:Star-schema-example.png
©2017 Couchbase Inc. 12
Normalized Denormalized
https://commons.wikimedia.org/wiki/File:Frown.JPG
©2017 Couchbase Inc. 13
First: Why NoSQL?
https://www.flickr.com/photos/wonderlane/13067014944
©2017 Couchbase Inc. 14
Round pegs, square holes
http://www.timesofbook.com/2013/09/blobfish-image-gallery.html#.V6iXwbgrJhE
©2017 Couchbase Inc. 15
Perhaps SQL is right for this project
©2017 Couchbase Inc. 16
Scaling can be hard
©2017 Couchbase Inc. 17
©2017 Couchbase Inc. 18
Availability is hard
©2017 Couchbase Inc. 19
©2017 Couchbase Inc. 20
Schemas can be hard
https://commons.wikimedia.org/wiki/File:MediaWiki_database_schema_1-17_(r82044).svg
©2017 Couchbase Inc. 21
Types of NoSQL databases
Document
Key/Value
Columnar
Graph
©2017 Couchbase Inc. 23
Document
I Have a NoSQL Toaster - Troy .NET User Group - July 2017
©2017 Couchbase Inc. 25
What makes it a document database?
JSON
XML
BSON
I Have a NoSQL Toaster - Troy .NET User Group - July 2017
©2017 Couchbase Inc. 28
The document database
understands the
format of the document
©2017 Couchbase Inc. 29
It can do
server-side stuff
Buckets
Documents
N1QL
"ClientProductCode","Title","Quantity"
"TShirtCBS","Couchbase logo t-shirt (small)",29
"TShirtCBM","Couchbase logo t-shirt (medium)",72
"TShirtCBL","Couchbase logo t-shirt (large)",34
"TShirtCBXL","Couchbase logo t-shirt (extra large)",12
"StickerCBLogo","Couchbase logo sticker",256
"PenCBLogo","Couchbase logo pen",365
class Program
{
private static IBucket _bucket;
static void Main(string[] args)
{
SetupCouchbase();
LoadStockList();
ClusterHelper.Close();
}
private static void SetupCouchbase()
{
ClientConfiguration config = new ClientConfiguration();
config.Servers = new List<Uri> {new Uri("couchbase://192.168.1.5") };
ClusterHelper.Initialize(config);
_bucket = ClusterHelper.GetBucket("default");
}
private static void LoadStockList()
{
var csv = new CsvReader(File.OpenText("swag.csv"));
while (csv.Read())
{
var record = csv.GetRecord<dynamic>();
var document = new Document<dynamic>
{
Id = record.ClientProductCode,
Content = new
{
record.Title,
record.Quantity
}
};
_bucket.Insert(document);
Console.WriteLine($"Added document '{record.ClientProductCode}'");
}
}
}
private static void SetupCouchbase()
{
ClientConfiguration config = new ClientConfiguration();
config.Servers = new List<Uri> {new Uri("couchbase://localhost") };
ClusterHelper.Initialize(config);
_bucket = ClusterHelper.GetBucket("default");
}
private static void LoadStockList() {
var csv = new CsvReader(File.OpenText("swag.csv"));
while (csv.Read()) {
var record = csv.GetRecord<dynamic>();
var document = new Document<dynamic> {
Id = record.ClientProductCode,
Content = new {
record.Title,
record.Quantity
}
};
_bucket.Insert(document);
Console.WriteLine($"Added document '{record.ClientProductCode}'");
}
}
I Have a NoSQL Toaster - Troy .NET User Group - July 2017
private static void GetDocument()
{
var doc = _bucket.Get<dynamic>("StickerCBLogo");
Console.WriteLine($"Document Key: {doc.Id}");
Console.WriteLine($"Title: {doc.Value.title}");
Console.WriteLine($"Quantity: {doc.Value.quantity}");
}
I Have a NoSQL Toaster - Troy .NET User Group - July 2017
©2017 Couchbase Inc. 38
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
N1QL
SELECT m.*
FROM `default` m
WHERE META(m).id = ‘StickerCBLogo’
SELECT m.*
FROM `default` m
WHERE m.quantity > 10
Great for Dev
Scales Easily
Consistently Fast
SQL for NoSQL
©2017 Couchbase Inc. 41
©2017 Couchbase Inc. 42
Use cases for Document Databases
• User profiles
• Session stores
• Content management
• Others:
http://info.couchbase.com/15Q1TopTenUC.html
©2017 Couchbase Inc. 43
Key/Value Database
I Have a NoSQL Toaster - Troy .NET User Group - July 2017
©2017 Couchbase Inc. 45
Key-Value Databases
In-memory caches
and
distributed data stores
©2017 Couchbase Inc. 46
Doesn’t care what your data is (mostly)
KEY1 { type: “json” }
KEY2 <data type=“xml”></data>
KEY3 Lorem ipsum
… 00100101000100101
KEYN
https://www.flickr.com/photos/dcmot/23168680069
Buckets
Key-Value Pairs
©2017 Couchbase Inc. 48
C# Riak
private static void DoStuffWithRiak()
{
var cluster = RiakCluster.FromConfig("riakConfig");
var client = cluster.CreateClient();
var actor = new RiakObject("actors", "James Bond","Sean Connery");
client.Put(actor);
var actorBackOut = client.Get("actors", "James Bond");
var str = System.Text.Encoding.UTF8.GetString(actorBackOut.Value.Value);
Console.WriteLine($"Value: {str}");
}
I Have a NoSQL Toaster - Troy .NET User Group - July 2017
©2017 Couchbase Inc. 50
Introducing: Eventual Consistency!
©2017 Couchbase Inc. 51
Eventual Consistency
https://www.flickr.com/photos/scottchene/7046992749
https://commons.wikimedia.org/wiki/File:Timothy_Dalton_1987.jpg
https://commons.wikimedia.org/wiki/File:Sir_Roger_Moore_crop.jpg
©2017 Couchbase Inc. 52
There can be only one!
https://en.wikipedia.org/wiki/File:Highlander_film_Connor_MacLeod.jpg
©2017 Couchbase Inc. 53
ScalesWell
Highly Available
Data Agnostic
©2017 Couchbase Inc. 55
Use Cases for K/V
• Data variability
• Object caching
• Session storage
• Large object storage
©2017 Couchbase Inc. 56
Columnar
I Have a NoSQL Toaster - Troy .NET User Group - July 2017
Keyspaces
Column Families
Rows
Columns
©2017 Couchbase Inc. 59
Keyspace
©2017 Couchbase Inc. 60
Column Family
CREATE KEYSPACE mykeyspace
WITH replication = { 'class': 'SimpleStrategy',
'replication_factor': '1'};
CREATE TABLE users (firstname text, lastname text, age int,
email text, city text, PRIMARY KEY (lastname));
private static void DoStuffWithDataStax()
{
var cluster = Cluster.Builder().AddContactPoint("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 userBackOut = session.Execute("select * from users where
lastname='Jones'").First();
Console.WriteLine($"{userBackOut["firstname"]} {userBackOut["age"]}");
}
I Have a NoSQL Toaster - Troy .NET User Group - July 2017
Impedance Mismatch
ScalesWell (Ops Headache)
Suited to Analytics
©2017 Couchbase Inc. 65
©2017 Couchbase Inc. 66
Use cases for Columnar
•Metering data
•Really big data
•Analytics
©2017 Couchbase Inc. 67
Graph
https://commons.wikimedia.org/wiki/File:The_protein_interaction_network_of_Treponema_pallidum.png
©2017 Couchbase Inc. 68
Leonhard Euler
©2017 Couchbase Inc. 69
7 Bridges of Königsberg
I Have a NoSQL Toaster - Troy .NET User Group - July 2017
I Have a NoSQL Toaster - Troy .NET User Group - July 2017
©2017 Couchbase Inc. 72
Querying
©2017 Couchbase Inc. 73
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
Box arrow box arrow
Web Service
SQL
Riak S2
Couchbase
Cluster
Another
Service
Mobile
Transactions
©2017 Couchbase Inc. 76
Couchbase, everybody!
©2017 Couchbase Inc. 77
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 same thing as CouchDb?
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?

More Related Content

PPTX
I Have a NoSQL toaster - DC - August 2017
PDF
Getting started with DataStax .NET Driver for Cassandra
PDF
IIJにおけるGlusterFS利用事例 GlusterFSの詳解と2年間の運用ノウハウ
 
PDF
Terraform, Ansible or pure CloudFormation
PDF
オブジェクトストレージの詳解とクラウドサービスを活かすスケーラブルなシステム開発
 
PDF
Mongo db japan
PPTX
Shankar's mongo db presentation
PDF
Redis for .NET Developers
I Have a NoSQL toaster - DC - August 2017
Getting started with DataStax .NET Driver for Cassandra
IIJにおけるGlusterFS利用事例 GlusterFSの詳解と2年間の運用ノウハウ
 
Terraform, Ansible or pure CloudFormation
オブジェクトストレージの詳解とクラウドサービスを活かすスケーラブルなシステム開発
 
Mongo db japan
Shankar's mongo db presentation
Redis for .NET Developers

What's hot (15)

PDF
A Developer Overview of Redis
KEY
CouchDB on Android
PDF
ODP
Guava
PPTX
KISSY 的昨天、今天与明天
PDF
kissy-past-now-future
KEY
Intro to Drush
PDF
Everyday - mongodb
PPTX
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
PDF
Dirty - How simple is your database?
PDF
Guava Overview Part 2 Bucharest JUG #2
PDF
MongoDB: a gentle, friendly overview
PPTX
SWORD & ResourceSync - Stuart Lewis
PDF
NoSQL - An introduction to CouchDB
PPTX
RediSearch Mumbai Meetup 2020
A Developer Overview of Redis
CouchDB on Android
Guava
KISSY 的昨天、今天与明天
kissy-past-now-future
Intro to Drush
Everyday - mongodb
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Dirty - How simple is your database?
Guava Overview Part 2 Bucharest JUG #2
MongoDB: a gentle, friendly overview
SWORD & ResourceSync - Stuart Lewis
NoSQL - An introduction to CouchDB
RediSearch Mumbai Meetup 2020
Ad

Similar to I Have a NoSQL Toaster - Troy .NET User Group - July 2017 (20)

PPTX
i_have_a_nosql_toaster_-_qcon_-_june_2017.pptx
PDF
I have a NoSQL Toaster - ConnectJS - October 2016
PDF
Couchbase Singapore Meetup #2: Why Developing with Couchbase is easy !!
PPTX
Couchbase 101
PDF
Couchbase Chennai Meetup: Developing with Couchbase- made easy
PPTX
Couchbase Overview - Monterey Bay Information Technologists Meetup 02.15.17
PDF
Couchbase overview033113long
PDF
Couchbase overview033113long
PDF
Manuel Hurtado. Couchbase paradigma4oct
PDF
The Why, When, and How of NoSQL - A Practical Approach
PDF
Slides: NoSQL Data Modeling Using JSON Documents – A Practical Approach
PPTX
Couchbase Data Platform | Big Data Demystified
ODP
Couchbase training basic
PDF
CBDW2014 - NoSQL Development With Couchbase and ColdFusion (CFML)
PPTX
CFCamp 2016 - Couchbase Overview
PDF
Couchbase - Yet Another Introduction
PDF
Igor Davydenko
PDF
Slides: Moving from a Relational Model to NoSQL
PDF
Migration and Coexistence between Relational and NoSQL Databases by Manuel H...
PDF
How companies use NoSQL and Couchbase - NoSQL Now 2013
i_have_a_nosql_toaster_-_qcon_-_june_2017.pptx
I have a NoSQL Toaster - ConnectJS - October 2016
Couchbase Singapore Meetup #2: Why Developing with Couchbase is easy !!
Couchbase 101
Couchbase Chennai Meetup: Developing with Couchbase- made easy
Couchbase Overview - Monterey Bay Information Technologists Meetup 02.15.17
Couchbase overview033113long
Couchbase overview033113long
Manuel Hurtado. Couchbase paradigma4oct
The Why, When, and How of NoSQL - A Practical Approach
Slides: NoSQL Data Modeling Using JSON Documents – A Practical Approach
Couchbase Data Platform | Big Data Demystified
Couchbase training basic
CBDW2014 - NoSQL Development With Couchbase and ColdFusion (CFML)
CFCamp 2016 - Couchbase Overview
Couchbase - Yet Another Introduction
Igor Davydenko
Slides: Moving from a Relational Model to NoSQL
Migration and Coexistence between Relational and NoSQL Databases by Manuel H...
How companies use NoSQL and Couchbase - NoSQL Now 2013
Ad

More from Matthew Groves (20)

PPTX
CREAM - That Conference Austin - January 2024.pptx
PPTX
FluentMigrator - Dayton .NET - July 2023
PPTX
Cache Rules Everything Around Me - DevIntersection - December 2022
PPTX
Putting the SQL Back in NoSQL - October 2022 - All Things Open
PPTX
Cache Rules Everything Around Me - Momentum - October 2022.pptx
PPTX
Don't Drop ACID (July 2021)
PPTX
Don't Drop ACID - Data Love - April 2021
PPTX
Demystifying NoSQL - All Things Open - October 2020
PPTX
Autonomous Microservices - Manning - July 2020
PPTX
CONDG April 23 2020 - Baskar Rao - GraphQL
PPTX
JSON Data Modeling - GDG Indy - April 2020
PPTX
Background Tasks Without a Separate Service: Hangfire for ASP.NET - KCDC - Ju...
PPTX
Intro to SQL++ - Detroit Tech Watch - June 2019
PPTX
Autonomous Microservices - CodeMash - January 2019
PPTX
5 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 2018
PPTX
JSON Data Modeling - July 2018 - Tulsa Techfest
PPTX
5 NoSQL Options - Toronto - May 2018
PPTX
Full stack development with node and NoSQL - All Things Open - October 2017
PPTX
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
PPTX
Querying NoSQL with SQL - KCDC - August 2017
CREAM - That Conference Austin - January 2024.pptx
FluentMigrator - Dayton .NET - July 2023
Cache Rules Everything Around Me - DevIntersection - December 2022
Putting the SQL Back in NoSQL - October 2022 - All Things Open
Cache Rules Everything Around Me - Momentum - October 2022.pptx
Don't Drop ACID (July 2021)
Don't Drop ACID - Data Love - April 2021
Demystifying NoSQL - All Things Open - October 2020
Autonomous Microservices - Manning - July 2020
CONDG April 23 2020 - Baskar Rao - GraphQL
JSON Data Modeling - GDG Indy - April 2020
Background Tasks Without a Separate Service: Hangfire for ASP.NET - KCDC - Ju...
Intro to SQL++ - Detroit Tech Watch - June 2019
Autonomous Microservices - CodeMash - January 2019
5 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 2018
JSON Data Modeling - July 2018 - Tulsa Techfest
5 NoSQL Options - Toronto - May 2018
Full stack development with node and NoSQL - All Things Open - October 2017
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
Querying NoSQL with SQL - KCDC - August 2017

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation_ Review paper, used for researhc scholars
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Machine learning based COVID-19 study performance prediction
Diabetes mellitus diagnosis method based random forest with bat algorithm
Understanding_Digital_Forensics_Presentation.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Network Security Unit 5.pdf for BCA BBA.
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation_ Review paper, used for researhc scholars
The AUB Centre for AI in Media Proposal.docx
Spectroscopy.pptx food analysis technology
Unlocking AI with Model Context Protocol (MCP)
Review of recent advances in non-invasive hemoglobin estimation
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Digital-Transformation-Roadmap-for-Companies.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Programs and apps: productivity, graphics, security and other tools
Machine learning based COVID-19 study performance prediction

I Have a NoSQL Toaster - Troy .NET User Group - July 2017

  • 3. ©2017 Couchbase Inc. 3 Where am I? • Troy .NET User Group • https://www.meetup.com/Troy-NET-User-Group/
  • 4. ©2017 Couchbase Inc. 4 Who am I? • Matthew D. Groves • Developer Advocate for Couchbase • @mgroves onTwitter • Podcast and blog: http://crosscuttingconcerns.com • “I am not an expert, but I am an enthusiast.” – Alan Stevens
  • 5. ©2017 Couchbase Inc. 5 SQL is the norm, right? https://commons.wikimedia.org/wiki/File:George_Wendt_at_the_41st_Emmy_Awards_cropped.jpg
  • 6. ~3200 BC: invention of writing in Mesopotamia ~300 BC: Library of Alexandria ~1041AD: Movable type invented inChina 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 v0.9 1995: MySQL’s initial release 2005: CouchDB released 2006: Google’s BigTable paper 2007: Amazon’s Dynamo paper 2008-2009: The NoSQL Cambrian explosion: Riak, MongoDB,Cassandra, Redis 2010: Couchbase arrives on the scene
  • 7. NoSQL isn’t a very useful term
  • 8. ©2017 Couchbase Inc. 8 Scalable? https://commons.wikimedia.org/wiki/File:Dagwood_sandwich.jpg
  • 9. ©2017 Couchbase Inc. 9 Easy? Flexible?
  • 10. ©2017 Couchbase Inc. 10 ACID vs BASE? https://commons.wikimedia.org/wiki/File:PH_Scale.svg Atomic Consistent Isolated Durable Basic Availability Soft-state Eventual consistency
  • 11. ©2017 Couchbase Inc. 11 Schema Schemaless https://en.wikipedia.org/wiki/File:Star-schema-example.png
  • 12. ©2017 Couchbase Inc. 12 Normalized Denormalized https://commons.wikimedia.org/wiki/File:Frown.JPG
  • 13. ©2017 Couchbase Inc. 13 First: Why NoSQL? https://www.flickr.com/photos/wonderlane/13067014944
  • 14. ©2017 Couchbase Inc. 14 Round pegs, square holes http://www.timesofbook.com/2013/09/blobfish-image-gallery.html#.V6iXwbgrJhE
  • 15. ©2017 Couchbase Inc. 15 Perhaps SQL is right for this project
  • 16. ©2017 Couchbase Inc. 16 Scaling can be hard
  • 18. ©2017 Couchbase Inc. 18 Availability is hard
  • 20. ©2017 Couchbase Inc. 20 Schemas can be hard https://commons.wikimedia.org/wiki/File:MediaWiki_database_schema_1-17_(r82044).svg
  • 21. ©2017 Couchbase Inc. 21 Types of NoSQL databases Document Key/Value Columnar Graph
  • 22. ©2017 Couchbase Inc. 23 Document
  • 24. ©2017 Couchbase Inc. 25 What makes it a document database?
  • 27. ©2017 Couchbase Inc. 28 The document database understands the format of the document
  • 28. ©2017 Couchbase Inc. 29 It can do server-side stuff
  • 30. "ClientProductCode","Title","Quantity" "TShirtCBS","Couchbase logo t-shirt (small)",29 "TShirtCBM","Couchbase logo t-shirt (medium)",72 "TShirtCBL","Couchbase logo t-shirt (large)",34 "TShirtCBXL","Couchbase logo t-shirt (extra large)",12 "StickerCBLogo","Couchbase logo sticker",256 "PenCBLogo","Couchbase logo pen",365
  • 31. class Program { private static IBucket _bucket; static void Main(string[] args) { SetupCouchbase(); LoadStockList(); ClusterHelper.Close(); } private static void SetupCouchbase() { ClientConfiguration config = new ClientConfiguration(); config.Servers = new List<Uri> {new Uri("couchbase://192.168.1.5") }; ClusterHelper.Initialize(config); _bucket = ClusterHelper.GetBucket("default"); } private static void LoadStockList() { var csv = new CsvReader(File.OpenText("swag.csv")); while (csv.Read()) { var record = csv.GetRecord<dynamic>(); var document = new Document<dynamic> { Id = record.ClientProductCode, Content = new { record.Title, record.Quantity } }; _bucket.Insert(document); Console.WriteLine($"Added document '{record.ClientProductCode}'"); } } }
  • 32. private static void SetupCouchbase() { ClientConfiguration config = new ClientConfiguration(); config.Servers = new List<Uri> {new Uri("couchbase://localhost") }; ClusterHelper.Initialize(config); _bucket = ClusterHelper.GetBucket("default"); }
  • 33. private static void LoadStockList() { var csv = new CsvReader(File.OpenText("swag.csv")); while (csv.Read()) { var record = csv.GetRecord<dynamic>(); var document = new Document<dynamic> { Id = record.ClientProductCode, Content = new { record.Title, record.Quantity } }; _bucket.Insert(document); Console.WriteLine($"Added document '{record.ClientProductCode}'"); } }
  • 35. private static void GetDocument() { var doc = _bucket.Get<dynamic>("StickerCBLogo"); Console.WriteLine($"Document Key: {doc.Id}"); Console.WriteLine($"Title: {doc.Value.title}"); Console.WriteLine($"Quantity: {doc.Value.quantity}"); }
  • 37. ©2017 Couchbase Inc. 38 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
  • 38. ©2017 Couchbase Inc. 39 N1QL SELECT m.* FROM `default` m WHERE META(m).id = ‘StickerCBLogo’ SELECT m.* FROM `default` m WHERE m.quantity > 10
  • 39. Great for Dev Scales Easily Consistently Fast SQL for NoSQL
  • 41. ©2017 Couchbase Inc. 42 Use cases for Document Databases • User profiles • Session stores • Content management • Others: http://info.couchbase.com/15Q1TopTenUC.html
  • 42. ©2017 Couchbase Inc. 43 Key/Value Database
  • 44. ©2017 Couchbase Inc. 45 Key-Value Databases In-memory caches and distributed data stores
  • 45. ©2017 Couchbase Inc. 46 Doesn’t care what your data is (mostly) KEY1 { type: “json” } KEY2 <data type=“xml”></data> KEY3 Lorem ipsum … 00100101000100101 KEYN https://www.flickr.com/photos/dcmot/23168680069
  • 47. ©2017 Couchbase Inc. 48 C# Riak private static void DoStuffWithRiak() { var cluster = RiakCluster.FromConfig("riakConfig"); var client = cluster.CreateClient(); var actor = new RiakObject("actors", "James Bond","Sean Connery"); client.Put(actor); var actorBackOut = client.Get("actors", "James Bond"); var str = System.Text.Encoding.UTF8.GetString(actorBackOut.Value.Value); Console.WriteLine($"Value: {str}"); }
  • 49. ©2017 Couchbase Inc. 50 Introducing: Eventual Consistency!
  • 50. ©2017 Couchbase Inc. 51 Eventual Consistency https://www.flickr.com/photos/scottchene/7046992749 https://commons.wikimedia.org/wiki/File:Timothy_Dalton_1987.jpg https://commons.wikimedia.org/wiki/File:Sir_Roger_Moore_crop.jpg
  • 51. ©2017 Couchbase Inc. 52 There can be only one! https://en.wikipedia.org/wiki/File:Highlander_film_Connor_MacLeod.jpg
  • 54. ©2017 Couchbase Inc. 55 Use Cases for K/V • Data variability • Object caching • Session storage • Large object storage
  • 55. ©2017 Couchbase Inc. 56 Columnar
  • 58. ©2017 Couchbase Inc. 59 Keyspace
  • 59. ©2017 Couchbase Inc. 60 Column Family
  • 60. CREATE KEYSPACE mykeyspace WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '1'}; CREATE TABLE users (firstname text, lastname text, age int, email text, city text, PRIMARY KEY (lastname));
  • 61. private static void DoStuffWithDataStax() { var cluster = Cluster.Builder().AddContactPoint("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 userBackOut = session.Execute("select * from users where lastname='Jones'").First(); Console.WriteLine($"{userBackOut["firstname"]} {userBackOut["age"]}"); }
  • 63. Impedance Mismatch ScalesWell (Ops Headache) Suited to Analytics
  • 65. ©2017 Couchbase Inc. 66 Use cases for Columnar •Metering data •Really big data •Analytics
  • 66. ©2017 Couchbase Inc. 67 Graph https://commons.wikimedia.org/wiki/File:The_protein_interaction_network_of_Treponema_pallidum.png
  • 67. ©2017 Couchbase Inc. 68 Leonhard Euler
  • 68. ©2017 Couchbase Inc. 69 7 Bridges of Königsberg
  • 71. ©2017 Couchbase Inc. 72 Querying
  • 72. ©2017 Couchbase Inc. 73 Use cases for Graph databases • Social networks / dating sites • Fraud detection • Parcel routing • Shopping recommendations
  • 73. ©2017 Couchbase Inc. 74 Say what? Relational Document Key/Value Columnar Graph Object others…
  • 74. ©2017 Couchbase Inc. 75 Box arrow box arrow Web Service SQL Riak S2 Couchbase Cluster Another Service Mobile Transactions
  • 75. ©2017 Couchbase Inc. 76 Couchbase, everybody!
  • 76. ©2017 Couchbase Inc. 77 Where do you find us? • blog.couchbase.com • @couchbasedev • @mgroves
  • 77. ©2017 Couchbase Inc. 78 Frequently Asked Questions 1. How is Couchbase different than Mongo? 2. Is Couchbase the same thing as CouchDb? 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?

Editor's Notes

  • #2: This session was originally conceived by Matthew Revell I have modified it, but it is largely based on his work, so I want to give him credit
  • #3: We're here because "relational" is the norm So right away I can tell the age of my audience
  • #6: We ‘always’ been doing SQL, anything else must be an aberration? Well I’m not so sure.
  • #7: In 3200 B.C. we have the first evidence of human writing Then later the printing press The first commercial database is in 1960 (SABRE by American Airlines and IBM making a better way to handle airline ticket bookings) It was not relational, it was more like a filesystem hierarchy 1970 – EF Codd proposes the relational db model, and came up with SQL later 1979 – the necessary sacrifices to the dark forces were made and the Oracle database is released So maybe around 1990, relational databases become “the norm”, about 20-30 years to where we default to stick things in tables In 2005, people start looking at old ideas (because there’s nothing new underneath the sun), and a document database was created called CouchDB (which was a different spin on Lotus Notes) 2008 – explosion of NoSQL databases, influenced by two academic papers from Google and Amazon, who were losing money because they couldn’t keep relational DBs online – so Amazon created a massively distributed, fault tolerant, highly available, eventually consistent db called Dynamo, and you can use a version of that today, which is called DynamoDB So these papers started a lot of open source activity, and we’ll look at those in a bit more detail today 2010 – the heavens open and Couchbase decends to earth (disclaimer, I work for Couchbase)
  • #8: That’s why I say this toaster is a NoSQL Toaster! I can operate it fully without using any SQL query on it It can store data, it’s not tables, it’s bread I can get that data back out (as toast) It’s a good marketing shorthand to say “these databases are different than what we’ve been doing for 30 years” But defining something by what it’s not – only useful for a little while So let’s dive in and figure out what NoSQL means?
  • #9: Is it because they’re scalable? Well… not really… not all of them are scalable (and sometimes they aren’t even if their creators say they are)
  • #10: So what is it that defines a NoSQL database? Is it because they’re easy to develop against? Well… not really… if you try Cassandra, it’s not straightforward totally easy, can still be a bit inflexible
  • #11: Does it have to do with ACID vs BASE? Atomic Consistent Isolated Durable Vs Basic Availability Soft-state Eventual Consistency Well, no… FoundationDB is a NoSQL database that is ACID compliant (Apple purchased them) Many NoSQL databases tradeoff some level of ACIDity for scalability or performance reasons
  • #12: Is it that there is no Schema? Maybe… kinda… sorta… even if your database isn’t imposing a rigid schema on you This doesn’t mean there isn’t a schema, it’s just that the database isn’t enforcing one You as a developer need to impose a schema on it
  • #13: Is it that they are denormalized? This is pretty close. Data doesn’t need to be normalized, and there may be some benefit to non-normalized data (performance or flexibility or both) Doesn’t mean you can’t split data up, you just do it differently/broader
  • #14: Before I get into some of the details about NoSQL databases Here’s a disclaimer If you’re starting out on a new project or refactoring an existing project, don’t use NoSQL Because it’s cool, because there’s peer pressure, because you want more stuff on your resume A lot of problems are SOLVED WELL by existing technology that you understand well and have a good toolset around So if you have a problem that’s not going to scale massively, or it fits nicely into a relational model, and you can deal with object impedance mismatch and OR/Ms and you’re comfortable with that, then you might as well use a relational database and leave the road less traveled for another time
  • #15: This is the Blobfish, some call it the ugliest fish in the world But this is a picture at surface level. This is actually a deep sea fish When it’s in its normal high-pressure environment it looks more like this It’s still not going to win any beauty pageants, but it definitely looks more like a standard fish My point is this: whatever data store you choose should be the right one for the job. There’s a term “Polyglot persistence” which just means that. So maybe if part of your app is just saving log data, maybe that’s a good place to start with a nosql db. If another part is highly relational, then use a relational db. Maybe stick with relational for the “database of record”, but use nosql for caching, or for session, or for shopping cart. Wherever it makes sense.
  • #16: So maybe SQL is right for your project But there are some cases where maybe relational ISN’T a good fit or at least not the best fit
  • #17: With ANY system really Vertical scaling is the easiest: faster server, more ram, beefier machine, but that gets expensive, impractical Horizontal scaling: with relational databases, I’ve got two words for you “sharding scheme” With SQL Server there are a variety of sharding methods (vertical, range, hash, directory), but you have to worry about joining across shards, denormalizing, rebalancing, what if you change the schema? People do this, and people get it to work. Depending on your use case, it can be reasonable for certain use cases where the data can be easily divided, it can be a nightmare otherwise.
  • #18: This is where distributed databases can help. You can do this with relational databases, but many NoSQL databases are built with this in mind If you have a database cluster, and you need additional capacity, you can rack up another cheap server and add it to the cluster. Now: You don’t have to upgrade your hardware licensing may cost you less Your capacity is flexible There are some other benefits!
  • #19: This is always hard with a relational database. Keeping things online. Especially for writes. CAP Theorum – Consistent Available Partition-tolerant, applies to when nodes go down or there’s a network split. When operating normally, there is no such tradeoff.
  • #20: CAP theorem states that a distributed system can have three attributes And that you can only guarantee two of them at a time That word “guarantee” is in the academic sense If your network and servers are working as expected, you get all three. You might get all three to 99999 but you can't guarantee it We’ll see more of this graph later
  • #21: Something simple may not be so bad But something complex… Coming up with good schemas in the first place And then maintaining them across the lifetime of your app Has anyone had to take a database offline (or put into read-only) in order to do a schema migration? In many cases, this just isn’t acceptable: to tell a user that you can’t use this because we’re doing schema maintenance
  • #22: There are lots of types of NoSQL databases These 4 seem to be the main categories that people are interested in, esp in open source world And these will be the ones you’ll likely encounter in your research about what to use Graph is still a bit of the odd one out
  • #23: NoSQL databases are converging, and databases overall are converging In Couchbase, we’ve introduced N1QL, which is a full SQL implementation PLUS SOME to query documents Riak has introduced indexing and other features to help with querying SQL Server and PostgreSQL have introduced some great JSON features DocumentDB for Azure has a SQL implementation So it’s an exciting time where databases are adapting and changing and converging
  • #25: Logos for: MongoDB, CouchDB, MarkLogic, Couchbase, Lotus Notes, RethinkDB, OrientDB, Xbase, RavenDB, Existdb These are the top two most relevant document databases MongoDB has huge traction, Couchbase is easily the runner up (I’d say that even if they didn’t pay my mortgage)
  • #26: It understands the format of the document you’re dealing with It’s not just a bag you throw things in, it has understanding of the data These are often the best general replacement for relational databases
  • #27: MarkLogic is XML, I learned recently it can also do JSON I guess there could be a YAML database or something else like that… But no one likes XML (animation to cross it off or whatever) BSON is a binary implementation of JSON that Mongo uses, can be exported to “Extended JSON” so really what we’re talking about here is JSON
  • #28: So what we’re talking about in document databases is storing JSON It’s human readable, compact (compared to XML), can contain arrays, objects, hierarchies
  • #30: It can do something to the document (or documents) without you having to -pull it out -do something to it -put it back
  • #31: Take a quick run through how couchbase handles documents Here are some new terms in NoSQL Buckets – is a collections of documents, or equivalent of a database Documents – Kinda like tables, but not Views – map/reduce functions to do interesting queries N1QL – Couchbase has a query language that you can use to query/operate on documents as well
  • #32: Here is a CSV of data for Swag There’s a code, title/description, and quantity
  • #33: Here’s some C# that pulls that in and puts it into couchbase
  • #34: There’s a URL to one or more nodes The bucket name
  • #35: Taking the values from the CSV I’m making the swag code into the document key And I’m taking the other values, stuffing them into an anonymous object (which will be converted to JSON)
  • #36: This is a screenshot of the Couchbase Console, it’s the admin view And this is what it would look like if you imported into Couchbase
  • #37: Pull out a single document with a GET statement
  • #39: Document databases have these operations, typically simple crud operations This is (initially) why these databases are called “nosql”, because you aren’t using SQL to do these core operations Do more interesting stuff with M/R or with N1QL queries in Couchbase Often what we’re doing with relational databases is starting with an object that has hierarchy, and twisting it around to get it to fit into database tables If we can avoid it, why go through that pain of an impedence mismatch? Instead just put the whole thing into a document
  • #41: Some things that couchbase is good for Great for dev, less impedence mismatch Scales well, works as a cluster, easy to ramp up – just rack up another server, join the cluster, and it redistributes data Fast, because there is a built-in cache so you’ll often be reading/writing to RAM and not having to wait on the disk Drawback: When nodes go down or network splits: highly consistent, but eventually available
  • #42: Consistency means that even during a network partition, there is only a single up to date copy of the data. Couchbase works this way. So, if a node goes down, you can no longer access that document. That sounds dire, but with Couchbase, there are replica documents stored on other nodes. So, when the nodes goes down, you can get read-only copies. And, Couchbase has an “auto failover” feature. When a node is detected as being down, it can compensate by promoting the replicas to active documents. This does take time, so during that period you do not get availability.
  • #44: Similar to document databases Except the value is an opaque blob, the database doesn’t care what the value is and doesn’t reason about it
  • #45: Couchbase can act as a key/value store Amazon dynamodb is a service from amazon Redis is an in-memory data store Riak, which is a faithful implementation of the Dynamo paper from Amazon
  • #46: Mix of in-memory and distributed data stores Let’s focus on distributed data stores (cross out in-memory caches)
  • #47: It’s “content agnostic” It’s very flexible in what you can store, usually very fast, not terribly flexible for querying
  • #48: I’m not a Riak expert, I’m not even a Riak user, I’ll try to represent it fairly
  • #49: Connects to riak Create a bucket called ‘actors’ Let’s store actors as the value and the role as the key “James Bond” => “Sean Connery”
  • #51: This is the gotcha with dynamo-style systems
  • #52: You’ve got a number of servers and a number of apps writing to them and reading from them at the same time Riak tries its best not to ever refuse a write So let’s say you lose a bunch of servers, someone tripped over the power cord And riak, dynamodb, etc, will carry on receiving the writes and taking over the workload for now Or maybe there’s a network split; some apps are writing to one half, the other are writing to the other half So you might have conflicting values With a strongly consistent database, writes could be refused. This is trade-off with something like Riak [animation] So app 1 writes Sean Connery, app 2 writes Timothy Dalton, and maybe app 3 writes in Roger Moore
  • #53: But the truth is: there can be only one!
  • #54: So when we’re talking about distributed databases, there’s really only two options, Availability or Consistency Availability means that when there is a network partition, you can still perform reads and writes on any piece of data Even if that data lived on a server that can no longer be accessed The question is, what happens if that node comes back? There’s potential for a conflict (also known as “siblings”) You can resolve this conflict in a number of ways: at the database level with timestamp or last-write-wins Or bubble it up to a user Or write some sort of custom merging code If availability is more important that consistency, this is the system you go with.
  • #55: Riak has introduced a lot of cool stuff to help with this problem: Version Vectors, explicit siblings, and other stuff But in many cases it’s going to be something that you have to think about, figure out, and fix I would recommend you try out Riak
  • #57: These come from google’s BigTable paper These are the hard ones Store data in columns instead of rows
  • #58: These are some Columnar databases For web devs working with open source tools, we focus on these two Let’s have a very quick look at cassandra
  • #59: It’s taken the data model idea from BigTable But it’s taken data distribution from the dynamo paper So you’ve got eventual consistency of something like Riak with data model that kinda looks relational but absolutely isn’t Keyspaces are like databases Column Families are a bit like tables Rows are rows, but different than you know them Columns are key-value pairs associated with a row
  • #60: So what does that actually mean This image borrowed from DataStax website The keyspace is ‘blog’ (but please don’t use Cassandra to run a blog)
  • #61: Zoom into column families ‘Users’ is a column family (kinda looks like a table) Each row has a key So if we get jbellis, we get name and state, which are columns (k/v pairs associated with the row) They can be anything, each row doesn’t have to have same columns You can do foreign keys, but manually It looks relational, but it really has a key/value approach Why do this? Google likes it for analytics. Instead of updating something in place, you can just add another column (there is an upper limit to columns, but it’s large) Let’s say we had a gas meter instead of a blog. Gas reader takes a reading every 15 minutes So a column family could be a gas meter A row could be a day Each column would be every 15-minute reading It’s very quick to do an aggregate of row, get an average reading per day, something like that
  • #62: This is an example I took from the datastax.com site on getting started This looks like SQL, but it’s CQL, and it’s more like a subset of SQL: it’s lacking things like JOINs and subqueries
  • #63: Here I’m connecting to the cluster Picking a keyspace Executing an insert And then selecting out that user and printing it to console
  • #65: Impedance mismatch – don’t use it for a blog, use it where you need to throw a lot of data quickly, do range queries across large bits of data Scales well – but apparently is an Ops headache, since it uses the JVM
  • #66: So when we’re talking about distributed databases, there’s really only two options, Availability or Consistency Availability means that when there is a network partition, you can still perform reads and writes on any piece of data Even if that data lived on a server that can no longer be accessed The question is, what happens if that node comes back? There’s potential for a conflict (also known as “siblings”) You can resolve this conflict in a number of ways: at the database level with timestamp or last-write-wins At the client level, do a merge or even let the user resolve the conflict, you cannot guarantee that a merge will never have to be handled manually If availability is more important that consistency, this is the system you go with.
  • #67: Really big data: Hbase says “billions of rows times millions of columns”
  • #68: Graph is kinda the odd one out, but worth mentioning The others are trying to store run-of-the-mill data With a graph, you’re storing data, but you’re also storing rich connections between the data
  • #69: Graph databases are based on the ideas of Euler who a polymath in the 1700s, contributed to math, physics, astronomy, logic, etc The “7 bridges of…” problem So Euler came up with a whole area of math to deal with that problem
  • #70: The problem is this: figure out a walk through the city that would cross each bridge once (and only once). You don’t have to start or stop at the same spot. He proved that there was no way to do that, but in doing so Euler used this problem to establish the entire field of graph theory
  • #71: Graph databases are all about the WAY that things are connected together CosmosDb is an azure offering from Microsoft, it’s “multi-model”, so it can act as all the types we’ve talked about as well as graph OrientDb is also multi-model, it can act as document database or graph
  • #72: Graph databases are all about the WAY that things are connected together So this image has some random-looking things Each of the items are all different things, database only cares about the relationships between them These relationships are directional So you could ask “give me all the enemies of Luke Skywalker who have appeared in The Force Awakens” Supermarket: “give me all the people who bought baby food and who also bought beer”, decide to give them discounts or coupons, etc Images: https://www.flickr.com/photos/mlemos/581278438 https://www.flickr.com/photos/pmiaki/5351186496 https://commons.wikimedia.org/wiki/File:Starwars-tatooine.jpg https://www.flickr.com/photos/stevetroughton/16889877817 https://commons.wikimedia.org/wiki/File:Star_Wars_The_Force_Awakens.jpg https://commons.wikimedia.org/wiki/File:MCM_London_May_15_-_Stormtrooper_(18246218651).jpg https://commons.wikimedia.org/wiki/File:Empirestrikesback2.png
  • #73: Gremlin, CosmosDB Neo4j supports Cypher query language
  • #75: NoSQL is a term that I have a love/hate relationship with Groups together a bunch of different databases into one big tent "NoSQL" may mean something different to someone you're talking to It's more helpful to drill into specifics: document, key/value, etc
  • #76: So, for your next web project, take a minute to think about the database you’re going to use Don’t use something just because it’s fashionable Don’t use something just because you’ve always used it Consider using multiple data stores Think about what you’re going to need long term Polyglot persistence
  • #79: Mongo: Features N1QL, XDCR, Full Text Search, Mobile & Sync. Memory-first architecture and proven, easy scaling. CouchDb: Couchbase started as a whole new piece of software that was basically a combination of memcache and CouchDb a long time ago, but has grown far beyond that. Couchbase isn’t a fork or vice versa. They share an acronym and they are both NoSQL. Like MySQL and SQL Server, for instance. Open source apache license for community edition, enterprise edition on a faster release schedule, some advanced features, and support license. Couchbase is software you can run in the cloud on a VM or on your own data center. CosmosDb is a manage cloud service, but there is a emulator you can run locally.